-
-
Notifications
You must be signed in to change notification settings - Fork 466
feat(otel): Create sentry-opentelemetry-otlp module for combining OpenTelemetry SDK OTLP export with Sentry SDK
#5100
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
Open
adinauer
wants to merge
9
commits into
main
Choose a base branch
from
feat/otlp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fb8fd83
Create sentry-opentelemetry-otlp module and OTLP sample for Spring Bo…
adinauer aaab229
Format code
getsentry-bot 476d7f1
also set trace id and span id for logs and metrics
adinauer 4beac30
Format code
getsentry-bot 2283547
add console otlp sample; some missing things; cleanup
adinauer e667a21
Merge branch 'main' into feat/otlp
adinauer 24f5720
simplify usage by adding an SPI file and propagator provider class
adinauer 0504c3c
changelog
adinauer a574637
adapt test to modifications from original console sample
adinauer 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| # sentry-opentelemetry-otlp | ||
|
|
||
| This module provides a lightweight integration for using OpenTelemetry alongside the Sentry SDK. It reads trace and span IDs from the OpenTelemetry `Context` so that Sentry events (errors, logs, metrics) are correlated with OpenTelemetry traces. | ||
|
|
||
| Unlike the other `sentry-opentelemetry-*` modules, this module does not rely on OpenTelemetry for scope storage or span creation. It is intended for setups where OpenTelemetry handles performance/tracing and Sentry handles errors, logs, metrics, and other products. | ||
|
|
||
| Please consult the documentation on how to install and use this integration in the [Sentry Docs for Java](https://docs.sentry.io/platforms/java/). |
22 changes: 22 additions & 0 deletions
22
sentry-opentelemetry/sentry-opentelemetry-otlp/api/sentry-opentelemetry-otlp.api
This file contains hidden or 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,22 @@ | ||
| public final class io/sentry/opentelemetry/otlp/OpenTelemetryOtlpEventProcessor : io/sentry/EventProcessor { | ||
| public fun <init> ()V | ||
| public fun getOrder ()Ljava/lang/Long; | ||
| public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent; | ||
| public fun process (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent; | ||
| public fun process (Lio/sentry/SentryMetricsEvent;Lio/sentry/Hint;)Lio/sentry/SentryMetricsEvent; | ||
| } | ||
|
|
||
| public final class io/sentry/opentelemetry/otlp/OpenTelemetryOtlpPropagator : io/opentelemetry/context/propagation/TextMapPropagator { | ||
| public static final field SENTRY_BAGGAGE_KEY Lio/opentelemetry/context/ContextKey; | ||
| public fun <init> ()V | ||
| public fun extract (Lio/opentelemetry/context/Context;Ljava/lang/Object;Lio/opentelemetry/context/propagation/TextMapGetter;)Lio/opentelemetry/context/Context; | ||
| public fun fields ()Ljava/util/Collection; | ||
| public fun inject (Lio/opentelemetry/context/Context;Ljava/lang/Object;Lio/opentelemetry/context/propagation/TextMapSetter;)V | ||
| } | ||
|
|
||
| public final class io/sentry/opentelemetry/otlp/OpenTelemetryOtlpPropagatorProvider : io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider { | ||
| public fun <init> ()V | ||
| public fun getName ()Ljava/lang/String; | ||
| public fun getPropagator (Lio/opentelemetry/sdk/autoconfigure/spi/ConfigProperties;)Lio/opentelemetry/context/propagation/TextMapPropagator; | ||
| } | ||
|
|
82 changes: 82 additions & 0 deletions
82
sentry-opentelemetry/sentry-opentelemetry-otlp/build.gradle.kts
This file contains hidden or 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,82 @@ | ||
| import net.ltgt.gradle.errorprone.errorprone | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| `java-library` | ||
| id("io.sentry.javadoc") | ||
| alias(libs.plugins.kotlin.jvm) | ||
| jacoco | ||
| alias(libs.plugins.errorprone) | ||
| alias(libs.plugins.gradle.versions) | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 | ||
| } | ||
|
|
||
| dependencies { | ||
| api(projects.sentry) | ||
|
|
||
| compileOnly(libs.otel) | ||
| compileOnly(libs.otel.extension.autoconfigure.spi) | ||
| // compileOnly(libs.otel.semconv) | ||
| // compileOnly(libs.otel.semconv.incubating) | ||
|
|
||
| compileOnly(libs.jetbrains.annotations) | ||
| compileOnly(libs.nopen.annotations) | ||
| errorprone(libs.errorprone.core) | ||
| errorprone(libs.nopen.checker) | ||
| errorprone(libs.nullaway) | ||
|
|
||
| // tests | ||
| testImplementation(projects.sentryTestSupport) | ||
| testImplementation(kotlin(Config.kotlinStdLib)) | ||
| testImplementation(libs.awaitility.kotlin) | ||
| testImplementation(libs.kotlin.test.junit) | ||
| testImplementation(libs.mockito.kotlin) | ||
|
|
||
| testImplementation(libs.otel) | ||
| // testImplementation(libs.otel.semconv) | ||
| // testImplementation(libs.otel.semconv.incubating) | ||
| } | ||
|
|
||
| configure<SourceSetContainer> { test { java.srcDir("src/test/java") } } | ||
|
|
||
| jacoco { toolVersion = libs.versions.jacoco.get() } | ||
|
|
||
| tasks.jacocoTestReport { | ||
| reports { | ||
| xml.required.set(true) | ||
| html.required.set(false) | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| jacocoTestCoverageVerification { | ||
| violationRules { rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } } | ||
| } | ||
| check { | ||
| dependsOn(jacocoTestCoverageVerification) | ||
| dependsOn(jacocoTestReport) | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<JavaCompile>().configureEach { | ||
| options.errorprone { | ||
| check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) | ||
| option("NullAway:AnnotatedPackages", "io.sentry") | ||
| } | ||
| } | ||
|
|
||
| tasks.jar { | ||
| manifest { | ||
| attributes( | ||
| "Sentry-Version-Name" to project.version, | ||
| "Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_OTLP_SDK_NAME, | ||
| "Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-opentelemetry-otlp", | ||
| "Implementation-Vendor" to "Sentry", | ||
| "Implementation-Title" to project.name, | ||
| "Implementation-Version" to project.version, | ||
| ) | ||
| } | ||
| } |
120 changes: 120 additions & 0 deletions
120
...etry-otlp/src/main/java/io/sentry/opentelemetry/otlp/OpenTelemetryOtlpEventProcessor.java
This file contains hidden or 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,120 @@ | ||
| package io.sentry.opentelemetry.otlp; | ||
|
|
||
| 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.IScopes; | ||
| import io.sentry.ScopesAdapter; | ||
| import io.sentry.SentryEvent; | ||
| import io.sentry.SentryLevel; | ||
| import io.sentry.SentryLogEvent; | ||
| import io.sentry.SentryMetricsEvent; | ||
| import io.sentry.SpanContext; | ||
| import io.sentry.protocol.SentryId; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.jetbrains.annotations.TestOnly; | ||
|
|
||
| public final class OpenTelemetryOtlpEventProcessor implements EventProcessor { | ||
|
|
||
| private final @NotNull IScopes scopes; | ||
|
|
||
| public OpenTelemetryOtlpEventProcessor() { | ||
| this(ScopesAdapter.getInstance()); | ||
| } | ||
|
|
||
| @TestOnly | ||
| OpenTelemetryOtlpEventProcessor(final @NotNull IScopes scopes) { | ||
| this.scopes = scopes; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { | ||
| @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 @NotNull SpanContext spanContext = | ||
| new SpanContext( | ||
| new SentryId(traceId), new io.sentry.SpanId(spanId), "opentelemetry", null, null); | ||
|
|
||
| event.getContexts().setTrace(spanContext); | ||
| scopes | ||
| .getOptions() | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.DEBUG, | ||
| "Linking Sentry event %s to span %s created via OpenTelemetry (trace %s).", | ||
| event.getEventId(), | ||
| spanId, | ||
| traceId); | ||
| } else { | ||
| scopes | ||
| .getOptions() | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.DEBUG, | ||
| "Not linking Sentry event %s to any transaction created via OpenTelemetry as traceId %s or spanId %s are invalid.", | ||
| event.getEventId(), | ||
| traceId, | ||
| spanId); | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable SentryLogEvent process(@NotNull SentryLogEvent event) { | ||
| @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)) { | ||
| event.setTraceId(new SentryId(traceId)); | ||
| event.setSpanId(new io.sentry.SpanId(spanId)); | ||
| } else { | ||
| scopes | ||
| .getOptions() | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.DEBUG, | ||
| "Not linking Sentry event to any transaction created via OpenTelemetry as traceId %s or spanId %s are invalid.", | ||
| traceId, | ||
| spanId); | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable SentryMetricsEvent process( | ||
| @NotNull SentryMetricsEvent event, @NotNull Hint hint) { | ||
| @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)) { | ||
| event.setTraceId(new SentryId(traceId)); | ||
| event.setSpanId(new io.sentry.SpanId(spanId)); | ||
| } else { | ||
| scopes | ||
| .getOptions() | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.DEBUG, | ||
| "Not linking Sentry event to any transaction created via OpenTelemetry as traceId %s or spanId %s are invalid.", | ||
| traceId, | ||
| spanId); | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable Long getOrder() { | ||
| return 6000L; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
👀 new event processor