Skip to content

Commit 54e6568

Browse files
authored
POTEL 19 - Review feedback (#3491)
* replace hub with scopes * Add Scopes * Introduce `IScopes` interface. * Replace `IHub` with `IScopes` in core * Replace `IHub` with `IScopes` in android core * Replace `IHub` with `IScopes` in android integrations * Replace `IHub` with `IScopes` in apollo integrations * Replace `IHub` with `IScopes` in okhttp integration * Replace `IHub` with `IScopes` in graphql integration * Replace `IHub` with `IScopes` in logging integrations * Replace `IHub` with `IScopes` in more integrations * Replace `IHub` with `IScopes` in OTel integration * Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations * Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations * Replace `IHub` with `IScopes` in samples * gitscopes -> github * Replace ThreadLocal with ScopesStorage * Move client and throwable to span map to scope * Add global scope * use global scope in Scopes * Implement pushScope popScope and withScope for Scopes * Add pushIsolationScope; add fork methods to ISCope * Use separate scopes for current, isolation and global scope; rename mainScopes to rootScopes * Allow controlling which scope configureScope uses * Combine scopes * Use new API for CRONS integrations * Add lifecycle helper * Change spring integrations to use new API * Use new API in servlet integrations * Use new API for kotlin coroutines and wrapers for Supplier/Callable * Discussion TODOs * Fix breadcrumb ordering * Mark TODOS with [HSM] * Add getGlobalScope and forkedRootScopes to IScopes * Fix EventProcessor ordering on scopes * Reuse code in Scopes * No longer replace global scope * Replace hub occurrences in comments, var names etc. * Implement ScopesTest * Implement CombinedScopeViewTest * Fix combined contexts * Use combined scopes for cross platform * Changes according to reviews of previous PRs * more * even more * isEnabled checks client instead of having a property on Scopes * Use SentryOptions.empty * Remove Hub * Use OpenTelemetry for Performance and Scopes propagation * Promote certain span attributes * Use OTel in Sentry API * Deduplicate SpanInfo extraction * Forward Sentry API to Sentry through OTel * Use OTel status for Sentry span API * POTel Tracing * fix root span detection (remote flag), and scope closing * Inherit OTel span IDs when sending to sentry * Fix tracing; parse incoming baggage; add baggage to outgoing * Cleanup * Move sampling logic to OTel Sampler * Remove internal span attributes so they are not sent to Sentry * Use transaction name * remove obsolete comment * Keep OTel and Sentry span name/op in sync * more cleanup * Make it possible to ignore span origins * Reuse TracesSampler instance * Catch exceptions thrown by integration.close * Set NoOpSpanFactory as property default * Use correct SentryOptions for SentryClient ctor * PR review feedback * more
1 parent 738c5fa commit 54e6568

File tree

24 files changed

+87
-74
lines changed

24 files changed

+87
-74
lines changed

sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
77
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
88
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
9-
import io.sentry.Instrumenter;
109
import io.sentry.Sentry;
1110
import io.sentry.SentryIntegrationPackageStorage;
1211
import io.sentry.SentryOptions;
@@ -38,10 +37,6 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
3837
Sentry.init(
3938
options -> {
4039
options.setEnableExternalConfiguration(true);
41-
// TODO [POTEL] deprecate
42-
options.setInstrumenter(Instrumenter.OTEL);
43-
// TODO [POTEL] do we still need this?
44-
options.addEventProcessor(new OpenTelemetryLinkErrorEventProcessor());
4540
options.setIgnoredSpanOrigins(SpanUtils.ignoredSpanOriginsForOpenTelemetry());
4641
options.setSpanFactory(new OtelSpanFactory());
4742
final @Nullable SdkVersion sdkVersion = createSdkVersion(options, versionInfoHolder);
@@ -153,8 +148,6 @@ private static class VersionInfoHolder {
153148

154149
private SdkTracerProviderBuilder configureSdkTracerProvider(
155150
SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
156-
// TODO [POTEL] configurable or separate packages for old vs new way
157-
// return tracerProvider.addSpanProcessor(new SentrySpanProcessor());
158151
return tracerProvider
159152
.setSampler(new SentrySampler())
160153
.addSpanProcessor(new PotelSentrySpanProcessor())

sentry-opentelemetry/sentry-opentelemetry-bootstrap/api/sentry-opentelemetry-bootstrap.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public final class io/sentry/opentelemetry/OtelSpanWrapper : io/sentry/ISpan {
4242
public fun getData ()Ljava/util/Map;
4343
public fun getData (Ljava/lang/String;)Ljava/lang/Object;
4444
public fun getDescription ()Ljava/lang/String;
45-
public fun getEventId ()Lio/sentry/protocol/SentryId;
4645
public fun getFinishDate ()Lio/sentry/SentryDate;
4746
public fun getLocalMetricsAggregator ()Lio/sentry/metrics/LocalMetricsAggregator;
4847
public fun getMeasurements ()Ljava/util/Map;

sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelContextScopesStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public final class OtelContextScopesStorage implements IScopesStorage {
1515

1616
@Override
17-
public ISentryLifecycleToken set(@Nullable IScopes scopes) {
17+
public @NotNull ISentryLifecycleToken set(@Nullable IScopes scopes) {
1818
final @NotNull Scope otelScope =
1919
Context.current().with(SENTRY_SCOPES_KEY, scopes).makeCurrent();
2020
return new OtelStorageToken(otelScope);

sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelSpanWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,6 @@ public Map<String, MeasurementValue> getMeasurements() {
476476
return context.getSamplingDecision();
477477
}
478478

479-
@Override
480-
public @NotNull SentryId getEventId() {
481-
// TODO [POTEL]
482-
return new SentryId(getOtelSpanId().toString());
483-
}
484-
485479
@ApiStatus.Internal
486480
public @NotNull IScopes getScopes() {
487481
return scopes;

sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelTransactionSpanForwarder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public boolean isNoOp() {
257257

258258
@Override
259259
public @NotNull SentryId getEventId() {
260-
return rootSpan.getEventId();
260+
// TODO [POTEL]
261+
return new SentryId();
261262
}
262263

263264
@ApiStatus.Internal

sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/SentryWeakSpanStorage.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
import org.jetbrains.annotations.Nullable;
88

99
/**
10-
* This class may have to be moved to a new gradle module to include it in the bootstrap
11-
* classloader.
12-
*
13-
* <p>This uses multiple maps instead of a single one with a wrapper object as porting this to
14-
* Android would mean there's no access to methods like compute etc. before API level 24. There's
15-
* also no easy way to pre-initialize the map for all keys as spans are used as keys. For span IDs
16-
* it would also not work as they are random. For client report storage we know beforehand what keys
17-
* can exist.
10+
* Weakly references wrappers for OpenTelemetry spans meaning they'll be cleaned up when the
11+
* OpenTelemetry span is garbage collected.
1812
*/
1913
@ApiStatus.Internal
2014
public final class SentryWeakSpanStorage {

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryLinkErrorEventProcessor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
import io.sentry.ScopesAdapter;
1212
import io.sentry.SentryEvent;
1313
import io.sentry.SentryLevel;
14-
import io.sentry.SentrySpanStorage;
1514
import io.sentry.SpanContext;
1615
import io.sentry.protocol.SentryId;
1716
import org.jetbrains.annotations.NotNull;
1817
import org.jetbrains.annotations.Nullable;
1918
import org.jetbrains.annotations.TestOnly;
2019

20+
/**
21+
* @deprecated this is no longer needed for the latest version of our OpenTelemetry integration.
22+
*/
23+
@Deprecated
2124
public final class OpenTelemetryLinkErrorEventProcessor implements EventProcessor {
2225

2326
private final @NotNull IScopes scopes;
24-
private final @NotNull SentrySpanStorage spanStorage = SentrySpanStorage.getInstance();
27+
28+
@SuppressWarnings("deprecation")
29+
private final @NotNull io.sentry.SentrySpanStorage spanStorage =
30+
io.sentry.SentrySpanStorage.getInstance();
2531

2632
public OpenTelemetryLinkErrorEventProcessor() {
2733
this(ScopesAdapter.getInstance());

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OtelSamplingUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@ApiStatus.Internal
1010
public final class OtelSamplingUtil {
1111

12-
public static @Nullable TracesSamplingDecision extractSamplingDecisionOrDefault(
12+
public static @NotNull TracesSamplingDecision extractSamplingDecisionOrDefault(
1313
final @NotNull Attributes attributes) {
1414
final @Nullable TracesSamplingDecision decision = extractSamplingDecision(attributes);
1515
if (decision != null) {

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/PotelSentrySpanProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri
8080
}
8181
}
8282

83-
// TODO [POTEL] what do we use as fallback here? could happen if misconfigured (i.e. sampler
84-
// not in place)
85-
final boolean sampled = samplingDecision != null ? samplingDecision.getSampled() : true;
83+
final boolean sampled =
84+
samplingDecision != null
85+
? samplingDecision.getSampled()
86+
: otelSpan.getSpanContext().isSampled();
8687

8788
final @NotNull PropagationContext propagationContext =
8889
sentryTraceHeader == null
@@ -128,7 +129,6 @@ public void onEnd(final @NotNull ReadableSpan spanBeingEnded) {
128129
new SentryLongDate(spanBeingEnded.toSpanData().getEndEpochNanos());
129130
sentrySpan.updateEndDate(finishDate);
130131
}
131-
System.out.println("span ended: " + spanBeingEnded.getSpanContext().getSpanId());
132132
}
133133

134134
@Override

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentryPropagator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.sentry.ISpan;
1515
import io.sentry.ScopesAdapter;
1616
import io.sentry.SentryLevel;
17-
import io.sentry.SentrySpanStorage;
1817
import io.sentry.SentryTraceHeader;
1918
import io.sentry.exception.InvalidSentryTraceHeaderException;
2019
import java.util.Arrays;
@@ -24,11 +23,19 @@
2423
import org.jetbrains.annotations.NotNull;
2524
import org.jetbrains.annotations.Nullable;
2625

26+
/**
27+
* @deprecated please use {@link PotelSentryPropagator} instead
28+
*/
29+
@Deprecated
2730
public final class SentryPropagator implements TextMapPropagator {
2831

2932
private static final @NotNull List<String> FIELDS =
3033
Arrays.asList(SentryTraceHeader.SENTRY_TRACE_HEADER, BaggageHeader.BAGGAGE_HEADER);
31-
private final @NotNull SentrySpanStorage spanStorage = SentrySpanStorage.getInstance();
34+
35+
@SuppressWarnings("deprecation")
36+
private final @NotNull io.sentry.SentrySpanStorage spanStorage =
37+
io.sentry.SentrySpanStorage.getInstance();
38+
3239
private final @NotNull IScopes scopes;
3340

3441
public SentryPropagator() {

0 commit comments

Comments
 (0)