|
9 | 9 | import io.sentry.ScopesAdapter; |
10 | 10 | import io.sentry.SentryEvent; |
11 | 11 | import io.sentry.SentryLevel; |
| 12 | +import io.sentry.SentryLogEvent; |
| 13 | +import io.sentry.SentryMetricsEvent; |
12 | 14 | import io.sentry.SpanContext; |
13 | 15 | import io.sentry.protocol.SentryId; |
14 | 16 | import org.jetbrains.annotations.NotNull; |
@@ -39,8 +41,8 @@ public OpenTelemetryOtlpEventProcessor() { |
39 | 41 | new SpanContext( |
40 | 42 | new SentryId(traceId), |
41 | 43 | new io.sentry.SpanId(spanId), |
42 | | - "opentelemetry", // TODO probably no way to get span name |
43 | | - null, // TODO where to get parent id from? |
| 44 | + "opentelemetry", |
| 45 | + null, |
44 | 46 | null); |
45 | 47 |
|
46 | 48 | event.getContexts().setTrace(spanContext); |
@@ -68,6 +70,52 @@ public OpenTelemetryOtlpEventProcessor() { |
68 | 70 | return event; |
69 | 71 | } |
70 | 72 |
|
| 73 | + @Override |
| 74 | + public @Nullable SentryLogEvent process(@NotNull SentryLogEvent event) { |
| 75 | + @NotNull final Span otelSpan = Span.current(); |
| 76 | + @NotNull final String traceId = otelSpan.getSpanContext().getTraceId(); |
| 77 | + @NotNull final String spanId = otelSpan.getSpanContext().getSpanId(); |
| 78 | + |
| 79 | + if (TraceId.isValid(traceId) && SpanId.isValid(spanId)) { |
| 80 | + event.setTraceId(new SentryId(traceId)); |
| 81 | + event.setSpanId(new io.sentry.SpanId(spanId)); |
| 82 | + } else { |
| 83 | + scopes |
| 84 | + .getOptions() |
| 85 | + .getLogger() |
| 86 | + .log( |
| 87 | + SentryLevel.DEBUG, |
| 88 | + "Not linking Sentry event to any transaction created via OpenTelemetry as traceId %s or spanId %s are invalid.", |
| 89 | + traceId, |
| 90 | + spanId); |
| 91 | + } |
| 92 | + |
| 93 | + return event; |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public @Nullable SentryMetricsEvent process(@NotNull SentryMetricsEvent event, @NotNull Hint hint) { |
| 98 | + @NotNull final Span otelSpan = Span.current(); |
| 99 | + @NotNull final String traceId = otelSpan.getSpanContext().getTraceId(); |
| 100 | + @NotNull final String spanId = otelSpan.getSpanContext().getSpanId(); |
| 101 | + |
| 102 | + if (TraceId.isValid(traceId) && SpanId.isValid(spanId)) { |
| 103 | + event.setTraceId(new SentryId(traceId)); |
| 104 | + event.setSpanId(new io.sentry.SpanId(spanId)); |
| 105 | + } else { |
| 106 | + scopes |
| 107 | + .getOptions() |
| 108 | + .getLogger() |
| 109 | + .log( |
| 110 | + SentryLevel.DEBUG, |
| 111 | + "Not linking Sentry event to any transaction created via OpenTelemetry as traceId %s or spanId %s are invalid.", |
| 112 | + traceId, |
| 113 | + spanId); |
| 114 | + } |
| 115 | + |
| 116 | + return event; |
| 117 | + } |
| 118 | + |
71 | 119 | @Override |
72 | 120 | public @Nullable Long getOrder() { |
73 | 121 | return 6000L; |
|
0 commit comments