/** * Retrieves a {@link SpanContext} which was serialized earlier in the {@link WorkItem} * * @return {@link SpanContext} or null if no {@link SpanContext} was serialized in the {@link * WorkItem} */ @Nullable @JsonIgnore public SpanContext getSourceSpan() { return getSourceSpan(GlobalTracer.get()); }
@Test public void testExtractOnly() { SpanContext sourceSpanContext = _workItem.getSourceSpan(_mockTracer); assertThat(sourceSpanContext, nullValue()); try (ActiveSpan childSpan = _mockTracer .buildSpan("test dangling child") .addReference(References.FOLLOWS_FROM, sourceSpanContext) .startActive()) { assertThat(childSpan, notNullValue()); assertThat(childSpan, instanceOf(ThreadLocalActiveSpan.class)); } }
@Test public void testExtractOnlyNoop() { SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer); try (ActiveSpan childSpan = _noopTracer .buildSpan("test dangling child") .addReference(References.FOLLOWS_FROM, sourceSpanContext) .startActive()) { assertThat(childSpan, notNullValue()); assertThat(childSpan, instanceOf(NoopActiveSpan.class)); } }
@Test public void testNullActiveSpan() { _workItem.setSourceSpan(null, _mockTracer); SpanContext sourceSpanContext = _workItem.getSourceSpan(_mockTracer); assertThat(sourceSpanContext, nullValue()); try (ActiveSpan childSpan = _mockTracer .buildSpan("test dangling child") .addReference(References.FOLLOWS_FROM, sourceSpanContext) .startActive()) { assertThat(childSpan, notNullValue()); assertThat(childSpan, instanceOf(ThreadLocalActiveSpan.class)); } }
@Test public void testNullActiveSpanNoop() { _workItem.setSourceSpan(null, _noopTracer); SpanContext sourceSpanContext = _workItem.getSourceSpan(_noopTracer); try (ActiveSpan childSpan = _noopTracer .buildSpan("test dangling child") .addReference(References.FOLLOWS_FROM, sourceSpanContext) .startActive()) { assertThat(childSpan, notNullValue()); assertThat(childSpan, instanceOf(NoopActiveSpan.class)); } }
SpanContext queueWorkSpan = work.getWorkItem().getSourceSpan(); try (ActiveSpan checkTaskSpan = GlobalTracer.get()
boolean killed = false; SpanContext queueWorkSpan = work.getWorkItem().getSourceSpan(); try (ActiveSpan killTaskSpan = GlobalTracer.get()
@Test public void testInjectExtractNoop() { ActiveSpan activeSpan = _noopTracer.buildSpan("test span").startActive(); _workItem.setSourceSpan(activeSpan, _noopTracer); try (ActiveSpan childSpan = _noopTracer .buildSpan("test span") .addReference(References.FOLLOWS_FROM, _workItem.getSourceSpan(_noopTracer)) .startActive()) { assertThat(childSpan, notNullValue()); assertThat(childSpan, instanceOf(NoopActiveSpan.class)); } }
SpanContext queueWorkSpan = work.getWorkItem().getSourceSpan(); try (ActiveSpan assignWorkSpan = GlobalTracer.get()
@Test public void testInjectExtract() { MockContext sourceContext; try (ActiveSpan activeSpan = _mockTracer.buildSpan("test span").startActive()) { SpanContext sourceContextTmp = activeSpan.context(); assertThat(sourceContextTmp, instanceOf(MockContext.class)); sourceContext = (MockContext) sourceContextTmp; _workItem.setSourceSpan(activeSpan, _mockTracer); } SpanContext extractedContextTmp = _workItem.getSourceSpan(_mockTracer); assertThat(extractedContextTmp, notNullValue()); assertThat(extractedContextTmp, instanceOf(MockContext.class)); MockContext extractedContext = (MockContext) extractedContextTmp; // test that injected and extracted spans have same span context data assertThat(extractedContext.traceId(), equalTo(sourceContext.traceId())); assertThat(extractedContext.spanId(), equalTo(sourceContext.spanId())); } }