Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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 @@ -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