Skip to content

Commit b46811b

Browse files
committed
re-working otel spec
1 parent b3220ae commit b46811b

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/trace/OtelConventions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
public final class OtelConventions {
3636
static final String SPAN_KIND_INTERNAL = "internal";
3737
static final String OPERATION_NAME_SPECIFIC_ATTRIBUTE = "operation.name";
38+
static final String SPAN_TYPE = "span.type";
3839
static final String ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES = "analytics.event";
3940
static final String HTTP_RESPONSE_STATUS_CODE_ATTRIBUTE = "http.response.status_code";
4041

@@ -110,6 +111,9 @@ public static <T> boolean applyReservedAttribute(AgentSpan span, AttributeKey<T>
110111
} else if (ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES.equals(name) && value instanceof String) {
111112
span.setMetric(ANALYTICS_SAMPLE_RATE, parseBoolean((String) value) ? 1 : 0);
112113
return true;
114+
} else if (SPAN_TYPE.equals(name) && value instanceof String) {
115+
span.setSpanType((CharSequence) value);
116+
return true;
113117
}
114118
case BOOLEAN:
115119
if (ANALYTICS_EVENT_SPECIFIC_ATTRIBUTES.equals(name) && value instanceof Boolean) {

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
compileOnly group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: openTelemetryVersion
1919
compileOnly group: 'com.google.auto.value', name: 'auto-value-annotations', version: '1.6.6'
2020

21+
implementation project(':dd-java-agent:agent-otel:otel-shim')
2122
testImplementation group: 'io.opentelemetry', name: 'opentelemetry-api', version: openTelemetryVersion
2223
testImplementation group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: openTelemetryVersion
2324
latest1xDepTestImplementation group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-annotations', version: '1+'

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/src/main/java/datadog/trace/instrumentation/opentelemetry/annotations/WithSpanAnnotationInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public String[] helperClassNames() {
4343
return new String[] {
4444
this.packageName + ".WithSpanDecorator",
4545
this.packageName + ".WithSpanDecorator$1", // Switch over enum generated class
46+
"datadog.opentelemetry.shim.trace.OtelConventions",
4647
};
4748
}
4849

dd-java-agent/instrumentation/opentelemetry/opentelemetry-annotations-1.20/src/main/java/datadog/trace/instrumentation/opentelemetry/annotations/WithSpanDecorator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package datadog.trace.instrumentation.opentelemetry.annotations;
22

3+
import static datadog.opentelemetry.shim.trace.OtelConventions.toSpanKindTagValue;
34
import static datadog.trace.api.DDSpanTypes.HTTP_CLIENT;
45
import static datadog.trace.api.DDSpanTypes.HTTP_SERVER;
56
import static datadog.trace.api.DDSpanTypes.MESSAGE_CONSUMER;
67
import static datadog.trace.api.DDSpanTypes.MESSAGE_PRODUCER;
8+
import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND;
79
import static java.lang.Math.min;
810

911
import datadog.trace.api.InstrumenterConfig;
@@ -55,12 +57,13 @@ protected CharSequence component() {
5557
public AgentSpan startMethodSpan(Method method) {
5658
CharSequence operationName = null;
5759
CharSequence spanType = null;
60+
SpanKind kind = null;
5861
boolean inheritContext = true;
5962

6063
WithSpan withSpanAnnotation = method.getAnnotation(WithSpan.class);
6164
if (withSpanAnnotation != null) {
6265
operationName = withSpanAnnotation.value();
63-
spanType = convertToSpanType(withSpanAnnotation.kind());
66+
kind = withSpanAnnotation.kind();
6467
if (INHERIT_CONTEXT_MH != null) {
6568
try {
6669
inheritContext = (boolean) INHERIT_CONTEXT_MH.invokeExact(withSpanAnnotation);
@@ -82,8 +85,9 @@ public AgentSpan startMethodSpan(Method method) {
8285
final AgentSpan span = spanBuilder.start();
8386
DECORATE.afterStart(span);
8487

85-
if (spanType != null) {
86-
span.setSpanType(spanType);
88+
if (kind != null) {
89+
span.setSpanType(convertToSpanType(kind));
90+
span.setTag(SPAN_KIND, toSpanKindTagValue(kind));
8791
}
8892
if (InstrumenterConfig.get().isMethodMeasured(method)) {
8993
span.setMeasured(true);

0 commit comments

Comments
 (0)