@@ -312,6 +312,37 @@ class DDSpanContextTest extends DDCoreSpecification {
312312 context. toString(). contains(" id=-" ) == false
313313 }
314314
315+ def " toString includes top_level flag" () {
316+ setup :
317+ def parent = tracer. buildSpan(" parentOperation" )
318+ .withServiceName(" parentService" )
319+ .withResourceName(" parentResource" )
320+ .start()
321+
322+ // Child span with different service name should be top-level
323+ def topLevelSpan = tracer. buildSpan(" childOperation" )
324+ .withServiceName(" childService" )
325+ .withResourceName(" childResource" )
326+ .asChildOf(parent. context())
327+ .start()
328+
329+ // Child span with same service name should not be top-level
330+ def nonTopLevelSpan = tracer. buildSpan(" childOperation2" )
331+ .withServiceName(" parentService" )
332+ .withResourceName(" childResource2" )
333+ .asChildOf(parent. context())
334+ .start()
335+
336+ def topLevelContext = topLevelSpan. context() as DDSpanContext
337+ def nonTopLevelContext = nonTopLevelSpan. context() as DDSpanContext
338+
339+ expect :
340+ topLevelContext. isTopLevel() == true
341+ topLevelContext. toString(). contains(" *top_level*" ) == true
342+ nonTopLevelContext. isTopLevel() == false
343+ nonTopLevelContext. toString(). contains(" *top_level*" ) == false
344+ }
345+
315346 static void assertTagmap (Map source , Map comparison , boolean removeThread = false ) {
316347 def sourceWithoutCommonTags = new HashMap (source)
317348 sourceWithoutCommonTags. remove(" runtime-id" )
0 commit comments