-
-
Notifications
You must be signed in to change notification settings - Fork 451
Support globalHubMode
for OpenTelemetry
#4349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f15dbbb
3c77729
20c7fef
049f59f
8c076b0
46170d4
1267993
66c10d9
f8a9c45
c072000
0ba317a
cddb1f0
0f63cb1
61e6d3e
965c00b
a18ffa8
094355c
205ad8a
4d4f6a8
c02df17
54c4b94
be70b9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,43 @@ private SentryContextWrapper(final @NotNull Context delegate) { | |
} | ||
|
||
@Override | ||
public <V> V get(final @NotNull ContextKey<V> contextKey) { | ||
return delegate.get(contextKey); | ||
public <V> @Nullable V get(final @NotNull ContextKey<V> contextKey) { | ||
final @Nullable V result = delegate.get(contextKey); | ||
if (shouldReturnRootSpanInstead(contextKey, result)) { | ||
return returnUnfinishedRootSpanIfAvailable(result); | ||
} | ||
return result; | ||
} | ||
|
||
private <V> boolean shouldReturnRootSpanInstead( | ||
final @NotNull ContextKey<V> contextKey, final @Nullable V result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (l) not sure about the param naming. Would something other than |
||
if (!Sentry.isGlobalHubMode()) { | ||
return false; | ||
} | ||
if (!isOpentelemetrySpan(contextKey)) { | ||
return false; | ||
} | ||
if (result == null) { | ||
return true; | ||
} | ||
if (result instanceof SentryOtelGlobalHubModeSpan) { | ||
return true; | ||
} | ||
return result instanceof Span && !((Span) result).getSpanContext().isValid(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private <V> @Nullable V returnUnfinishedRootSpanIfAvailable(final @Nullable V result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (l) not sure about the param naming. Would something other than |
||
final @Nullable IOtelSpanWrapper sentrySpan = | ||
SentryWeakSpanStorage.getInstance().getLastKnownUnfinishedRootSpan(); | ||
if (sentrySpan != null) { | ||
try { | ||
return (V) sentrySpan.getOpenTelemetrySpan(); | ||
} catch (Throwable t) { | ||
return result; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.sentry.opentelemetry; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanContext; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import java.util.concurrent.TimeUnit; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Experimental | ||
public final class SentryOtelGlobalHubModeSpan implements Span { | ||
|
||
private @NotNull Span getOtelSpan() { | ||
final @Nullable IOtelSpanWrapper lastKnownUnfinishedRootSpan = | ||
SentryWeakSpanStorage.getInstance().getLastKnownUnfinishedRootSpan(); | ||
if (lastKnownUnfinishedRootSpan != null) { | ||
final @Nullable Span openTelemetrySpan = lastKnownUnfinishedRootSpan.getOpenTelemetrySpan(); | ||
if (openTelemetrySpan != null) { | ||
return openTelemetrySpan; | ||
} | ||
} | ||
|
||
return Span.getInvalid(); | ||
} | ||
|
||
@Override | ||
public <T> Span setAttribute(AttributeKey<T> key, T value) { | ||
return getOtelSpan().setAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name, Attributes attributes) { | ||
return getOtelSpan().addEvent(name, attributes); | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name, Attributes attributes, long timestamp, TimeUnit unit) { | ||
return getOtelSpan().addEvent(name, attributes, timestamp, unit); | ||
} | ||
|
||
@Override | ||
public Span setStatus(StatusCode statusCode, String description) { | ||
return getOtelSpan().setStatus(statusCode, description); | ||
} | ||
|
||
@Override | ||
public Span recordException(Throwable exception, Attributes additionalAttributes) { | ||
return getOtelSpan().recordException(exception, additionalAttributes); | ||
} | ||
|
||
@Override | ||
public Span updateName(String name) { | ||
return getOtelSpan().updateName(name); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
getOtelSpan().end(); | ||
} | ||
|
||
@Override | ||
public void end(long timestamp, TimeUnit unit) { | ||
getOtelSpan().end(timestamp, unit); | ||
} | ||
|
||
@Override | ||
public SpanContext getSpanContext() { | ||
return getOtelSpan().getSpanContext(); | ||
} | ||
|
||
@Override | ||
public boolean isRecording() { | ||
return getOtelSpan().isRecording(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 8.11.0
.Consider moving the entry to the
## Unreleased
section, please.