-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add OpenTelemetryLinkErrorEventProcessor for linking errors to traces created via OpenTelemetry #2418
Merged
adinauer
merged 2 commits into
feat/allow-turning-off-auto-init-in-otel-agent
from
feat/link-errors-to-otel-created-traces
Dec 6, 2022
Merged
Add OpenTelemetryLinkErrorEventProcessor for linking errors to traces created via OpenTelemetry #2418
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
50 changes: 50 additions & 0 deletions
50
...etry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryLinkErrorEventProcessor.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,50 @@ | ||
package io.sentry.opentelemetry; | ||
|
||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanId; | ||
import io.opentelemetry.api.trace.TraceId; | ||
import io.sentry.EventProcessor; | ||
import io.sentry.Hint; | ||
import io.sentry.HubAdapter; | ||
import io.sentry.ISpan; | ||
import io.sentry.Instrumenter; | ||
import io.sentry.SentryEvent; | ||
import io.sentry.SentrySpanStorage; | ||
import io.sentry.SpanContext; | ||
import io.sentry.protocol.SentryId; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class OpenTelemetryLinkErrorEventProcessor implements EventProcessor { | ||
|
||
private final @NotNull SentrySpanStorage spanStorage = SentrySpanStorage.getInstance(); | ||
|
||
@Override | ||
public @Nullable SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { | ||
if (Instrumenter.OTEL.equals(HubAdapter.getInstance().getOptions().getInstrumenter())) { | ||
@NotNull final Span otelSpan = Span.current(); | ||
@NotNull final String traceId = otelSpan.getSpanContext().getTraceId(); | ||
@NotNull final String spanId = otelSpan.getSpanContext().getSpanId(); | ||
|
||
if (TraceId.isValid(traceId) && SpanId.isValid(spanId)) { | ||
final @Nullable ISpan sentrySpan = spanStorage.get(spanId); | ||
if (sentrySpan != null) { | ||
final @NotNull SpanContext sentrySpanSpanContext = sentrySpan.getSpanContext(); | ||
final @NotNull String operation = sentrySpanSpanContext.getOperation(); | ||
final @Nullable io.sentry.SpanId parentSpanId = sentrySpanSpanContext.getParentSpanId(); | ||
final @NotNull SpanContext spanContext = | ||
new SpanContext( | ||
new SentryId(traceId), | ||
new io.sentry.SpanId(spanId), | ||
operation, | ||
parentSpanId, | ||
null); | ||
|
||
event.getContexts().setTrace(spanContext); | ||
} | ||
} | ||
} | ||
|
||
return event; | ||
} | ||
} |
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
7 changes: 5 additions & 2 deletions
7
...ntry/opentelemetry/SentrySpanStorage.java → ...ain/java/io/sentry/SentrySpanStorage.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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
l: I'm probably missing some context here, but is it fine to override the existing trace context?
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.
I'd say yes because it only does so in case instrumenter is set to
otel
, there's an OTEL span with valid IDs and it can find the Sentry span in the shared storage. For now we don't allow starting transactions outside of OTEL if instrumenter is set tootel
. So there shouldn't be anything worth keeping in there.