Skip to content
Merged
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 @@ -35,6 +35,7 @@
public final class OtelConventions {
static final String SPAN_KIND_INTERNAL = "internal";
static final String OPERATION_NAME_SPECIFIC_ATTRIBUTE = "operation.name";
static final String SPAN_TYPE = "span.type";
static final String ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES = "analytics.event";
static final String HTTP_RESPONSE_STATUS_CODE_ATTRIBUTE = "http.response.status_code";

Expand Down Expand Up @@ -110,6 +111,9 @@ public static <T> boolean applyReservedAttribute(AgentSpan span, AttributeKey<T>
} else if (ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES.equals(name) && value instanceof String) {
span.setMetric(ANALYTICS_SAMPLE_RATE, parseBoolean((String) value) ? 1 : 0);
return true;
} else if (SPAN_TYPE.equals(name) && value instanceof String) {
span.setSpanType((CharSequence) value);
return true;
}
case BOOLEAN:
if (ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES.equals(name) && value instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GuavaAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand All @@ -74,6 +75,7 @@ class GuavaAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -104,6 +106,7 @@ class GuavaAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
compileOnly group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: openTelemetryVersion
compileOnly group: 'com.google.auto.value', name: 'auto-value-annotations', version: '1.6.6'

implementation project(':dd-java-agent:agent-otel:otel-shim')
testImplementation group: 'io.opentelemetry', name: 'opentelemetry-api', version: openTelemetryVersion
testImplementation group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: openTelemetryVersion
latest1xDepTestImplementation group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: '1+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WithSpanAnnotationLatestDepTest extends WithSpanAnnotationTest {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public String[] helperClassNames() {
return new String[] {
this.packageName + ".WithSpanDecorator",
this.packageName + ".WithSpanDecorator$1", // Switch over enum generated class
"datadog.opentelemetry.shim.trace.OtelConventions",
"datadog.opentelemetry.shim.trace.OtelConventions$1",
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package datadog.trace.instrumentation.opentelemetry.annotations;

import static datadog.opentelemetry.shim.trace.OtelConventions.toSpanKindTagValue;
import static datadog.trace.api.DDSpanTypes.HTTP_CLIENT;
import static datadog.trace.api.DDSpanTypes.HTTP_SERVER;
import static datadog.trace.api.DDSpanTypes.MESSAGE_CONSUMER;
import static datadog.trace.api.DDSpanTypes.MESSAGE_PRODUCER;
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND;
import static java.lang.Math.min;

import datadog.trace.api.InstrumenterConfig;
Expand Down Expand Up @@ -55,12 +57,13 @@ protected CharSequence component() {
public AgentSpan startMethodSpan(Method method) {
CharSequence operationName = null;
CharSequence spanType = null;
SpanKind kind = null;
boolean inheritContext = true;

WithSpan withSpanAnnotation = method.getAnnotation(WithSpan.class);
if (withSpanAnnotation != null) {
operationName = withSpanAnnotation.value();
spanType = convertToSpanType(withSpanAnnotation.kind());
kind = withSpanAnnotation.kind();
if (INHERIT_CONTEXT_MH != null) {
try {
inheritContext = (boolean) INHERIT_CONTEXT_MH.invokeExact(withSpanAnnotation);
Expand All @@ -82,8 +85,9 @@ public AgentSpan startMethodSpan(Method method) {
final AgentSpan span = spanBuilder.start();
DECORATE.afterStart(span);

if (spanType != null) {
span.setSpanType(spanType);
if (kind != null) {
span.setSpanType(convertToSpanType(kind));
span.setTag(SPAN_KIND, toSpanKindTagValue(kind));
}
if (InstrumenterConfig.get().isMethodMeasured(method)) {
span.setMeasured(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SpanAttributeAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
"custom-tag" value
}
}
Expand Down Expand Up @@ -57,6 +58,7 @@ class SpanAttributeAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
"custom-tag1" "param1"
"custom-tag2" "param2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand All @@ -52,6 +53,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand All @@ -75,18 +77,19 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" kindTag
}
}
}
}

where:
kind | type
'SERVER' | DDSpanTypes.HTTP_SERVER
'CLIENT' | DDSpanTypes.HTTP_CLIENT
'PRODUCER' | DDSpanTypes.MESSAGE_PRODUCER
'CONSUMER' | DDSpanTypes.MESSAGE_CONSUMER
'INTERNAL' | null
kind | type | kindTag
'SERVER' | DDSpanTypes.HTTP_SERVER | Tags.SPAN_KIND_SERVER
'CLIENT' | DDSpanTypes.HTTP_CLIENT | Tags.SPAN_KIND_CLIENT
'PRODUCER' | DDSpanTypes.MESSAGE_PRODUCER | Tags.SPAN_KIND_PRODUCER
'CONSUMER' | DDSpanTypes.MESSAGE_CONSUMER | Tags.SPAN_KIND_CONSUMER
'INTERNAL' | null | Tags.SPAN_KIND_INTERNAL
kindName = kind.substring(0, 1) + kind.substring(1).toLowerCase()
}

Expand All @@ -109,6 +112,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(error.class, error.getMessage())
}
}
Expand All @@ -129,6 +133,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -156,6 +161,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -186,6 +192,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -214,6 +221,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -244,6 +252,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand All @@ -267,6 +276,7 @@ class WithSpanAnnotationTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ReactiveStreamsAsyncResultExtensionTest extends InstrumentationSpecificati
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -63,6 +64,7 @@ class ReactiveStreamsAsyncResultExtensionTest extends InstrumentationSpecificati
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -92,6 +94,7 @@ class ReactiveStreamsAsyncResultExtensionTest extends InstrumentationSpecificati
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -121,6 +124,7 @@ class ReactiveStreamsAsyncResultExtensionTest extends InstrumentationSpecificati
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
span {
Expand All @@ -130,6 +134,7 @@ class ReactiveStreamsAsyncResultExtensionTest extends InstrumentationSpecificati
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -79,6 +80,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -107,6 +109,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -134,6 +137,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -164,6 +168,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -192,6 +197,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -78,6 +79,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -106,6 +108,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -133,6 +136,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -163,6 +167,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -191,6 +196,7 @@ class ReactorAsyncResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RxJava2ResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down Expand Up @@ -73,6 +74,7 @@ class RxJava2ResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
errorTags(expectedException)
}
}
Expand Down Expand Up @@ -110,6 +112,7 @@ class RxJava2ResultExtensionTest extends InstrumentationSpecification {
tags {
defaultTags()
"$Tags.COMPONENT" "opentelemetry"
"$Tags.SPAN_KIND" "internal"
}
}
}
Expand Down