Source:
public void testSingleChildOfSpanContextWithOtherFollowsFromRefs() { TestTraceReporter reporter = new TestTraceReporter(); APMTracer tracer = new APMTracer(reporter); Span refdSpan1 = tracer.buildSpan("ref1") .start(); refdSpan1.finish(); Span refdSpan2 = tracer.buildSpan("ref2") .start(); refdSpan2.finish(); Map<String, String> headers = new HashMap<>(); headers.put(Constants.HAWKULAR_APM_TRACEID, TEST_APM_TRACEID); headers.put(Constants.HAWKULAR_APM_ID, TEST_APM_ID1); headers.put(Constants.HAWKULAR_APM_TXN, TEST_TXN); SpanContext spanCtx = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(headers)); Span span = tracer.buildSpan("SingleChildOfSpanContext") .addReference(References.FOLLOWS_FROM, refdSpan1.context()) .asChildOf(spanCtx) .addReference(References.FOLLOWS_FROM, refdSpan2.context()) .start(); span.finish(); assertEquals(3, reporter.getTraces().size()); Trace trace1 = reporter.getTraces().get(0); Trace trace2 = reporter.getTraces().get(1); Trace trace3 = reporter.getTraces().get(2); assertEquals(1, trace3.getNodes().size()); assertEquals(Consumer.class, trace3.getNodes().get(0).getClass()); assertTrue(((Consumer) trace3.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.Interaction, TEST_APM_ID1))); assertTrue(((Consumer) trace3.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.CausedBy, trace1.getFragmentId() + ":0"))); assertTrue(((Consumer) trace3.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.CausedBy, trace2.getFragmentId() + ":0"))); assertEquals(0, ((Consumer) trace3.getNodes().get(0)).getNodes().size()); }

Target:
public void testSingleChildOfSpanContextWithOtherFollowsFromRefs() { TestTraceReporter reporter = new TestTraceReporter(); Tracer tracer = new APMTracer(reporter); SpanContext spanCtx1 = extractedTraceState(tracer, TEST_APM_ID1); Span rootSpan = tracer.buildSpan("root") .asChildOf(spanCtx1) .start(); Span refdSpan1 = tracer.buildSpan("ref1") .asChildOf(rootSpan) .start(); refdSpan1.finish(); Span refdSpan2 = tracer.buildSpan("ref2") .asChildOf(rootSpan) .start(); refdSpan2.finish(); rootSpan.finish(); SpanContext spanCtx2 = extractedTraceState(tracer, TEST_APM_ID2); Span span = tracer.buildSpan("SingleChildOfSpanContext") .addReference(References.FOLLOWS_FROM, refdSpan1.context()) .asChildOf(spanCtx2) .addReference(References.FOLLOWS_FROM, refdSpan2.context()) .start(); span.finish(); assertEquals(2, reporter.getTraces().size()); Trace trace1 = reporter.getTraces().get(0); Trace trace2 = reporter.getTraces().get(1); assertEquals(1, trace2.getNodes().size()); assertEquals(Consumer.class, trace2.getNodes().get(0).getClass()); assertTrue(((Consumer) trace2.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.Interaction, TEST_APM_ID2))); assertTrue(((Consumer) trace2.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.CausedBy, trace1.getFragmentId() + ":0:0"))); assertTrue(((Consumer) trace2.getNodes().get(0)).getCorrelationIds().contains( new CorrelationIdentifier(Scope.CausedBy, trace1.getFragmentId() + ":0:1"))); assertEquals(0, ((Consumer) trace2.getNodes().get(0)).getNodes().size()); }