Skip to content

Commit

Permalink
Swap original StrictContextStorage with simple wrapper to avoid missi…
Browse files Browse the repository at this point in the history
…ng reference issue on native-image (#7201)
  • Loading branch information
mcculls authored Jun 17, 2024
1 parent f8dbe2b commit 9c5c8ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions dd-java-agent/agent-otel/otel-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ shadowJar {
include 'io/opentelemetry/api/**'
exclude 'io/opentelemetry/api/incubator/**'
include 'io/opentelemetry/context/**'
exclude 'io/opentelemetry/context/StrictContextStorage*'
exclude 'io/opentelemetry/context/internal/shaded/**'
include 'io/opentelemetry/semconv/**'
include 'io/opentelemetry/instrumentation/api/**'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package datadog.trace.bootstrap.otel.context;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.Scope;

/**
* Replaces original class with a simple wrapper to avoid missing reference issue on native-image.
*
* <p>The original class is only used for testing purposes when a particular property is set, but
* native-image follows the reference in {@code LazyStorage} and attempts to load everything it
* touches, including some types we are not embedding. This simple replacement fixes this issue.
*/
final class StrictContextStorage implements ContextStorage {
private final ContextStorage delegate;

static StrictContextStorage create(ContextStorage delegate) {
return new StrictContextStorage(delegate);
}

public StrictContextStorage(ContextStorage delegate) {
this.delegate = delegate;
}

@Override
public Scope attach(Context context) {
return delegate.attach(context);
}

@Override
public Context current() {
return delegate.current();
}
}

0 comments on commit 9c5c8ab

Please sign in to comment.