Skip to content

Commit c60e61e

Browse files
mchandramouliashishagg
authored andcommitted
Add support single and dual span types (#68)
* adding support for single and dual span types * merge conflicts * renaming config to dualSpanMode instead of dualSpanType * fixing bug: server span context created from extracted wire context does not carry extracted flag
1 parent 7dc7923 commit c60e61e

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

core/src/main/java/com/expedia/www/haystack/client/Tracer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ SpanContext createDependentContext() {
290290
// then we assume this is the first span in the server and so just return the parent context
291291
// with the same shared span ids
292292
if (!tracer.dualSpanMode && (isServerSpan() || parent.getContext().isExtractedContext())) {
293-
return parent.getContext();
293+
return createContext(parent.getContext().getTraceId(),
294+
parent.getContext().getSpanId(),
295+
parent.getContext().getParentId(),
296+
baggage);
294297
}
295298

296299
return createContext(parent.getContext().getTraceId(),

core/src/test/java/com/expedia/www/haystack/client/SpanBuilderTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,52 @@ public void testChildOfWithSingleSpanTypeAndExtractedContext() {
154154
serverSpan.context().getSpanId().toString());
155155
}
156156

157+
@Test
158+
public void testChildOfSingleSpanTypeWithExtractedContextDoesNotPropagateExtractedContext() {
159+
//create a client span
160+
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
161+
"ClientService",
162+
dispatcher).build();
163+
final Span clientSpan = clientTracer.buildSpan("Api_call")
164+
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
165+
.start();
166+
final MapBackedTextMap wireData = new MapBackedTextMap();
167+
clientTracer.inject(clientSpan.context(), Format.Builtin.TEXT_MAP, wireData);
168+
169+
//create a server
170+
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
171+
"ServerService",
172+
dispatcher).build();
173+
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
174+
final Span serverSpan = serverTracer.buildSpan("Api")
175+
.asChildOf(wireContext)
176+
.start();
177+
178+
//make sure client and server have the same span-ids for single span type
179+
Assert.assertEquals("trace-ids are not matching",
180+
clientSpan.context().getTraceId().toString(),
181+
serverSpan.context().getTraceId().toString());
182+
Assert.assertEquals("server - client span-ids do not match",
183+
clientSpan.context().getSpanId().toString(),
184+
serverSpan.context().getSpanId().toString());
185+
186+
//not create another child of server span
187+
final Span childOfServerSpan = serverTracer.buildSpan("child_operation")
188+
.asChildOf(serverSpan)
189+
.start();
190+
191+
//make sure server span and child span have the same trace-ids but different span-ids
192+
Assert.assertEquals("trace-ids are not matching",
193+
serverSpan.context().getTraceId().toString(),
194+
childOfServerSpan.context().getTraceId().toString());
195+
Assert.assertNotEquals("server - childOfServerSpan span-ids match - they should not",
196+
serverSpan.context().getSpanId().toString(),
197+
childOfServerSpan.context().getSpanId().toString());
198+
Assert.assertEquals("server's span id - childOfServerSpan's parent id do not match",
199+
serverSpan.context().getSpanId().toString(),
200+
childOfServerSpan.context().getParentId().toString());
201+
}
202+
157203
@Test
158204
public void testWithTags() {
159205
Span child = tracer.buildSpan("child")

0 commit comments

Comments
 (0)