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
4 changes: 1 addition & 3 deletions dd-java-agent/agent-otel/otel-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ dependencies {
embeddedClasspath group: 'io.opentelemetry.javaagent.instrumentation', name: 'opentelemetry-javaagent-servlet-common-bootstrap', version: "$otelInstrumentationApiVersion-alpha"

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

tasks.named("shadowJar", ShadowJar) {
Expand All @@ -93,6 +92,7 @@ tasks.named("shadowJar", ShadowJar) {
include 'io/opentelemetry/instrumentation/api/**'
exclude 'io/opentelemetry/instrumentation/api/incubator/log/**'
exclude 'io/opentelemetry/instrumentation/api/incubator/semconv/db/*Sanitizer*'
exclude 'io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementInfo*'
Copy link
Contributor Author

@mcculls mcculls Mar 11, 2026

Choose a reason for hiding this comment

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

This exclusion is one that was missed during earlier development of the drop-in feature - we deliberately have our own SqlStatementInfo in otel-bootstrap that replaces the original. This PR fixes this omission and avoids any temporary duplication, even though the end result is not affected.

exclude 'io/opentelemetry/instrumentation/api/internal/cache/**'
exclude 'io/opentelemetry/instrumentation/api/internal/RuntimeVirtualFieldSupplier*'
exclude 'io/opentelemetry/instrumentation/api/util/VirtualField*'
Expand All @@ -104,15 +104,13 @@ tasks.named("shadowJar", ShadowJar) {
exclude 'io/opentelemetry/javaagent/bootstrap/internal/EmptyInstrumentationConfig*'
exclude 'io/opentelemetry/javaagent/bootstrap/internal/InClassLoaderMatcher*'
exclude 'io/opentelemetry/javaagent/bootstrap/internal/InstrumentationConfig*'
include 'datadog/opentelemetry/shim/**'
include 'datadog/trace/bootstrap/otel/**'

relocate 'io.opentelemetry.api', 'datadog.trace.bootstrap.otel.api'
relocate 'io.opentelemetry.context', 'datadog.trace.bootstrap.otel.context'
relocate 'io.opentelemetry.semconv', 'datadog.trace.bootstrap.otel.semconv'
relocate 'io.opentelemetry.instrumentation.api', 'datadog.trace.bootstrap.otel.instrumentation.api'
relocate 'io.opentelemetry.javaagent.bootstrap', 'datadog.trace.bootstrap.otel.instrumentation'
relocate 'datadog.opentelemetry.shim', 'datadog.trace.bootstrap.otel.shim'
}

tasks.named("jar", Jar) {
Expand Down
1 change: 1 addition & 0 deletions dd-java-agent/agent-otel/otel-shim/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ minimumBranchCoverage = 0.0
dependencies {
// minimum OpenTelemetry API version this shim is compatible with
compileOnly group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1.47.0'
compileOnly project(':dd-java-agent:agent-otel:otel-bootstrap')

implementation project(':products:metrics:metrics-api')
implementation project(':internal-api')
Expand Down
8 changes: 8 additions & 0 deletions dd-java-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def generalShadowJarConfig(ShadowJar shadowJarTask) {
relocate 'org.snakeyaml.engine', 'datadog.snakeyaml.engine'
relocate 'okhttp3', 'datadog.okhttp3'
relocate 'okio', 'datadog.okio'

// embed an extra copy of our otel-shim for drop-in/extension support
// extensions are remapped to avoid classpath conflicts; use same mapping here
relocate 'io.opentelemetry.api', 'datadog.trace.bootstrap.otel.api'
relocate 'io.opentelemetry.context', 'datadog.trace.bootstrap.otel.context'
relocate 'datadog.opentelemetry.shim', 'datadog.trace.bootstrap.otel.shim'
Comment on lines +154 to +158
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Out of curiosity I wonder if these relocation rules be in otel-shim ?

Copy link
Contributor Author

@mcculls mcculls Mar 12, 2026

Choose a reason for hiding this comment

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

No, because we need two copies of the shim:

  1. the bootstrap shim used to support OTel drop-in, where we allow extensions to be added at runtime

    • this shim uses an embedded+shaded copy of certain OTel classes
    • OTel references must be shaded to avoid conflicting with OTel libraries on the application classpath
  2. the auto-instrumentation shim which is used to redirect application calls to OTel to our tracer

    • this shim is added to the application class-loader which has access to the OTel classes
    • OTel references must not be shaded because we want to use the same provided OTel classes as the app

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I think I get a better picture of how otel support works now.

}

if (!project.hasProperty("disableShadowRelocate") || !disableShadowRelocate) {
Expand Down Expand Up @@ -362,6 +368,8 @@ dependencies {
shadowInclude project(path: ':dd-java-agent:agent-bootstrap')
shadowInclude project(path: ':dd-java-agent:agent-debugger:debugger-bootstrap')
shadowInclude project(path: ':dd-java-agent:agent-otel:otel-bootstrap', configuration: 'shadow')
// embed an extra copy of our otel-shim for drop-in/extension support
Copy link
Contributor

@bric3 bric3 Mar 12, 2026

Choose a reason for hiding this comment

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

question: Is it exactly an extra copy ? (I.e I'm mostly wondering if there's a better wording for these comments, there's the same at line 154)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is literally an extra copy - same classes, but shaded to match the embedded+shaded OTel classes needed for drop-in/extension support.

The other copy is in the instrumentation section - not shaded because we need it to work with the OTel classes provided from the application class-loader

Copy link
Contributor

Choose a reason for hiding this comment

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

OK makes sense

shadowInclude project(path: ':dd-java-agent:agent-otel:otel-shim')
shadowInclude project(path: ':products:feature-flagging:feature-flagging-bootstrap')

// Includes for the shared internal shadow jar
Expand Down
Loading