Skip to content

Commit 0735f22

Browse files
adinauerclaude
andauthored
docs(java): Add OpenTelemetry OTLP setup documentation (#16551)
## Summary - Adds a new OTLP section to the OpenTelemetry setup index page explaining the lightweight OTLP integration - Creates a new `otlp.mdx` setup page with install and configuration instructions for both plain Java (`sentry-opentelemetry-otlp`) and Spring Boot (`sentry-opentelemetry-otlp-spring`) - Uses `___OTLP_TRACES_URL___` and `___PUBLIC_KEY___` placeholders for auto-populated endpoint/auth values Companion to getsentry/sentry-java#5100 ## Test plan - [ ] Verify the OTLP section renders on `/platforms/java/opentelemetry/setup/` - [ ] Verify the OTLP detail page renders at `/platforms/java/opentelemetry/setup/otlp/` - [ ] Verify Spring Boot variant renders at `/platforms/java/guides/spring-boot/opentelemetry/setup/otlp/` - [ ] Verify `___OTLP_TRACES_URL___`, `___PUBLIC_KEY___`, and `___PUBLIC_DSN___` placeholders resolve for logged-in users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent daf7a49 commit 0735f22

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

docs/platforms/java/common/opentelemetry/setup/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ For a guide on how to set up `sentry-opentelemetry-agent`, please have a look at
1818
<PlatformContent includePath="performance/opentelemetry-setup/agentless-explanation" />
1919

2020
For a guide on how to set up agentless, please have a look at <PlatformLink to="/opentelemetry/setup/agentless">the detailed Agentless docs</PlatformLink>.
21+
22+
## OTLP
23+
24+
If you want OpenTelemetry to handle tracing and export spans via OTLP directly to Sentry, while Sentry handles errors, logs, and metrics, you can use the `sentry-opentelemetry-otlp` module. This is a lightweight integration where Sentry only reads the trace and span IDs from the OpenTelemetry `Context` to correlate its events with OpenTelemetry traces. Unlike the Agent and Agentless integrations above, it does not use OpenTelemetry for scope storage or span creation within the Sentry SDK.
25+
26+
For a guide on how to set up OTLP, please have a look at <PlatformLink to="/opentelemetry/setup/otlp">the detailed OTLP docs</PlatformLink>.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
title: OpenTelemetry OTLP
3+
sdk: sentry.java
4+
description: "Using OpenTelemetry OTLP export with Sentry."
5+
sidebar_order: 300
6+
---
7+
8+
Use the `sentry-opentelemetry-otlp` module when you want OpenTelemetry to handle tracing (with spans exported via OTLP to Sentry) while Sentry handles errors, logs, and metrics. Sentry reads trace and span IDs from the OpenTelemetry `Context` so that all Sentry events are correlated with your OpenTelemetry traces.
9+
10+
Unlike the <PlatformLink to="/opentelemetry/setup/agent">Agent</PlatformLink> and <PlatformLink to="/opentelemetry/setup/agentless">Agentless</PlatformLink> integrations, this module does not use OpenTelemetry for scope storage or span creation within the Sentry SDK.
11+
12+
## Install
13+
14+
<PlatformSection notSupported={["java.spring-boot"]}>
15+
16+
```groovy {tabTitle:Gradle}
17+
implementation 'io.sentry:sentry-opentelemetry-otlp:{{@inject packages.version('sentry.java', '8.0.0') }}'
18+
```
19+
20+
```xml {tabTitle:Maven}
21+
<dependency>
22+
<groupId>io.sentry</groupId>
23+
<artifactId>sentry-opentelemetry-otlp</artifactId>
24+
<version>{{@inject packages.version('sentry.java', '8.0.0') }}</version>
25+
</dependency>
26+
```
27+
28+
This includes the OpenTelemetry SDK autoconfiguration and OTLP exporter as transitive dependencies. If you configure the OpenTelemetry SDK manually without autoconfiguration, you can exclude `opentelemetry-sdk-extension-autoconfigure` to prevent it from discovering and activating components via SPI.
29+
30+
</PlatformSection>
31+
32+
<PlatformSection supported={["java.spring-boot"]}>
33+
34+
```groovy {tabTitle:Gradle}
35+
implementation 'io.sentry:sentry-opentelemetry-otlp-spring:{{@inject packages.version('sentry.java', '8.0.0') }}'
36+
```
37+
38+
```xml {tabTitle:Maven}
39+
<dependency>
40+
<groupId>io.sentry</groupId>
41+
<artifactId>sentry-opentelemetry-otlp-spring</artifactId>
42+
<version>{{@inject packages.version('sentry.java', '8.0.0') }}</version>
43+
</dependency>
44+
```
45+
46+
This includes `sentry-opentelemetry-otlp` and the OpenTelemetry Spring Boot starter as transitive dependencies.
47+
48+
</PlatformSection>
49+
50+
## Setup
51+
52+
You need to configure both OpenTelemetry (to export spans via OTLP to Sentry) and Sentry (to read trace/span IDs from OpenTelemetry).
53+
54+
The OTLP endpoint and authentication details are shown in the code examples below. You can also find the **OTLP Traces Endpoint** and **OTLP Traces Endpoint Headers** in your Sentry project under **Settings > Projects > [Project] > Client Keys (DSN)**.
55+
56+
<PlatformSection notSupported={["java.spring-boot"]}>
57+
58+
Initialize OpenTelemetry using `AutoConfiguredOpenTelemetrySdk`, then initialize Sentry with the `OpenTelemetryOtlpEventProcessor`:
59+
60+
```java {tabTitle:Java}
61+
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
62+
import io.sentry.Sentry;
63+
import io.sentry.opentelemetry.otlp.OpenTelemetryOtlpEventProcessor;
64+
65+
// 1. Configure OpenTelemetry
66+
AutoConfiguredOpenTelemetrySdk.builder()
67+
.setResultAsGlobal()
68+
.addPropertiesSupplier(() -> {
69+
Map<String, String> properties = new HashMap<>();
70+
properties.put("otel.traces.exporter", "otlp");
71+
properties.put("otel.exporter.otlp.traces.endpoint", "___OTLP_TRACES_URL___");
72+
properties.put("otel.exporter.otlp.traces.protocol", "http/protobuf");
73+
properties.put("otel.exporter.otlp.traces.headers", "x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___");
74+
properties.put("otel.propagators", "sentry");
75+
properties.put("otel.logs.exporter", "none");
76+
properties.put("otel.metrics.exporter", "none");
77+
return properties;
78+
})
79+
.build();
80+
81+
// 2. Initialize Sentry
82+
Sentry.init(options -> {
83+
options.setDsn("___PUBLIC_DSN___");
84+
// Link Sentry events to OpenTelemetry traces
85+
options.addEventProcessor(new OpenTelemetryOtlpEventProcessor());
86+
});
87+
```
88+
89+
</PlatformSection>
90+
91+
<PlatformSection supported={["java.spring-boot"]}>
92+
93+
Add the following to your `application.properties`:
94+
95+
```properties {tabTitle:application.properties}
96+
sentry.dsn=___PUBLIC_DSN___
97+
98+
otel.propagators=sentry
99+
otel.traces.exporter=otlp
100+
otel.exporter.otlp.traces.endpoint=___OTLP_TRACES_URL___
101+
otel.exporter.otlp.traces.protocol=http/protobuf
102+
otel.exporter.otlp.traces.headers=x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___
103+
otel.logs.exporter=none
104+
otel.metrics.exporter=none
105+
```
106+
107+
Register the `OpenTelemetryOtlpEventProcessor` as a Spring bean to link Sentry events to OpenTelemetry traces:
108+
109+
```java {tabTitle:Java}
110+
import io.sentry.opentelemetry.otlp.OpenTelemetryOtlpEventProcessor;
111+
import org.springframework.context.annotation.Bean;
112+
import org.springframework.context.annotation.Configuration;
113+
114+
@Configuration
115+
public class SentryConfig {
116+
@Bean
117+
public OpenTelemetryOtlpEventProcessor openTelemetryOtlpEventProcessor() {
118+
return new OpenTelemetryOtlpEventProcessor();
119+
}
120+
}
121+
```
122+
123+
</PlatformSection>

0 commit comments

Comments
 (0)