Trace { public Span startSpan(String operationName, SpanContext spnContext){ Span span; if (spnContext!= null){ span = modelServiceApiTracer.buildSpan(operationName).asChildOf(spnContext).start(); } else { span = modelServiceApiTracer.buildSpan(operationName).start(); } return span; } @Autowired  Trace(Tracer tracer); Span startSpan(String operationName, SpanContext spnContext); SpanContext extractParentSpan(HttpHeaders headers);  }
@Test public void testNullSpanContext() throws NullPointerException { val testChildSpan = noOpsTracer.buildSpan("testOperationName"); SpanContext testNullSpanContext = null; when(tracer.buildSpan("testOperationName")).thenReturn(testChildSpan); val resultSpan = utilUnderTest.startSpan("testOperationName", testNullSpanContext); Assert.assertEquals("testOperationName", resultSpan.getOperationName()); }
@Test public void testNonNullSpanContext() { val testChildSpanContext = noOpsTracer.buildSpan("testChildOperationName").asChildOf(testSpanContext); when(tracer.buildSpan("testChildOperationName")).thenReturn(testChildSpanContext); val resultChildSpan = utilUnderTest.startSpan("testChildOperationName", testSpanContext); Assert.assertEquals(testSpanContext.toTraceId(), resultChildSpan.context().toTraceId()); Assert.assertEquals(testSpanContext.toSpanId(), resultChildSpan.context().getParentId().toString()); }