Skip to content

Commit 6c03ee9

Browse files
feat(otel): Create sentry-opentelemetry-otlp module for combining OpenTelemetry SDK OTLP export with Sentry SDK (#5100)
* Create sentry-opentelemetry-otlp module and OTLP sample for Spring Boot 4 * Format code * also set trace id and span id for logs and metrics * Format code * add console otlp sample; some missing things; cleanup * simplify usage by adding an SPI file and propagator provider class * changelog * adapt test to modifications from original console sample * add otel dependencies to otlp module so it is easier to use * add sentry-opentelemetry-otlp-spring module * update changelog * read sentry-trace header for sampled / non sampled TraceFlags * update opentelemetry.mdc to mention otlp-spring module * convert to api dependencies * only add baggage to context if actually present --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent 9dc12d1 commit 6c03ee9

File tree

57 files changed

+2765
-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.

57 files changed

+2765
-1
lines changed

.craft.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ 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:
52+
# maven:io.sentry:sentry-opentelemetry-otlp-spring:
5153
maven:io.sentry:sentry-apollo:
5254
maven:io.sentry:sentry-jdbc:
5355
maven:io.sentry:sentry-graphql:

.cursor/rules/opentelemetry.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ 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.
18+
- `sentry-opentelemetry-otlp-spring`: Spring Boot convenience module that includes `sentry-opentelemetry-otlp` and the OpenTelemetry Spring Boot starter as transitive dependencies.
1719

1820
## Advantages over using Sentry without OpenTelemetry
1921

@@ -86,3 +88,10 @@ After creating the transaction with child spans `SentrySpanExporter` uses Sentry
8688
## Troubleshooting
8789

8890
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.
91+
92+
# OTLP
93+
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`.
94+
It is common to keep Performance in Sentry SDK disabled since that part is taken over by OpenTelemetry.
95+
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.
96+
The `sentry-opentelemetry-otlp-spring` module wraps `sentry-opentelemetry-otlp` and includes the OpenTelemetry Spring Boot starter for easier setup in Spring Boot applications.
97+
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"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
### Features
66

7+
- Create `sentry-opentelemetry-otlp` and `sentry-opentelemetry-otlp-spring` modules for combining OpenTelemetry SDK OTLP export with Sentry SDK ([#5100](https://github.com/getsentry/sentry-java/pull/5100))
8+
- OpenTelemetry is configured to send spans to Sentry directly using an OTLP endpoint.
9+
- Sentry only uses trace and span ID from OpenTelemetry (via `OpenTelemetryOtlpEventProcessor`) but will not send spans through OpenTelemetry nor use OpenTelemetry `Context` for `Scopes` propagation.
10+
- See the OTLP setup docs for [Java](https://docs.sentry.io/platforms/java/opentelemetry/setup/otlp/) and [Spring Boot](https://docs.sentry.io/platforms/java/guides/spring-boot/opentelemetry/setup/otlp/) for installation and configuration instructions.
711
- Add screenshot masking support using view hierarchy ([#5077](https://github.com/getsentry/sentry-java/pull/5077))
812
- Masks sensitive content (text, images) in error screenshots using the same view hierarchy approach as Session Replay
913
- Requires the `sentry-android-replay` module to be present at runtime for masking to work

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ 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) |
69+
| sentry-opentelemetry-otlp-spring | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-opentelemetry-otlp-spring?style=for-the-badge&logo=sentry&color=green) |
6870
| sentry-okhttp | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-okhttp?style=for-the-badge&logo=sentry&color=green) |
6971
| sentry-reactor | ![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-reactor?style=for-the-badge&logo=sentry&color=green) |
7072
| 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ 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"
68+
val SENTRY_OPENTELEMETRY_OTLP_SPRING_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.otlp-spring"
6769
val SENTRY_OPENTELEMETRY_AGENT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agent"
6870
val SENTRY_OPENTELEMETRY_AGENTLESS_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.opentelemetry.agentless"
6971
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-spring
2+
3+
This module combines `sentry-opentelemetry-otlp` with the OpenTelemetry Spring Boot Starter for a simpler setup in Spring Boot applications.
4+
5+
It is intended for setups where OpenTelemetry handles tracing (with spans exported via OTLP to Sentry) while 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/opentelemetry/setup/otlp/).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
`java-library`
3+
id("io.sentry.javadoc")
4+
}
5+
6+
dependencies {
7+
api(projects.sentryOpentelemetry.sentryOpentelemetryOtlp)
8+
implementation(libs.springboot3.otel)
9+
}
10+
11+
tasks.jar {
12+
manifest {
13+
attributes(
14+
"Sentry-Version-Name" to project.version,
15+
"Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENTELEMETRY_OTLP_SPRING_SDK_NAME,
16+
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-opentelemetry-otlp-spring",
17+
"Implementation-Vendor" to "Sentry",
18+
"Implementation-Title" to project.name,
19+
"Implementation-Version" to project.version,
20+
)
21+
}
22+
}

0 commit comments

Comments
 (0)