brave.propagation.TraceIdContext Java Examples
The following examples show how to use
brave.propagation.TraceIdContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSPropagationTest.java From zipkin-aws with Apache License 2.0 | 6 votes |
/** 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(((AmznTraceId) extracted.extra().get(0)).customFields) .contains(new StringBuilder(";Robot=Hello;TotalTimeSoFar=112ms;CalledFrom=Foo")); }
Example #2
Source File: AWSPropagationTest.java From zipkin-aws with Apache License 2.0 | 5 votes |
@Test public void extract_noParent() { carrier.put("x-amzn-trace-id", "Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=1"); assertThat(extractor.extract(carrier).traceIdContext()) .isEqualTo( TraceIdContext.newBuilder() .traceIdHigh(lowerHexToUnsignedLong("5759e988bd862e3f")) .traceId(lowerHexToUnsignedLong("e1be46a994272793")) .sampled(true) .build()); }
Example #3
Source File: TracerTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void nextSpan_extractedTraceId() { TraceIdContext traceIdContext = TraceIdContext.newBuilder().traceId(1L).build(); TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(traceIdContext); assertThat(tracer.nextSpan(extracted).context().traceId()) .isEqualTo(1L); }
Example #4
Source File: TracerTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void nextSpan_extractedTraceId_extra() { TraceIdContext traceIdContext = TraceIdContext.newBuilder().traceId(1L).build(); TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.newBuilder(traceIdContext) .addExtra(1L).build(); assertThat(tracer.nextSpan(extracted).context().extra()) .containsExactly(1L); }
Example #5
Source File: TracerTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void nextSpan_fromIdContext_resultantSpanIsLocalRoot() { TraceIdContext context = TraceIdContext.newBuilder().traceId(1).build(); Span span = tracer.nextSpan(TraceContextOrSamplingFlags.create(context)); assertThat(span.context().spanId()).isEqualTo(span.context().localRootId()); // Sanity check assertThat(span.context().isLocalRoot()).isTrue(); }
Example #6
Source File: ITKafkaTracing.java From brave with Apache License 2.0 | 5 votes |
@Override public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) { return request -> { String result = getter.get(request, TRACE_ID); if (result == null) return TraceContextOrSamplingFlags.create(SamplingFlags.EMPTY); return TraceContextOrSamplingFlags.create(TraceIdContext.newBuilder() .traceId(HexCodec.lowerHexToUnsignedLong(result)) .build()); }; }
Example #7
Source File: XCloudTraceContextExtractor.java From zipkin-gcp with Apache License 2.0 | 4 votes |
/** * Creates a tracing context if the extracted string follows the "x-cloud-trace-context: TRACE_ID" * or "x-cloud-trace-context: TRACE_ID/SPAN_ID" format; or the "x-cloud-trace-context: * TRACE_ID/SPAN_ID;o=TRACE_TRUE" format and {@code TRACE_TRUE}'s value is {@code 1}. */ @Override public TraceContextOrSamplingFlags extract(R request) { if (request == null) throw new NullPointerException("request == null"); TraceContextOrSamplingFlags context = primary.extract(request); if (context != TraceContextOrSamplingFlags.EMPTY) return context; TraceContextOrSamplingFlags result = TraceContextOrSamplingFlags.EMPTY; String xCloudTraceContext = getter.get(request, StackdriverTracePropagation.TRACE_ID_NAME); if (xCloudTraceContext != null) { String[] tokens = xCloudTraceContext.split("/"); long[] traceId = convertHexTraceIdToLong(tokens[0]); // traceId is null if invalid if (traceId != null) { long spanId = 0; // 0 indicates no span ID is set by the user Boolean traceTrue = null; // null means to defer trace decision to sampler // A span ID exists. A TRACE_TRUE flag also possibly exists. if (tokens.length >= 2) { String[] traceOptionTokens = tokens[1].split(";"); if (traceOptionTokens.length >= 1 && !traceOptionTokens[0].isEmpty()) { spanId = parseUnsignedLong(traceOptionTokens[0]); } if (traceOptionTokens.length >= 2) { traceTrue = extractTraceTrueFromToken(traceOptionTokens[1]); } } if (spanId == 0) { result = TraceContextOrSamplingFlags.create( TraceIdContext.newBuilder() .traceIdHigh(traceId[0]) .traceId(traceId[1]) .sampled(traceTrue) .build()); } else { result = TraceContextOrSamplingFlags.create( TraceContext.newBuilder() .traceIdHigh(traceId[0]) .traceId(traceId[1]) .spanId(spanId) .sampled(traceTrue) .build()); } } } return result; }
Example #8
Source File: TracerTest.java From brave with Apache License 2.0 | 4 votes |
@Test public void localRootId_nextSpan_ids_notYetSampled() { TraceIdContext context1 = TraceIdContext.newBuilder().traceId(1).build(); TraceIdContext context2 = TraceIdContext.newBuilder().traceId(2).build(); localRootId(context1, context2, ctx -> tracer.nextSpan(ctx)); }
Example #9
Source File: TracerTest.java From brave with Apache License 2.0 | 4 votes |
@Test public void localRootId_nextSpan_ids_notSampled() { TraceIdContext context1 = TraceIdContext.newBuilder().traceId(1).sampled(false).build(); TraceIdContext context2 = TraceIdContext.newBuilder().traceId(2).sampled(false).build(); localRootId(context1, context2, ctx -> tracer.nextSpan(ctx)); }
Example #10
Source File: TracerTest.java From brave with Apache License 2.0 | 4 votes |
@Test public void localRootId_nextSpan_ids_sampled() { TraceIdContext context1 = TraceIdContext.newBuilder().traceId(1).sampled(true).build(); TraceIdContext context2 = TraceIdContext.newBuilder().traceId(2).sampled(true).build(); localRootId(context1, context2, ctx -> tracer.nextSpan(ctx)); }
Example #11
Source File: TracerTest.java From brave with Apache License 2.0 | 4 votes |
void localRootId(TraceIdContext c1, TraceIdContext c2, Function<TraceContextOrSamplingFlags, Span> fn) { localRootId(TraceContextOrSamplingFlags.create(c1), TraceContextOrSamplingFlags.create(c2), fn); }