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 @@ -3,6 +3,7 @@
import static datadog.opentelemetry.shim.trace.OtelConventions.SPAN_KIND_INTERNAL;

import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.otel.common.OtelInstrumentationScope;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -11,9 +12,12 @@
final class OtelTracer implements Tracer {
private static final String INSTRUMENTATION_NAME = otelInstrumentationName();

private final OtelInstrumentationScope instrumentationScope;

private final AgentTracer.TracerAPI tracer;

OtelTracer(@SuppressWarnings("unused") String instrumentationScopeName) {
OtelTracer(OtelInstrumentationScope instrumentationScope) {
this.instrumentationScope = instrumentationScope;
this.tracer = AgentTracer.get();
}

Expand All @@ -24,6 +28,11 @@ public SpanBuilder spanBuilder(String spanName) {
return new OtelSpanBuilder(delegate);
}

@Override
public String toString() {
return "OtelTracer{instrumentationScope=" + instrumentationScope + "}";
}

@SuppressWarnings("ConstantConditions")
private static String otelInstrumentationName() {
// is this the bootstrap shim for drop-in support, or the shim for manual instrumentation?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
final class OtelTracerBuilder implements TracerBuilder {
private final OtelTracerProvider tracerProvider;

private final String instrumentationScopeName;
@Nullable private String instrumentationScopeVersion;
@Nullable private String schemaUrl;

OtelTracerBuilder(OtelTracerProvider tracerProvider, String instrumentationScopeName) {
this.tracerProvider = tracerProvider;
Expand All @@ -16,18 +20,19 @@ final class OtelTracerBuilder implements TracerBuilder {

@Override
public TracerBuilder setInstrumentationVersion(String instrumentationScopeVersion) {
// Not supported
this.instrumentationScopeVersion = instrumentationScopeVersion;
return this;
}

@Override
public TracerBuilder setSchemaUrl(String schemaUrl) {
// Not supported
this.schemaUrl = schemaUrl;
return this;
}

@Override
public Tracer build() {
return tracerProvider.getTracerShim(instrumentationScopeName);
return tracerProvider.getTracerShim(
instrumentationScopeName, instrumentationScopeVersion, schemaUrl);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package datadog.opentelemetry.shim.trace;

import datadog.trace.bootstrap.otel.common.OtelInstrumentationScope;
import datadog.trace.util.Strings;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;
import io.opentelemetry.api.trace.TracerProvider;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,31 +19,35 @@ public final class OtelTracerProvider implements TracerProvider {

public static final TracerProvider INSTANCE = new OtelTracerProvider();

/** Tracer shims, indexed by instrumentation scope name. */
private final Map<String, OtelTracer> tracers = new ConcurrentHashMap<>();
/** Tracer shims, indexed by instrumentation scope. */
private final Map<OtelInstrumentationScope, OtelTracer> tracers = new ConcurrentHashMap<>();

@Override
public Tracer get(String instrumentationScopeName) {
return getTracerShim(instrumentationScopeName);
return getTracerShim(instrumentationScopeName, null, null);
}

@Override
public Tracer get(
String instrumentationScopeName,
@SuppressWarnings("unused") String instrumentationScopeVersion) {
return getTracerShim(instrumentationScopeName);
public Tracer get(String instrumentationScopeName, String instrumentationScopeVersion) {
return getTracerShim(instrumentationScopeName, instrumentationScopeVersion, null);
}

@Override
public TracerBuilder tracerBuilder(String instrumentationScopeName) {
return new OtelTracerBuilder(this, instrumentationScopeName);
}

OtelTracer getTracerShim(String instrumentationScopeName) {
OtelTracer getTracerShim(
String instrumentationScopeName,
@Nullable String instrumentationScopeVersion,
@Nullable String schemaUrl) {
if (Strings.isBlank(instrumentationScopeName)) {
LOGGER.debug("Tracer requested without instrumentation scope name.");
instrumentationScopeName = DEFAULT_TRACER_NAME;
}
Comment on lines 44 to 47
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't care about empty values for version and schemaUrl, though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return tracers.computeIfAbsent(instrumentationScopeName, OtelTracer::new);
return tracers.computeIfAbsent(
new OtelInstrumentationScope(
instrumentationScopeName, instrumentationScopeVersion, schemaUrl),
OtelTracer::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ dependencies {

implementation project(':dd-java-agent:agent-otel:otel-shim')

muzzleBootstrap project(path: ':dd-java-agent:agent-otel:otel-bootstrap', configuration: 'shadow')
testImplementation project(path: ':dd-java-agent:agent-otel:otel-bootstrap', configuration: 'shadow')

testImplementation group: 'io.opentelemetry', name: 'opentelemetry-api', version: openTelemetryVersion
testImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
latestDepTestImplementation group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {

testImplementation project(':dd-java-agent:instrumentation:datadog:tracing:trace-annotation')
testImplementation project(':dd-java-agent:instrumentation:reactive-streams-1.0')
testImplementation project(path: ':dd-java-agent:agent-otel:otel-bootstrap', configuration: 'shadow')
testImplementation project(':dd-java-agent:instrumentation:opentelemetry:opentelemetry-1.4')
testImplementation project(':dd-java-agent:instrumentation:opentelemetry:opentelemetry-annotations-1.20')
testImplementation project (':dd-java-agent:instrumentation:opentracing:opentracing-0.32')
Expand Down
Loading