Skip to content

Commit ae36667

Browse files
authored
Merge 443f631 into 6df3ba5
2 parents 6df3ba5 + 443f631 commit ae36667

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
package io.sentry.opentelemetry;
22

3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.Iterator;
6+
import java.util.ServiceLoader;
7+
38
import io.opentelemetry.context.ContextStorage;
49
import io.opentelemetry.context.ContextStorageProvider;
510

611
public final class SentryContextStorageProvider implements ContextStorageProvider {
712
@Override
813
public ContextStorage get() {
9-
return new SentryContextStorage(new SentryOtelThreadLocalStorage());
14+
return new SentryContextStorage(findStorageToWrap());
15+
}
16+
17+
private @NotNull ContextStorage findStorageToWrap() {
18+
try {
19+
ServiceLoader<ContextStorageProvider> serviceLoader = ServiceLoader.load(ContextStorageProvider.class);
20+
Iterator<ContextStorageProvider> iterator = serviceLoader.iterator();
21+
while (iterator.hasNext()) {
22+
ContextStorageProvider contextStorageProvider = iterator.next();
23+
if (!(contextStorageProvider instanceof SentryContextStorageProvider)) {
24+
return contextStorageProvider.get();
25+
}
26+
}
27+
} catch (Throwable t) {
28+
// ignore and use fallback
29+
}
30+
31+
// using default / fallback storage
32+
return new SentryOtelThreadLocalStorage();
1033
}
1134
}

0 commit comments

Comments
 (0)