use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class AWSPropagationTest method extract_containsMarker.
@Test
public void extract_containsMarker() {
carrier.put("x-amzn-trace-id", sampledTraceId);
TraceContextOrSamplingFlags extracted = extractor.extract(carrier);
assertThat(extracted.context().extra()).containsExactly(AWSPropagation.MARKER);
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class AWSPropagationTest method extract_fail_containsMarker.
/**
* If invoked extract, a 128-bit trace ID will be created, compatible with AWS format
*/
@Test
public void extract_fail_containsMarker() {
TraceContextOrSamplingFlags extracted = extractor.extract(carrier);
assertThat(extracted.extra()).containsExactly(AWSPropagation.MARKER);
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class AWSPropagationTest method contextWithPassThrough.
TraceContext contextWithPassThrough() {
extractor = ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "x-amzn-trace-id").create(Propagation.KeyFactory.STRING).extractor(Map::get);
TraceContextOrSamplingFlags extracted = extractor.extract(carrier);
// sanity check
assertThat(extracted.samplingFlags()).isEqualTo(SamplingFlags.EMPTY);
assertThat(extracted.extra()).isNotEmpty();
// Make a context that wasn't from AWSPropagation
return TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).extra(extracted.extra()).build();
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class AWSPropagationTest method extract_skipsSelfField.
/**
* Shows we skip whitespace and extra fields like self or custom ones
*/
// https://aws.amazon.com/blogs/aws/application-performance-percentiles-and-request-tracing-for-aws-application-load-balancer/
@Test
public void extract_skipsSelfField() {
// TODO: check with AWS if it is valid to have arbitrary fields in front of standard ones.
// we currently permit them
carrier.put("x-amzn-trace-id", "Robot=Hello;Self=1-582113d1-1e48b74b3603af8479078ed6; " + "Root=1-58211399-36d228ad5d99923122bbe354; " + "TotalTimeSoFar=112ms;CalledFrom=Foo");
TraceContextOrSamplingFlags extracted = extractor.extract(carrier);
assertThat(extracted.traceIdContext()).isEqualTo(TraceIdContext.newBuilder().traceIdHigh(lowerHexToUnsignedLong("5821139936d228ad")).traceId(lowerHexToUnsignedLong("5d99923122bbe354")).build());
assertThat(((AWSPropagation.Extra) extracted.extra().get(0)).fields).contains(new StringBuilder(";Robot=Hello;TotalTimeSoFar=112ms;CalledFrom=Foo"));
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracingFilter method invoke.
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (tracer == null)
return invoker.invoke(invocation);
RpcContext rpcContext = RpcContext.getContext();
Kind kind = rpcContext.isProviderSide() ? Kind.SERVER : Kind.CLIENT;
final Span span;
if (kind.equals(Kind.CLIENT)) {
span = tracer.nextSpan();
injector.inject(span.context(), invocation.getAttachments());
} else {
TraceContextOrSamplingFlags extracted = extractor.extract(invocation.getAttachments());
span = extracted.context() != null ? tracer.joinSpan(extracted.context()) : tracer.nextSpan(extracted);
}
if (!span.isNoop()) {
span.kind(kind).start();
String service = invoker.getInterface().getSimpleName();
String method = RpcUtils.getMethodName(invocation);
span.kind(kind);
span.name(service + "/" + method);
InetSocketAddress remoteAddress = rpcContext.getRemoteAddress();
Endpoint.Builder remoteEndpoint = Endpoint.newBuilder().port(remoteAddress.getPort());
if (!remoteEndpoint.parseIp(remoteAddress.getAddress())) {
remoteEndpoint.parseIp(remoteAddress.getHostName());
}
span.remoteEndpoint(remoteEndpoint.build());
}
boolean isOneway = false, deferFinish = false;
try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) {
Result result = invoker.invoke(invocation);
if (result.hasException()) {
onError(result.getException(), span.customizer());
}
isOneway = RpcUtils.isOneway(invoker.getUrl(), invocation);
// the case on async client invocation
Future<Object> future = rpcContext.getFuture();
if (future instanceof FutureAdapter) {
deferFinish = true;
((FutureAdapter) future).getFuture().setCallback(new FinishSpanCallback(span));
}
return result;
} catch (Error | RuntimeException e) {
onError(e, span.customizer());
throw e;
} finally {
if (isOneway) {
span.flush();
} else if (!deferFinish) {
span.finish();
}
}
}
Aggregations