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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

### Features

- Wrap configured OpenTelemetry `ContextStorageProvider` if available ([#4359](https://github.com/getsentry/sentry-java/pull/4359))
- This is only relevant if you see `java.lang.IllegalStateException: Found multiple ContextStorageProvider. Set the io.opentelemetry.context.ContextStorageProvider property to the fully qualified class name of the provider to use. Falling back to default ContextStorage. Found providers: ...`
- Set `-Dio.opentelemetry.context.contextStorageProvider=io.sentry.opentelemetry.SentryContextStorageProvider` on your `java` command
- Sentry will then wrap the other `ContextStorageProvider` that has been configured by loading it through SPI
- If no other `ContextStorageProvider` is available or there are problems loading it, we fall back to using `SentryOtelThreadLocalStorage`

### Fixes

- Update profile chunk rate limit and client report ([#4353](https://github.com/getsentry/sentry-java/pull/4353))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@

import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.ContextStorageProvider;
import java.util.Iterator;
import java.util.ServiceLoader;
import org.jetbrains.annotations.NotNull;

public final class SentryContextStorageProvider implements ContextStorageProvider {
@Override
public ContextStorage get() {
return new SentryContextStorage(new SentryOtelThreadLocalStorage());
return new SentryContextStorage(findStorageToWrap());
}

private @NotNull ContextStorage findStorageToWrap() {
try {
ServiceLoader<ContextStorageProvider> serviceLoader =
ServiceLoader.load(ContextStorageProvider.class);
Iterator<ContextStorageProvider> iterator = serviceLoader.iterator();
while (iterator.hasNext()) {
ContextStorageProvider contextStorageProvider = iterator.next();
if (!(contextStorageProvider instanceof SentryContextStorageProvider)) {
return contextStorageProvider.get();
}
}
} catch (Throwable t) {
// ignore and use fallback
}

// using default / fallback storage
return new SentryOtelThreadLocalStorage();
}
}
Loading