diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dab3467c1..3a217e5af3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ ### Features - Extract OpenTelemetry `URL_PATH` span attribute into description ([#3933](https://github.com/getsentry/sentry-java/pull/3933)) +- Replace OpenTelemetry `ContextStorage` wrapper with `ContextStorageProvider` ([#3938](https://github.com/getsentry/sentry-java/pull/3938)) + - The wrapper had to be put in place before any call to `Context` whereas `ContextStorageProvider` is automatically invoked at the correct time. + +### Dependencies + +- Bump OpenTelemetry to 1.44.1, OpenTelemetry Java Agent to 2.10.0 and Semantic Conventions to 1.28.0 ([#3935](https://github.com/getsentry/sentry-java/pull/3935)) ### Dependencies diff --git a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/api/sentry-opentelemetry-bootstrap.api b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/api/sentry-opentelemetry-bootstrap.api index 0e061c84c0..38ce3b8803 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/api/sentry-opentelemetry-bootstrap.api +++ b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/api/sentry-opentelemetry-bootstrap.api @@ -103,6 +103,11 @@ public final class io/sentry/opentelemetry/SentryContextStorage : io/opentelemet public fun current ()Lio/opentelemetry/context/Context; } +public final class io/sentry/opentelemetry/SentryContextStorageProvider : io/opentelemetry/context/ContextStorageProvider { + public fun ()V + public fun get ()Lio/opentelemetry/context/ContextStorage; +} + public final class io/sentry/opentelemetry/SentryContextWrapper : io/opentelemetry/context/Context { public fun get (Lio/opentelemetry/context/ContextKey;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; diff --git a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelContextScopesStorage.java b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelContextScopesStorage.java index cd63187178..143ebb6c16 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelContextScopesStorage.java +++ b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelContextScopesStorage.java @@ -3,7 +3,6 @@ import static io.sentry.opentelemetry.SentryOtelKeys.SENTRY_SCOPES_KEY; import io.opentelemetry.context.Context; -import io.opentelemetry.context.ContextStorage; import io.opentelemetry.context.Scope; import io.sentry.IScopes; import io.sentry.IScopesStorage; @@ -27,8 +26,8 @@ public void init() { * should try to use OTels StorageProvider mechanism instead. */ // ContextStorage.addWrapper((storage) -> new SentryContextStorage(storage)); - ContextStorage.addWrapper( - (storage) -> new SentryContextStorage(new SentryOtelThreadLocalStorage())); + // ContextStorage.addWrapper( + // (storage) -> new SentryContextStorage(new SentryOtelThreadLocalStorage())); } @Override diff --git a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/SentryContextStorageProvider.java b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/SentryContextStorageProvider.java new file mode 100644 index 0000000000..0f2aa97c8d --- /dev/null +++ b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/SentryContextStorageProvider.java @@ -0,0 +1,11 @@ +package io.sentry.opentelemetry; + +import io.opentelemetry.context.ContextStorage; +import io.opentelemetry.context.ContextStorageProvider; + +public final class SentryContextStorageProvider implements ContextStorageProvider { + @Override + public ContextStorage get() { + return new SentryContextStorage(new SentryOtelThreadLocalStorage()); + } +} diff --git a/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/resources/META-INF/services/io.opentelemetry.context.ContextStorageProvider b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/resources/META-INF/services/io.opentelemetry.context.ContextStorageProvider new file mode 100644 index 0000000000..87a43eea48 --- /dev/null +++ b/sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/resources/META-INF/services/io.opentelemetry.context.ContextStorageProvider @@ -0,0 +1 @@ +io.sentry.opentelemetry.SentryContextStorageProvider