-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POTEL 6 - Use OpenTelemetry span status for Sentry span API (#3439)
* 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
- Loading branch information
Showing
7 changed files
with
136 additions
and
21 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
88 changes: 88 additions & 0 deletions
88
...sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelSpanContext.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,88 @@ | ||
package io.sentry.opentelemetry; | ||
|
||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.data.StatusData; | ||
import io.sentry.SpanContext; | ||
import io.sentry.SpanId; | ||
import io.sentry.SpanStatus; | ||
import io.sentry.protocol.SentryId; | ||
import java.lang.ref.WeakReference; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class OtelSpanContext extends SpanContext { | ||
|
||
/** | ||
* OpenTelemetry span which this wrapper wraps. Needs to be referenced weakly as otherwise we'd | ||
* create a circular reference from {@link io.opentelemetry.sdk.trace.data.SpanData} to {@link | ||
* OtelSpanWrapper} and indirectly back to {@link io.opentelemetry.sdk.trace.data.SpanData} via | ||
* {@link Span}. Also see {@link SentryWeakSpanStorage}. | ||
*/ | ||
private final @NotNull WeakReference<ReadWriteSpan> span; | ||
|
||
public OtelSpanContext(final @NotNull ReadWriteSpan span, final @Nullable Span parentSpan) { | ||
// TODO [POTEL] tracesSamplingDecision | ||
super( | ||
new SentryId(span.getSpanContext().getTraceId()), | ||
new SpanId(span.getSpanContext().getSpanId()), | ||
parentSpan == null ? null : new SpanId(parentSpan.getSpanContext().getSpanId()), | ||
span.getName(), | ||
null, | ||
null, | ||
null, | ||
null); | ||
this.span = new WeakReference<>(span); | ||
} | ||
|
||
@Override | ||
public @Nullable SpanStatus getStatus() { | ||
final @Nullable ReadWriteSpan otelSpan = span.get(); | ||
|
||
if (otelSpan != null) { | ||
final @NotNull StatusData otelStatus = otelSpan.toSpanData().getStatus(); | ||
final @NotNull String otelStatusDescription = otelStatus.getDescription(); | ||
if (otelStatusDescription.isEmpty()) { | ||
return otelStatusCodeFallback(otelStatus); | ||
} | ||
final @Nullable SpanStatus spanStatus = SpanStatus.fromApiNameSafely(otelStatusDescription); | ||
if (spanStatus == null) { | ||
return otelStatusCodeFallback(otelStatus); | ||
} | ||
return spanStatus; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void setStatus(@Nullable SpanStatus status) { | ||
if (status != null) { | ||
final @Nullable ReadWriteSpan otelSpan = span.get(); | ||
if (otelSpan != null) { | ||
final @NotNull StatusCode statusCode = translateStatusCode(status); | ||
otelSpan.setStatus(statusCode, status.apiName()); | ||
} | ||
} | ||
} | ||
|
||
private @Nullable SpanStatus otelStatusCodeFallback(final @NotNull StatusData otelStatus) { | ||
if (otelStatus.getStatusCode() == StatusCode.ERROR) { | ||
return SpanStatus.UNKNOWN_ERROR; | ||
} else if (otelStatus.getStatusCode() == StatusCode.OK) { | ||
return SpanStatus.OK; | ||
} | ||
return null; | ||
} | ||
|
||
private @NotNull StatusCode translateStatusCode(final @Nullable SpanStatus status) { | ||
if (status == null) { | ||
return StatusCode.UNSET; | ||
} else if (status == SpanStatus.OK) { | ||
return StatusCode.OK; | ||
} else { | ||
return StatusCode.ERROR; | ||
} | ||
} | ||
} |
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
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
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
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
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