Tracer { public final Span joinSpan(TraceContext context) { if (context == null) throw new NullPointerException("context == null"); if (!supportsJoin) return newChild(context); int flags = InternalPropagation.instance.flags(context); if (!context.shared()) { flags |= FLAG_SHARED; return toSpan(context, InternalPropagation.instance.withFlags(context, flags)); } else { flags &= ~FLAG_SHARED; return toSpan(InternalPropagation.instance.withFlags(context, flags), context); } } Tracer(
    Clock clock,
    Propagation.Factory propagationFactory,
    SpanHandler spanHandler,
    PendingSpans pendingSpans,
    Sampler sampler,
    CurrentTraceContext currentTraceContext,
    boolean traceId128Bit,
    boolean supportsJoin,
    boolean alwaysSampleLocal,
    AtomicBoolean noop
  ); @Deprecated Tracer withSampler(Sampler sampler); Span newTrace(); final Span joinSpan(TraceContext context); Span newChild(TraceContext parent); Span nextSpan(TraceContextOrSamplingFlags extracted); Span toSpan(TraceContext context); SpanInScope withSpanInScope(@Nullable Span span); SpanCustomizer currentSpanCustomizer(); @Nullable Span currentSpan(); Span nextSpan(); ScopedSpan startScopedSpan(String name); ScopedSpan startScopedSpan(String name, SamplerFunction<T> samplerFunction, T arg); Span nextSpan(SamplerFunction<T> samplerFunction, T arg); Span nextSpanWithParent(SamplerFunction<T> samplerFunction, T arg,
    @Nullable TraceContext parent); ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext parent); @Override String toString();  }
@Test public void joinSpan_notYetSampledIsNotShared_root() { Span span = tracer.joinSpan(context); assertThat(span.context().shared()).isFalse(); }
@Test public void joinSpan_notYetSampledIsNotShared_child() { TraceContext context = TraceContext.newBuilder().traceId(1).parentId(2).spanId(3).shared(true).build(); Span span = tracer.joinSpan(context); assertThat(span.context().shared()).isFalse(); }
@Test public void localRootId_joinSpan_notYetSampled() { TraceContext context1 = TraceContext.newBuilder().traceId(1).spanId(2).build(); TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(3).build(); localRootId(context1, context2, ctx -> tracer.joinSpan(ctx.context())); }
@Test public void localRootId_joinSpan_notSampled() { TraceContext context1 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(false).build(); TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(3).sampled(false).build(); localRootId(context1, context2, ctx -> tracer.joinSpan(ctx.context())); }
@Test public void localRootId_joinSpan_sampled() { TraceContext context1 = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build(); TraceContext context2 = TraceContext.newBuilder().traceId(1).spanId(3).sampled(true).build(); localRootId(context1, context2, ctx -> tracer.joinSpan(ctx.context())); }
@Test public void joinSpan_decorates() { propagationFactory = baggageFactory; TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true) .shared(true).build(); TraceContext joined = tracer.joinSpan(incoming).context(); assertThat(joined).isNotSameAs(incoming); assertThat(joined.extra()).isNotEmpty(); }
@Test public void joinSpan_decorates_unsampled() { propagationFactory = baggageFactory; TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false) .shared(true).build(); TraceContext joined = tracer.joinSpan(incoming).context(); assertThat(joined).isNotSameAs(incoming); assertThat(joined.extra()).isNotEmpty(); }
@Test public void join_idempotent() { TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true) .shared(true).build(); TraceContext joined = tracer.joinSpan(incoming).context(); assertThat(joined).isNotSameAs(incoming); assertThat(tracer.joinSpan(incoming).context()).isSameAs(joined); }
@Test public void join_idempotent_unsampled() { TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false) .shared(true).build(); TraceContext joined = tracer.joinSpan(incoming).context(); assertThat(joined).isNotSameAs(incoming); assertThat(tracer.joinSpan(incoming).context()) .isNotSameAs(joined); }