Skip to content

Commit 8fbca7d

Browse files
adinauerlbloder
authored andcommitted
Improve Java OpenTelemetry docs (#13202)
* Improve Java OpenTelemetry docs * try to fix lint * try to fix lint2 * Apply suggestions from code review Co-authored-by: Lukas Bloder <[email protected]> * PR feedback --------- Co-authored-by: Lukas Bloder <[email protected]>
1 parent e6b9967 commit 8fbca7d

File tree

14 files changed

+226
-102
lines changed

14 files changed

+226
-102
lines changed

docs/platforms/java/common/migration/7.x-to-8.0.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ If you've been using the previous version of `sentry-opentelemetry-agent`, simpl
109109
If you've not been using the Sentry OpenTelemetry agent before, you can add `sentry-opentelemetry-agent` to your setup by downloading the latest release and using it when starting up your application
110110
- `SENTRY_PROPERTIES_FILE=sentry.properties java -javaagent:sentry-opentelemetry-agent-x.x.x.jar -jar your-application.jar`
111111
- Please use `sentry.properties` or environment variables to configure the SDK as the agent is now in charge of initializing the SDK and options coming from things like logging integrations or our Spring Boot integration will not take effect.
112-
- You may find the [docs page](https://docs.sentry.io/platforms/java/tracing/instrumentation/opentelemetry/#using-sentry-opentelemetry-agent-with-auto-initialization) useful.
112+
- You may find the <PlatformLink to="/opentelemetry/setup/agent/auto-init/">docs page</PlatformLink> useful.
113113

114114
If you want to skip auto initialization of the SDK performed by the agent, please follow the steps above and set the environment variable `SENTRY_AUTO_INIT` to `false`, then use `Sentry.init` as usual.
115115

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: OpenTelemetry Support
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Using OpenTelemetry with Sentry."
5+
sidebar_order: 160
6+
---
7+
8+
[OpenTelemetry](https://opentelemetry.io/) enhances Sentry by providing support for more frameworks and libraries that:
9+
10+
- Let you create more spans, for example around requests.
11+
- Provide `Context` propagation that also takes care of propagating Sentry `Scopes`, ensuring things like tags and other information end up on the correct event.
12+
- Extract tracing information from incoming requests and consumed messages.
13+
- Inject tracing information into outgoing requests and produced messages.
14+
15+
Please take a look at the [OpenTelemetry GitHub repository](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation) for a full list of available instrumentations.
16+
17+
In some cases there is instrumentation available by both OpenTelemetry and Sentry. In this case we automatically configure the Sentry instrumentation to not create spans and instead let OpenTelemetry take over.
18+
19+
You may use OpenTelemetry API or Sentry API to manually instrument your application. Both will end up in Sentry. If you are already using Sentry API, you can keep using it when switching over to our OpenTelemetry integration. If you already have OpenTelemetry instrumentation in place you can have the resulting spans sent to Sentry.
20+
21+
<PageGrid />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: OpenTelemetry Agent With Auto Init
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Using OpenTelemetry with sentry-opentelemetry-agent and AUTO_INIT enabled."
5+
sidebar_order: 100
6+
---
7+
8+
If you use `sentry-opentelemetry-agent`, it will look for `SENTRY_DSN` and `SENTRY_PROPERTIES_FILE` environment variables to be defined, and then initialize Sentry automatically. You'll just need to configure your `DSN` and `tracesSampleRate`.
9+
10+
<PlatformContent includePath="performance/opentelemetry-setup/agent-auto-init-recommendation/enabled" />
11+
12+
## Install
13+
14+
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent/with-auto-init" />
15+
16+
## Usage
17+
18+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init" />
19+
20+
## Debugging
21+
22+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init/debugging" />
23+
24+
## Turn Off Exporter Error Messages
25+
26+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: OpenTelemetry Agent
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Using OpenTelemetry with sentry-opentelemetry-agent."
5+
sidebar_order: 100
6+
---
7+
8+
<PlatformContent includePath="performance/opentelemetry-setup/agent-explanation" />
9+
10+
When using `sentry-opentelemetry-agent` you can choose whether the Agent should call `Sentry.init`.
11+
By default the Agent will initialize Sentry for you. If you prefer to manually initialize Sentry or have another integration perform the init you can disable this behaviour.
12+
13+
<PlatformContent includePath="performance/opentelemetry-setup/agent-auto-init-recommendation/enabled" />
14+
<PlatformContent includePath="performance/opentelemetry-setup/agent-auto-init-recommendation/disabled" />
15+
16+
<PageGrid />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: OpenTelemetry Agent Without Auto Init
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Using OpenTelemetry with sentry-opentelemetry-agent and AUTO_INIT disabled."
5+
sidebar_order: 200
6+
---
7+
8+
You may also disable automatic initialization of Sentry in `sentry-opentelemetry-agent` by setting `SENTRY_AUTO_INIT=false` as an environment variable. Doing this will mean you'll either have to use another Sentry integration that performs initialization, (for example Spring Boot), or initialize Sentry manually.
9+
10+
<PlatformContent includePath="performance/opentelemetry-setup/agent-auto-init-recommendation/disabled" />
11+
12+
## Install
13+
14+
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent/without-auto-init" />
15+
16+
## Usage
17+
18+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init" />
19+
20+
## Debugging
21+
22+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init/debugging" />
23+
24+
## Turn Off Exporter Error Messages
25+
26+
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: OpenTelemetry Agentless
3+
sdk: sentry.java.opentelemetry-agentless
4+
description: "Using OpenTelemetry with sentry-opentelemetry-agentless."
5+
sidebar_order: 200
6+
---
7+
8+
If you do not want to use our recommended <PlatformLink to="/opentelemetry/setup/agent">Java Agent</PlatformLink>, we also offer a dependency that allows you to use OpenTelemetry with Sentry.
9+
10+
## Install
11+
12+
<PlatformContent includePath="performance/opentelemetry-install/without-java-agent" />
13+
14+
## Usage
15+
16+
You'll have to configure both OpenTelemetry and Sentry to see transactions in Sentry and have errors linked to transactions created by OpenTelemetry.
17+
18+
<PlatformContent includePath="performance/opentelemetry-setup/without-java-agent" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: OpenTelemetry Setup
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Setting up Sentry with OpenTelemetry."
5+
sidebar_order: 160
6+
---
7+
8+
There are multiple ways to configure our OpenTelemetry integration. You may chose between using our Java Agent or using one of our agentless dependencies.
9+
10+
## Java Agent
11+
12+
<PlatformContent includePath="performance/opentelemetry-setup/agent-explanation" />
13+
14+
For a guide on how to set up `sentry-opentelemetry-agent`, please have a look at <PlatformLink to="/opentelemetry/setup/agent">the detailed Agent docs</PlatformLink>.
15+
16+
## Agentless
17+
18+
<PlatformContent includePath="performance/opentelemetry-setup/agentless-explanation" />
19+
20+
For a guide on how to set up agentless, please have a look at <PlatformLink to="/opentelemetry/setup/agentless">the detailed Agentless docs</PlatformLink>.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: OpenTelemetry Usage
3+
sdk: sentry.java.opentelemetry-agent
4+
description: "Using OpenTelemetry with Sentry."
5+
sidebar_order: 160
6+
---
7+
8+
## OpenTelemetry and Sentry
9+
10+
With Sentry’s OpenTelemetry SDK, an OpenTelemetry `Span` becomes a Sentry `Transaction` or `Span`. The first `Span` sent through the Sentry `SpanProcessor` is a `Transaction`, and any child `Span` gets attached to the first `Transaction` upon checking the parent `Span` context. This is true for the OpenTelemetry root `Span` and any top level `Span` in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root `Span` with a corresponding Sentry `Transaction`. The backend request will create a new Sentry `Transaction` for the OpenTelemetry `Span`. The Sentry `Transaction` and `Span` are linked as a trace for navigation and error tracking purposes.
11+
12+
### Manual Instrumentation with OpenTelemetry
13+
14+
If you have the OpenTelemetry SDK in you classpath, you can also instrument your code manually using the OpenTelemetry API as documented [in the OpenTelemetry docs](https://opentelemetry.io/docs/languages/java/api/#span).
15+
16+
A manually created span for HTTP requests needs to declare its `SpanKind` as well as the `HttpAttributes.HTTP_REQUEST_METHOD` attribute, so that `Sentry` can correctly process these:
17+
18+
```java {tabTitle:Java}
19+
Span span = tracer.spanBuilder("myspan")
20+
.setAttribute(HTTP_REQUEST_METHOD, "GET")
21+
.setSpanKind(SpanKind.SERVER)
22+
.startSpan();
23+
```
24+
```kotlin {tabTitle:Kotlin}
25+
val span = tracer.spanBuilder("myspan")
26+
.setAttribute(HTTP_REQUEST_METHOD, "GET")
27+
.setSpanKind(SpanKind.SERVER)
28+
.startSpan()
29+
```
30+
31+
### Capturing HTTP Headers
32+
33+
By default OpenTelemetry does not capture any HTTP headers. This, however, can be configured using system properties or environment variables as per OpenTelemetry's configuration documentation [here](https://opentelemetry.io/docs/zero-code/java/agent/instrumentation/http/#capturing-http-request-and-response-headers). Each variable is a comma-separated list of HTTP header names that should be captured.
34+
35+
<Alert title="✨ Note">
36+
37+
Please only enable headers you actually want to send to Sentry. Some may contain sensitive data like PII, cookies or tokens.
38+
39+
</Alert>
40+
41+
#### Client variables
42+
43+
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_REQUEST_HEADERS`
44+
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_RESPONSE_HEADERS`
45+
46+
#### Server variables
47+
48+
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_REQUEST_HEADERS`
49+
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_RESPONSE_HEADERS`
50+
51+
## Additional Configuration
52+
53+
If you need more fine grained control over Sentry, take a look at the <PlatformLink to="/configuration/">Configuration page</PlatformLink>. In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the <PlatformLink to="/configuration/filtering/#filtering-transaction-events">Filtering page</PlatformLink> helpful.

docs/platforms/java/common/tracing/instrumentation/opentelemetry.mdx

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -5,103 +5,4 @@ description: "Using OpenTelemetry with Sentry Performance."
55
sidebar_order: 20
66
---
77

8-
There are multiple ways to configure your [OpenTelemetry SDK](https://opentelemetry.io/) and send traces and spans to Sentry. They're described below.
9-
10-
<PlatformSection supported={["java.spring", "java.spring-boot"]} notSupported={["java"]}>
11-
If you're unsure whether to use the Java Agent, please have a look at [what the OpenTelemetry SDK has to say about this](https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/).
12-
</PlatformSection>
13-
14-
## Using `sentry-opentelemetry-agent` With Auto Initialization
15-
16-
If you use `sentry-opentelemetry-agent`, it will look for `SENTRY_DSN` and `SENTRY_PROPERTIES_FILE` environment variables to be defined, and then initialize Sentry automatically. You'll just need to configure your `DSN` and `tracesSampleRate`.
17-
18-
### Install
19-
20-
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent/with-auto-init" />
21-
22-
### Usage
23-
24-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init" />
25-
26-
### Debugging
27-
28-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init/debugging" />
29-
30-
### Turn Off Exporter Error Messages
31-
32-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" />
33-
34-
## Using `sentry-opentelemetry-agent` Without Auto-Initialization
35-
36-
You may also disable automatic initialization of Sentry in `sentry-opentelemetry-agent` by setting `SENTRY_AUTO_INIT=false` as an environment variable. Doing this will mean you'll either have to use another Sentry integration that performs initialization, (for example Spring Boot), or initialize Sentry manually.
37-
38-
### Install
39-
40-
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent/without-auto-init" />
41-
42-
### Usage
43-
44-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init" />
45-
46-
### Debugging
47-
48-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init/debugging" />
49-
50-
### Turn Off Exporter Error Messages
51-
52-
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" />
53-
54-
## Using OpenTelemetry Without Any Java Agent
55-
56-
If the Java Agent approach isn't for you, you can manually initialize OpenTelemetry. We have a separate dependency for this use case.
57-
58-
### Install
59-
60-
<PlatformContent includePath="performance/opentelemetry-install/without-java-agent" />
61-
62-
### Usage
63-
64-
You'll have to configure both OpenTelemetry and Sentry to see transactions in Sentry and have errors linked to transactions created by OpenTelemetry.
65-
66-
<PlatformContent includePath="performance/opentelemetry-setup/without-java-agent" />
67-
68-
## OpenTelemetry and Sentry
69-
70-
With Sentry’s OpenTelemetry SDK, an OpenTelemetry `Span` becomes a Sentry `Transaction` or `Span`. The first `Span` sent through the Sentry `SpanProcessor` is a `Transaction`, and any child `Span` gets attached to the first `Transaction` upon checking the parent `Span` context. This is true for the OpenTelemetry root `Span` and any top level `Span` in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root `Span` with a corresponding Sentry `Transaction`. The backend request will create a new Sentry `Transaction` for the OpenTelemetry `Span`. The Sentry `Transaction` and `Span` are linked as a trace for navigation and error tracking purposes.
71-
72-
### Manual Instrumentation with OpenTelemetry
73-
74-
If you have the OpenTelemetry SDK in you classpath, you can also instrument your code manually using the OpenTelemetry API as documented [in the OpenTelemetry docs](https://opentelemetry.io/docs/languages/java/api/#span).
75-
76-
A manually created span for HTTP requests needs to declare its `SpanKind` as well as the `HttpAttributes.HTTP_REQUEST_METHOD` attribute, so that `Sentry` can correctly process these:
77-
78-
```java {tabTitle:Java}
79-
Span span = tracer.spanBuilder("myspan")
80-
.setAttribute(HTTP_REQUEST_METHOD, "GET")
81-
.setSpanKind(SpanKind.SERVER)
82-
.startSpan();
83-
```
84-
```kotlin {tabTitle:Kotlin}
85-
val span = tracer.spanBuilder("myspan")
86-
.setAttribute(HTTP_REQUEST_METHOD, "GET")
87-
.setSpanKind(SpanKind.SERVER)
88-
.startSpan()
89-
```
90-
91-
### Capturing HTTP Headers
92-
93-
By default OpenTelemetry does not capture any HTTP headers. This, however, can be configured using system properties or environment variables as per OpenTelemetry's configuration documentation [here](https://opentelemetry.io/docs/zero-code/java/agent/instrumentation/http/#capturing-http-request-and-response-headers). Each variable is a comma-separated list of HTTP header names that should be captured.
94-
95-
#### Client variables
96-
97-
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_REQUEST_HEADERS`
98-
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_RESPONSE_HEADERS`
99-
100-
#### Server variables
101-
102-
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_REQUEST_HEADERS`
103-
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_RESPONSE_HEADERS`
104-
105-
## Additional Configuration
106-
107-
If you need more fine grained control over Sentry, take a look at the <PlatformLink to="/configuration/">Configuration page</PlatformLink>. In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the <PlatformLink to="/configuration/filtering/#filtering-transaction-events">Filtering page</PlatformLink> helpful.
8+
This page has moved to <PlatformLink to="/opentelemetry">a top level page</PlatformLink>.

platform-includes/performance/opentelemetry-install/without-java-agent/java.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ implementation 'io.sentry:sentry-opentelemetry-agentless:{{@inject packages.vers
1111
</dependency>
1212
```
1313

14-
Please note, if you're using Spring Boot, there's a separate `sentry-opentelemetry-agentless-spring` dependency. You can [find out more here](/platforms/java/guides/spring-boot/tracing/instrumentation/opentelemetry/).
14+
Please note, if you're using Spring Boot, there's a separate `sentry-opentelemetry-agentless-spring` dependency. You can [find out more here](/platforms/java/guides/spring-boot/opentelemetry/setup/agentless/).

0 commit comments

Comments
 (0)