-
-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenTelemetryLinkErrorEventProcessor for linking errors to traces…
… created via OpenTelemetry (#2418)
- Loading branch information
Showing
8 changed files
with
71 additions
and
9 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
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