-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap original StrictContextStorage with simple wrapper to avoid missi…
…ng reference issue on native-image (#7201)
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...el-bootstrap/src/main/java/datadog/trace/bootstrap/otel/context/StrictContextStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |