Skip to content

Commit 53c2fc4

Browse files
authored
Merge 2283547 into ad8da22
2 parents ad8da22 + 2283547 commit 53c2fc4

File tree

54 files changed

+2666
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2666
-1
lines changed

.craft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ targets:
4848
maven:io.sentry:sentry-opentelemetry-agentless-spring:
4949
maven:io.sentry:sentry-opentelemetry-bootstrap:
5050
maven:io.sentry:sentry-opentelemetry-core:
51+
# maven:io.sentry:sentry-opentelemetry-otlp:
5152
maven:io.sentry:sentry-apollo:
5253
maven:io.sentry:sentry-jdbc:
5354
maven:io.sentry:sentry-graphql:

.cursor/rules/opentelemetry.mdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The Sentry Java SDK provides comprehensive OpenTelemetry integration through mul
1414
- `sentry-opentelemetry-agentless-spring`: Spring-specific agentless integration
1515
- `sentry-opentelemetry-bootstrap`: Classes that go into the bootstrap classloader when the agent is used. For agentless they are simply used in the applications classloader.
1616
- `sentry-opentelemetry-agentcustomization`: Classes that help wire up Sentry in OpenTelemetry. These land in the agent classloader when the agent is used. For agentless they are simply used in the application classloader.
17+
- `sentry-opentelemetry-otlp`: Classes for using OpenTelemetry to send spans to Sentry using the OTLP endpoint and have Sentry use OpenTelemetry trace and span id.
1718

1819
## Advantages over using Sentry without OpenTelemetry
1920

@@ -86,3 +87,9 @@ After creating the transaction with child spans `SentrySpanExporter` uses Sentry
8687
## Troubleshooting
8788

8889
To debug forking of `Scopes`, we added a reference to `parent` `Scopes` and a `creator` String to store the reason why `Scopes` were created or forked.
90+
91+
# OTLP
92+
When using `sentry-opentelemetry-otlp`, Sentry only loads trace ID and span ID from OpenTelemetry `Context` (via `OpenTelemetryOtlpEventProcessor`). Sentry does not rely on OpenTelemetry `Context` for scope storage and propagation, instead relying on its `DefaultScopesStorage`.
93+
It is common to keep Performance in Sentry SDK disabled since that part is taken over by OpenTelemetry.
94+
The `sentry-opentelemetry-otlp` module is not connected to the other `sentry-opentelemetry-*` modules but instead intended only when the goal is to run OpenTelemetry for creating spans and Sentry for other products like errors, logs, metrics etc.
95+
The OTLP module does not easily work with the OpenTelemetry agent as it would require customizing the agent.JAR in order to get the propagator loaded.

.github/workflows/system-tests-backend.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ jobs:
5454
- sample: "sentry-samples-console"
5555
agent: "false"
5656
agent-auto-init: "true"
57+
- sample: "sentry-samples-console-otlp"
58+
agent: "false"
59+
agent-auto-init: "true"
5760
- sample: "sentry-samples-logback"
5861
agent: "false"
5962
agent-auto-init: "true"
@@ -78,6 +81,9 @@ jobs:
7881
- sample: "sentry-samples-spring-boot-4-opentelemetry"
7982
agent: "true"
8083
agent-auto-init: "false"
84+
- sample: "sentry-samples-spring-boot-4-otlp"
85+
agent: "false"
86+
agent-auto-init: "true"
8187
- sample: "sentry-samples-spring-7"
8288
agent: "false"
8389
agent-auto-init: "true"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Sentry SDK for Java and Android
6565
| sentry-opentelemetry-agent | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-opentelemetry-agent?style=for-the-badge&logo=sentry&color=green) |
6666
| sentry-opentelemetry-agentcustomization | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-opentelemetry-agentcustomization?style=for-the-badge&logo=sentry&color=green) |
6767
| sentry-opentelemetry-core | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-opentelemetry-core?style=for-the-badge&logo=sentry&color=green) |
68+
| sentry-opentelemetry-otlp | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-opentelemetry-otlp?style=for-the-badge&logo=sentry&color=green) |
6869
| sentry-okhttp | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-okhttp?style=for-the-badge&logo=sentry&color=green) |
6970
| sentry-reactor | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-reactor?style=for-the-badge&logo=sentry&color=green) |
7071
| sentry-spotlight | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-spotlight?style=for-the-badge&logo=sentry&color=green) |

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ apiValidation {
7777
"sentry-samples-spring-boot-4",
7878
"sentry-samples-spring-boot-4-opentelemetry",
7979
"sentry-samples-spring-boot-4-opentelemetry-noagent",
80+
"sentry-samples-spring-boot-4-otlp",
8081
"sentry-samples-spring-boot-4-webflux",
8182
"sentry-samples-ktor-client",
8283
"sentry-uitest-android",
@@ -85,7 +86,8 @@ apiValidation {
8586
"test-app-plain",
8687
"test-app-sentry",
8788
"test-app-size",
88-
"sentry-samples-netflix-dgs"
89+
"sentry-samples-netflix-dgs",
90+
"sentry-samples-console-otlp"
8991
)
9092
)
9193
}

