Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,9 @@ public String toString() {
if (measured) {
s.append(" *measured*");
}
if (topLevel) {
s.append(" *top_level*");
}

synchronized (unsafeTags) {
s.append(" tags=").append(new TreeMap<>(getTags()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,37 @@ class DDSpanContextTest extends DDCoreSpecification {
context.toString().contains("id=-") == false
}

def "toString includes top_level flag"() {
setup:
def parent = tracer.buildSpan("parentOperation")
.withServiceName("parentService")
.withResourceName("parentResource")
.start()

// Child span with different service name should be top-level
def topLevelSpan = tracer.buildSpan("childOperation")
.withServiceName("childService")
.withResourceName("childResource")
.asChildOf(parent.context())
.start()

// Child span with same service name should not be top-level
def nonTopLevelSpan = tracer.buildSpan("childOperation2")
.withServiceName("parentService")
.withResourceName("childResource2")
.asChildOf(parent.context())
.start()

def topLevelContext = topLevelSpan.context() as DDSpanContext
def nonTopLevelContext = nonTopLevelSpan.context() as DDSpanContext

expect:
topLevelContext.isTopLevel() == true
topLevelContext.toString().contains("*top_level*") == true
nonTopLevelContext.isTopLevel() == false
nonTopLevelContext.toString().contains("*top_level*") == false
Comment on lines +340 to +343
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spock will assert booleans out of the box, so I think this can be like:

Suggested change
topLevelContext.isTopLevel() == true
topLevelContext.toString().contains("*top_level*") == true
nonTopLevelContext.isTopLevel() == false
nonTopLevelContext.toString().contains("*top_level*") == false
topLevelContext.isTopLevel()
topLevelContext.toString().contains("*top_level*")
!nonTopLevelContext.isTopLevel()
!nonTopLevelContext.toString().contains("*top_level*")

}

static void assertTagmap(Map source, Map comparison, boolean removeThread = false) {
def sourceWithoutCommonTags = new HashMap(source)
sourceWithoutCommonTags.remove("runtime-id")
Expand Down
Loading