Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTEL: preserve span.kind if set as attributes in the builder #8298

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -99,6 +99,8 @@ public SpanBuilder setAttribute(String key, String value) {
} else if (ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES.equals(key) && value != null) {
this.overriddenAnalyticsSampleRate = parseBoolean(value) ? 1 : 0;
return this;
} else if (SPAN_KIND.equals(key) && value != null) {
this.spanKindSet = true;
}
// Store as object to prevent delegate to remove tag when value is empty
this.delegate.withTag(key, (Object) value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND_CLIENT
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND_CONSUMER
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND_INTERNAL
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND_PRODUCER
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND_SERVER

import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.DDSpanId
import datadog.trace.api.DDTags
Expand Down Expand Up @@ -96,6 +103,36 @@ class OpenTelemetryTest extends AgentTestRunner {
false | true
}

def "test span kinds as attributes"() {
setup:
def result = tracer.spanBuilder("some-name")
.setAttribute("span.kind", otelSpanKind)
.startSpan()

when:
result.end()

then:
assertTraces(1) {
trace(1) {
span {
tags {
defaultTags()
"$SPAN_KIND" "$tagSpanKind"
}
}
}
}

where:
otelSpanKind | tagSpanKind
"internal" | SPAN_KIND_INTERNAL
"server" | SPAN_KIND_SERVER
"client" | SPAN_KIND_CLIENT
"producer" | SPAN_KIND_PRODUCER
"consumer" | SPAN_KIND_CONSUMER
}

def "test span exception"() {
setup:
def builder = tracer.spanBuilder("some name")
Expand Down
Loading