buildSrc/src/main/java/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object Config {
6464
val SENTRY_SPRING_BOOT_4_STARTER_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot-4-starter"
6565
val SENTRY_OPENTELEMETRY_BOOTSTRAP_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.bootstrap"
6666
val SENTRY_OPENTELEMETRY_CORE_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.core"
67+
val SENTRY_OPENTELEMETRY_OTLP_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.otlp"
6768
val SENTRY_OPENTELEMETRY_AGENT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agent"
6869
val SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agentless"
6970
val SENTRY_OPENTELEMETRY_AGENTLESS_SPRING_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agentless-spring"

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
134134
okhttp-bom = { module = "com.squareup.okhttp3:okhttp-bom", version.ref = "okhttp" }
135135
openfeature = { module = "dev.openfeature:sdk", version.ref = "openfeature" }
136136
otel = { module = "io.opentelemetry:opentelemetry-sdk", version.ref = "otel" }
137+
otel-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporter-otlp", version.ref = "otel" }
138+
otel-exporter-logging = { module = "io.opentelemetry:opentelemetry-exporter-logging", version.ref = "otel" }
137139
otel-extension-autoconfigure = { module = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure", version.ref = "otel" }
138140
otel-extension-autoconfigure-spi = { module = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi", version.ref = "otel" }
139141
otel-instrumentation-bom = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom", version.ref = "otelInstrumentation" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# sentry-opentelemetry-otlp
2+
3+
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.
4+
5+
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.
6+
7+
Please consult the documentation on how to install and use this integration in the [Sentry Docs for Java](https://docs.sentry.io/platforms/java/).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public final class io/sentry/opentelemetry/otlp/OpenTelemetryOtlpEventProcessor : io/sentry/EventProcessor {
2+
public fun <init> ()V
3+
public fun getOrder ()Ljava/lang/Long;
4+
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
5+
public fun process (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent;
6+
public fun process (Lio/sentry/SentryMetricsEvent;Lio/sentry/Hint;)Lio/sentry/SentryMetricsEvent;
7+
}
8+
9+
public final class io/sentry/opentelemetry/otlp/OpenTelemetryOtlpPropagator : io/opentelemetry/context/propagation/TextMapPropagator {
10+
public static final field SENTRY_BAGGAGE_KEY Lio/opentelemetry/context/ContextKey;
11+
public fun <init> ()V
12+
public fun extract (Lio/opentelemetry/context/Context;Ljava/lang/Object;Lio/opentelemetry/context/propagation/TextMapGetter;)Lio/opentelemetry/context/Context;
13+
public fun fields ()Ljava/util/Collection;
14+
public fun inject (Lio/opentelemetry/context/Context;Ljava/lang/Object;Lio/opentelemetry/context/propagation/TextMapSetter;)V
15+
}
16+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import net.ltgt.gradle.errorprone.errorprone
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
`java-library`
6+
id("io.sentry.javadoc")
7+
alias(libs.plugins.kotlin.jvm)
8+
jacoco
9+
alias(libs.plugins.errorprone)
10+
alias(libs.plugins.gradle.versions)
11+
}
12+
13+
tasks.withType<KotlinCompile>().configureEach {
14+
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
15+
}
16+
17+
dependencies {
18+
api(projects.sentry)
19+
20+
compileOnly(libs.otel)
21+
// compileOnly(libs.otel.semconv)
22+
// compileOnly(libs.otel.semconv.incubating)
23+
24+
compileOnly(libs.jetbrains.annotations)
25+
compileOnly(libs.nopen.annotations)
26+
errorprone(libs.errorprone.core)
27+
errorprone(libs.nopen.checker)
28+
errorprone(libs.nullaway)
29+
30+
// tests
31+
testImplementation(projects.sentryTestSupport)
32+
testImplementation(kotlin(Config.kotlinStdLib))
33+
testImplementation(libs.awaitility.kotlin)
34+
testImplementation(libs.kotlin.test.junit)
35+
testImplementation(libs.mockito.kotlin)
36+
37+
testImplementation(libs.otel)
38+
// testImplementation(libs.otel.semconv)
39+
// testImplementation(libs.otel.semconv.incubating)
40+
}
41+
42+
configure<SourceSetContainer> { test { java.srcDir("src/test/java") } }
43+
44+
jacoco { toolVersion = libs.versions.jacoco.get() }
45+
46+
tasks.jacocoTestReport {
47+
reports {
48+
xml.required.set(true)
49+
html.required.set(false)
50+
}
51+
}
52+
53+
tasks {
54+
jacocoTestCoverageVerification {
55+
violationRules { rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } }
56+
}
57+
check {
58+
dependsOn(jacocoTestCoverageVerification)
59+
dependsOn(jacocoTestReport)
60+
}
61+
}
62+
63+
tasks.withType<JavaCompile>().configureEach {
64+
options.errorprone {
65+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
66+
option("NullAway:AnnotatedPackages", "io.sentry")
67+
}
68+
}
69+
70+
tasks.jar {
71+
manifest {
72+
attributes(
73+
"Sentry-Version-Name" to project.version,
74+
"Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_OTLP_SDK_NAME,
75+
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-opentelemetry-otlp",
76+
"Implementation-Vendor" to "Sentry",
77+
"Implementation-Title" to project.name,
78+
"Implementation-Version" to project.version,
79+
)
80+
}
81+
}

0 commit comments

Comments
 (0)