-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add docs for OpenTelemetry Java #5968
Changes from 1 commit
6e3c15c
cda847e
9825b52
8cf6bb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You can download the latest version of the `sentry-opentelemetry-agent-{{ packages.version('sentry.java.opentelemetry-agent') }}.zip` from [GitHub](https://github.com/getsentry/sentry-java/releases/) which contains the `JAR` file used in this docs page. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
In addition to OpenTelemetry dependencies and your typical Sentry dependencies, you will need to add `sentry-opentelemetry-core` as a dependency: | ||
|
||
```groovy {tabTitle:Gradle} | ||
implementation 'io.sentry:sentry-opentelemetry-core::{{ packages.version('sentry.java.opentelemetry-agent', '6.9.2') }}' | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
In case you are using `sentry-opentelemetry-agent` without needing to use any OpenTelemetry exporters you can add | ||
the following environment variables to turn off exporters and stop seeing error messages about | ||
servers not being reachable in the logs. | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example log message: | ||
``` | ||
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export spans. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317 | ||
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export metrics. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317 | ||
``` | ||
|
||
#### Traces | ||
|
||
To turn off exporting of traces you can set `OTEL_TRACES_EXPORTER=none` as environment variable | ||
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters). | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Metrics | ||
|
||
To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none` as environment variable | ||
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters). | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To enable debug logging for Sentry, please provide `SENTRY_DEBUG=true` as environment variable or | ||
add `debug=true` to your `sentry.properties`. | ||
|
||
To also show debug output for OpenTelemetry please add `-Dotel.javaagent.debug=true` to the `java` command. | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This `java` command shows how to run your application using `sentry-opentelemetry-agent`: | ||
|
||
```bash | ||
SENTRY_PROPERTIES_FILE=sentry.properties java -javaagent:sentry-opentelemetry-agent-{{ packages.version('sentry.java.opentelemetry-agent') }}.jar -jar your-application.jar | ||
``` | ||
|
||
Here's the `sentry.properties` file that goes with it: | ||
|
||
```properties {filename:sentry.properties} | ||
dsn=___DSN___ | ||
traces-sample-rate=1.0 | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To enable debug logging for Sentry, please provide `SENTRY_DEBUG=true` as environment variable or | ||
add `debug=true` to your `sentry.properties`. | ||
|
||
To also show debug output for OpenTelemetry please add `-Dotel.javaagent.debug=true` to the `java` command. | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To enable debug logging for Sentry, please provide `SENTRY_DEBUG=true` as environment variable or | ||
add `sentry.debug=true` to your `application.properties`. | ||
|
||
To also show debug output for OpenTelemetry please add `-Dotel.javaagent.debug=true` to the command. | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
If you are not using the auto initialization provided by `sentry-opentelemetry-agent` (`SENTRY_AUTO_INIT=false`) you have to set the `instrumenter` option to `otel`. This disables all Sentry instrumentation and relies on the chosen OpenTelemetry tracers for creating spans. You also have to add the `OpenTelemetryLinkErrorEventProcessor` to ensure errors are properly linked to transactions that were created by the OpenTelemetry integration: | ||
|
||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```java {tabTitle: Java} | ||
import io.sentry.Instrumenter; | ||
import io.sentry.Sentry; | ||
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor; | ||
|
||
Sentry.init(options -> { | ||
options.setDsn("___PUBLIC_DSN___"); | ||
options.setTracesSampleRate(1.0); | ||
options.setInstrumenter(Instrumenter.OTEL); | ||
options.addEventProcessor(new OpenTelemetryLinkErrorEventProcessor()); | ||
}); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
If you are not using the auto initialization provided by `sentry-opentelemetry-agent` (`SENTRY_AUTO_INIT=false`) you have to | ||
set the `instrumenter` option to `otel`. This disables all Sentry instrumentation and relies on the chosen OpenTelemetry tracers for creating spans. | ||
|
||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```properties {filename:application.properties} | ||
sentry.dsn=___DSN___ | ||
sentry.traces-sample-rate=1.0 | ||
# enable this to see more logs | ||
sentry.debug=false | ||
# set the instrumenter to use OpenTelemetry instead of Sentry | ||
sentry.instrumenter=otel | ||
``` | ||
|
||
You also have to manually provide the `OpenTelemetryLinkErrorEventProcessor` bean to ensure errors are properly linked to transactions that were created by the OpenTelemetry integration: | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```java {filename:SentryDemoApplication.java} | ||
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor; | ||
|
||
@SpringBootApplication | ||
public class SentryDemoApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(SentryDemoApplication.class, args); | ||
} | ||
|
||
... | ||
|
||
@Bean | ||
OpenTelemetryLinkErrorEventProcessor otelLinkEventProcessor() { | ||
return new OpenTelemetryLinkErrorEventProcessor(); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#### Initializing OpenTelemetry | ||
|
||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to add an introductory sentence before the code snippet to give the user more context and an easier way to scan the page. |
||
```Java | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.propagation.ContextPropagators; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.trace.SdkTracerProvider; | ||
|
||
import io.sentry.opentelemetry.SentryPropagator; | ||
import io.sentry.opentelemetry.SentrySpanProcessor; | ||
|
||
|
||
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() | ||
.addSpanProcessor(new SentrySpanProcessor()) | ||
.build(); | ||
|
||
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() | ||
.setTracerProvider(sdkTracerProvider) | ||
.setPropagators(ContextPropagators.create(new SentryPropagator())) | ||
.buildAndRegisterGlobal(); | ||
``` | ||
|
||
#### Initializing Sentry | ||
|
||
You have to set the `instrumenter` option to `otel`. This disables all Sentry instrumentation and relies on the chosen OpenTelemetry tracers for creating spans. You also have to add the `OpenTelemetryLinkErrorEventProcessor` to ensure errors are properly linked to transactions that were created by the OpenTelemetry integration: | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```java {tabTitle: Java} | ||
import io.sentry.Instrumenter; | ||
import io.sentry.Sentry; | ||
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor; | ||
|
||
Sentry.init(options -> { | ||
options.setDsn("___PUBLIC_DSN___"); | ||
options.setTracesSampleRate(1.0); | ||
options.setInstrumenter(Instrumenter.OTEL); | ||
options.addEventProcessor(new OpenTelemetryLinkErrorEventProcessor()); | ||
}); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#### Initializing OpenTelemetry | ||
|
||
```Java | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.propagation.ContextPropagators; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.trace.SdkTracerProvider; | ||
|
||
import io.sentry.opentelemetry.SentryPropagator; | ||
import io.sentry.opentelemetry.SentrySpanProcessor; | ||
|
||
|
||
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() | ||
.addSpanProcessor(new SentrySpanProcessor()) | ||
.build(); | ||
|
||
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() | ||
.setTracerProvider(sdkTracerProvider) | ||
.setPropagators(ContextPropagators.create(new SentryPropagator())) | ||
.buildAndRegisterGlobal(); | ||
``` | ||
|
||
#### Initializing Sentry | ||
|
||
You have to set the `instrumenter` option to `otel`. This disables all Sentry instrumentation and relies on the chosen OpenTelemetry tracers for creating spans. | ||
|
||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```properties {filename:application.properties} | ||
sentry.dsn=___DSN___ | ||
sentry.traces-sample-rate=1.0 | ||
# enable this to see more logs | ||
sentry.debug=false | ||
# set the instrumenter to use OpenTelemetry instead of Sentry | ||
sentry.instrumenter=otel | ||
``` | ||
|
||
You also have to manually provide the `OpenTelemetryLinkErrorEventProcessor` bean to ensure errors are properly linked to transactions that were created by the OpenTelemetry integration: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to keep this as is for now as there doesn't seem to be an easy way to detect whether the |
||
|
||
```java {filename:SentryDemoApplication.java} | ||
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor; | ||
|
||
@SpringBootApplication | ||
public class SentryDemoApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(SentryDemoApplication.class, args); | ||
} | ||
|
||
... | ||
|
||
@Bean | ||
OpenTelemetryLinkErrorEventProcessor otelLinkEventProcessor() { | ||
return new OpenTelemetryLinkErrorEventProcessor(); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||
--- | ||||||
title: OpenTelemetry Support | ||||||
sidebar_order: 20 | ||||||
description: "Using OpenTelemetry with Sentry Performance." | ||||||
--- | ||||||
|
||||||
<Include name="alpha-note.mdx" /> | ||||||
|
||||||
You can configure your [OpenTelemetry SDK](https://opentelemetry.io/) to send traces and spans to Sentry. | ||||||
|
||||||
There are multiple ways of combining OpenTelemetry and Sentry. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## Using `sentry-opentelemetry-agent` with auto initialization | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
By default, if you use `sentry-opentelemetry-agent`, it will look for `SENTRY_DSN` and `SENTRY_PROPERTIES_FILE` environment variables to be defined. If either of those is set, `sentry-opentelemetry-agent` will initialize Sentry automatically and you don't have to perform any setup work besides configuring your `DSN` and `tracesSampleRate`. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
### Install | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent" /> | ||||||
|
||||||
### Usage | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init" /> | ||||||
|
||||||
### Debugging | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/with-auto-init/debugging" /> | ||||||
|
||||||
### Getting rid of exporter error messages | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" /> | ||||||
|
||||||
## Using `sentry-opentelemetry-agent` without auto initialization | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
You may also disable automatic initialization of Sentry in `sentry-opentelemetry-agent` by setting `SENTRY_AUTO_INIT=false` as environment variable. This means you will either have to use another Sentry integration that performs initialization, for example Spring Boot, or initialize Sentry manually. | ||||||
|
||||||
### Install | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-install/with-java-agent" /> | ||||||
|
||||||
### Usage | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init" /> | ||||||
|
||||||
### Debugging | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/without-auto-init/debugging" /> | ||||||
|
||||||
### Getting rid of exporter error messages | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing with
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/with-java-agent/exporter-messages" /> | ||||||
|
||||||
## Using OpenTelemetry without any Java Agent | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
When manually initializing OpenTelemetry you have to register a few Sentry classes. | ||||||
|
||||||
### Install | ||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-install/without-java-agent" /> | ||||||
|
||||||
### Usage | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to add an introductory sentence to introduce the user to the section and make the page easier to read. Please avoid stacking headings without text in-between. |
||||||
|
||||||
<PlatformContent includePath="performance/opentelemetry-setup/without-java-agent" /> |
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.
Just want to double check that we're pointing to the right page. I don't see a .zip file named "sentry.java.opentelemetry-agent", but it may be part of one of the other files. Just wanted to make sure.
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.
It's only visible if you hit "Show all 33 assets".