diff --git a/sentry-opentelemetry/README.md b/sentry-opentelemetry/README.md index 02c5e3f1ae..2a7e629e78 100644 --- a/sentry-opentelemetry/README.md +++ b/sentry-opentelemetry/README.md @@ -1,7 +1,5 @@ # sentry-opentelemetry -*NOTE: Our OpenTelemetry modules are still experimental. Any feedback is welcome.* - ## OpenTelemetry More information on OpenTelemetry can be found on their [website](https://opentelemetry.io/) as well @@ -21,8 +19,7 @@ application. Please see the module [README](sentry-opentelemetry-agent/README.md This contains customizations to the OpenTelemetry Java Agent such as registering the `SentrySpanProcessor` and `SentryPropagator` as well as providing default properties that -enable the `sentry` propagator and disable exporters so our agent doesn't trigger lots of log -warnings due to OTLP server not being there. This can also be used without the agent. +enable the `sentry` propagator. ### `sentry-opentelemetry-bootstrap` @@ -39,4 +36,50 @@ you also need this module as a dependency. Contains `SentrySpanProcessor` and `SentryPropagator` which are used by our Java Agent but can also be used when manually instrumenting using OpenTelemetry. If you want to use OpenTelemetry without the agent but still want some configuration convenience, you should rather use the -`sentry-opentelemetry-agentcustomization` module. +`sentry-opentelemetry-agentless` module or the `sentry-opentelemetry-agentless-spring` module if you are using Spring Boot. + +### `sentry-opentelemetry-agentless` +Combines all modules and dependencies needed to use Sentry with OpenTelemetry without the agent. + +### `sentry-opentelemetry-agentless-spring` +Combines all modules and dependencies needed to use Sentry with OpenTelemetry in Spring Boot without an agent. + +## Running without an Agent +If you want to use Sentry with OpenTelemetry without an agent, you can do so by adding the `sentry-opentelemetry-agentless` (or `sentry-opentelemetry-agentless-spring`) module as dependency to your project. + +And run your application with the following JVM arguments: +``` +-Dotel.java.global-autoconfigure.enabled=true +``` +You may also want to set the following environment variables to if you do not use OpenTelemetry exporters: +`OTEL_LOGS_EXPORTER=none;OTEL_METRICS_EXPORTER=none;OTEL_TRACES_EXPORTER=none` + +Alternatively you can initialize OpenTelemetry programmatically like this: + +```java +// Initialize OpenTelemetry by using the AutoConfiguredOpenTelemetrySdk which automatically +// registers the `SentrySpanProcessor` and `SentryPropagator` and others. +// Also, you need to disable the OTEL exporters if you do not use them. +AutoConfiguredOpenTelemetrySdk.builder() + .setResultAsGlobal() + .addPropertiesSupplier(() -> { +final Map properties = new HashMap<>(); + properties.put("otel.logs.exporter", "none"); + properties.put("otel.metrics.exporter", "none"); + properties.put("otel.traces.exporter", "none"); + return properties; + }) + .build(); +``` + +And then initialize Sentry as usual: + +```java +// Initialize Sentry +Sentry.init( + options -> { + options.setDsn("..."); + ... + } +) +``` diff --git a/sentry-opentelemetry/sentry-opentelemetry-agent/README.md b/sentry-opentelemetry/sentry-opentelemetry-agent/README.md index 92ddb89a1c..e6feb1f3ae 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agent/README.md +++ b/sentry-opentelemetry/sentry-opentelemetry-agent/README.md @@ -1,7 +1,5 @@ # sentry-opentelemetry-agent -*NOTE: Our OpenTelemetry modules are still experimental. Any feedback is welcome.* - ## How to use it Download the latest `sentry-opentelemetry-agent.jar` and use it when launching your Java @@ -21,30 +19,24 @@ For more details on configuring Sentry via `sentry.properties` please see the [docs page](https://docs.sentry.io/platforms/java/configuration/). As an alternative to the `SENTRY_PROPERTIES_FILE` environment variable you can provide individual -settings as environment variables (e.g. `SENTRY_DSN=...`) or you may initialize `Sentry` inside -your target application. If you do so, please make sure to set the `instrumenter` to `otel`, e.g. -like this: +settings as environment variables (e.g. `SENTRY_DSN=...`). + +## Controlling auto initialization of Sentry + +By default, if you pass either `SENTRY_DSN` or `SENTRY_PROPERTIES_FILE` as environment variable, +Sentry will automatically be initialized by this agent. To disable this behaviour, you can set +`SENTRY_AUTO_INIT=false` as environment variable. You will then have to use a Sentry SDK that takes care of initialization or initialize Sentry manually inside +the target application: ``` Sentry.init( options -> { options.setDsn("..."); ... - options.setInstrumenter(Instrumenter.OTEL); } ) ``` -Using the `otel` instrumenter will ensure `Sentry` instrumentation will be done via OpenTelemetry -and integrations as well as direct interactions with transactions and spans have no effect. - -## Controlling auto initialization of Sentry - -By default if you pass either `SENTRY_DSN` or `SENTRY_PROPERTIES_FILE` as environment variable, -Sentry will automatically be initialized by this agent. To disable this behaviour, you can set -`SENTRY_AUTO_INIT=false` as environment variable. You will then have to initialize Sentry inside -the target application. - ## Debugging To enable debug logging for Sentry, please provide `SENTRY_DEBUG=true` as environment variable or @@ -62,6 +54,7 @@ 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 +ERROR io.opentelemetry.exporter.internal.http.HttpExporter - Failed to export logs. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4318 ``` ### Traces @@ -73,3 +66,8 @@ see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/ To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none` see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters) + +### Logs + +To turn off log exporting, set `OTEL_LOGS_EXPORTER=none` +see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters). diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentless-spring/README.md b/sentry-opentelemetry/sentry-opentelemetry-agentless-spring/README.md index b808195c90..9e4bd992fb 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agentless-spring/README.md +++ b/sentry-opentelemetry/sentry-opentelemetry-agentless-spring/README.md @@ -1,54 +1,20 @@ # sentry-opentelemetry-agentless-spring -*NOTE: Our OpenTelemetry modules are still experimental. Any feedback is welcome.* +This module allows the use of Sentry with OpenTelemetry in SpringBoot without an agent by using the OpenTelemetry Spring Boot Starter. +For guidance on when to use this module instead of the agent, please have a look at the [OpenTelemetry Spring Boot Starter documentation](https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/). ## How to use it -Add the latest `sentry-opentelemetry-agentless-spring` module as a dependency and add a `sentry.properties` -configuration file to your project that could look like this: +Add the latest `sentry-opentelemetry-agentless-spring` module as a dependency to your Sentry enabled [SpringBoot](https://docs.sentry.io/platforms/java/guides/spring-boot/) application and add the following to your `application.properties`: ```properties -# NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard -dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -traces-sample-rate=1.0 +# OTEL configuration +otel.propagators=tracecontext,baggage,sentry +otel.logs.exporter=none +otel.metrics.exporter=none +otel.traces.exporter=none ``` -For more details on configuring Sentry via `sentry.properties` please see the -[docs page](https://docs.sentry.io/platforms/java/configuration/). +This module will automatically configure OpenTelemetry and Sentry for you. -As an alternative to the `SENTRY_PROPERTIES_FILE` environment variable you can provide individual -settings as environment variables (e.g. `SENTRY_DSN=...`) or you may initialize `Sentry` inside -your target application. If you do so, please make sure to apply OpenTelemetry specific options, e.g. -like this: - -``` -Sentry.init( - options -> { - options.setDsn("..."); - ... - OpenTelemetryUtil.applyOpenTelemetryOptions(options, false); - } -) -``` - -## Getting rid of exporter error messages - -In case you are using this module 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. - -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` -see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters) - -### Metrics - -To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none` -see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters) +With the dependency and configuration in place, just run your SpringBoot application as usual. diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentless/README.md b/sentry-opentelemetry/sentry-opentelemetry-agentless/README.md index 9ce3319bae..8663a6caa9 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agentless/README.md +++ b/sentry-opentelemetry/sentry-opentelemetry-agentless/README.md @@ -1,7 +1,5 @@ # sentry-opentelemetry-agentless -*NOTE: Our OpenTelemetry modules are still experimental. Any feedback is welcome.* - ## How to use it Add the latest `sentry-opentelemetry-agentless` module as a dependency and add a `sentry.properties` @@ -17,38 +15,42 @@ For more details on configuring Sentry via `sentry.properties` please see the [docs page](https://docs.sentry.io/platforms/java/configuration/). As an alternative to the `SENTRY_PROPERTIES_FILE` environment variable you can provide individual -settings as environment variables (e.g. `SENTRY_DSN=...`) or you may initialize `Sentry` inside -your target application. If you do so, please make sure to apply OpenTelemetry specific options, e.g. -like this: +settings as environment variables (e.g. `SENTRY_DSN=...`). +Run your application with the following JVM arguments: ``` -Sentry.init( - options -> { - options.setDsn("..."); - ... - OpenTelemetryUtil.applyOpenTelemetryOptions(options, false); - } -) +-Dotel.java.global-autoconfigure.enabled=true ``` -## Getting rid of exporter error messages - -In case you are using this module 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. - -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 +You may also want to set the following environment variables to if you do not use OpenTelemetry exporters: +`OTEL_LOGS_EXPORTER=none;OTEL_METRICS_EXPORTER=none;OTEL_TRACES_EXPORTER=none` + +Alternatively you can initialize OpenTelemetry programmatically like this: + +```java +// Initialize OpenTelemetry by using the AutoConfiguredOpenTelemetrySdk which automatically +// registers the `SentrySpanProcessor` and `SentryPropagator` and others. +// Also, you need to disable the OTEL exporters if you do not use them. +AutoConfiguredOpenTelemetrySdk.builder() + .setResultAsGlobal() + .addPropertiesSupplier(() -> { +final Map properties = new HashMap<>(); + properties.put("otel.logs.exporter", "none"); + properties.put("otel.metrics.exporter", "none"); + properties.put("otel.traces.exporter", "none"); + return properties; + }) + .build(); ``` -### Traces +If you're not using `sentry.properties` or environment variables you can then initialize Sentry programmatically as usual: -To turn off exporting of traces you can set `OTEL_TRACES_EXPORTER=none` -see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters) - -### Metrics - -To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none` -see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters) +```java +// Initialize Sentry +Sentry.init( + options -> { + options.setDsn("..."); + ... + } +) +``` diff --git a/sentry-samples/sentry-samples-console-opentelemetry-noagent/README.md b/sentry-samples/sentry-samples-console-opentelemetry-noagent/README.md index 9e4b9e3e8a..bc918c5824 100644 --- a/sentry-samples/sentry-samples-console-opentelemetry-noagent/README.md +++ b/sentry-samples/sentry-samples-console-opentelemetry-noagent/README.md @@ -1,6 +1,6 @@ # Sentry Sample Console -Sample application showing how to use Sentry manually without any framework integration. +Sample application showing how to use Sentry with OpenTelemetry manually without any framework integration and without java agent. ## How to run? diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/README.md b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/README.md index 58b94ba899..4a5f2a7739 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/README.md +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/README.md @@ -1,6 +1,6 @@ # Sentry Sample Spring Boot 3.0+ -Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) from version `3.0` onwards. +Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) from version `3.0` onwards integrated with the [OpenTelemetry Spring Boot Starter](https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/) without an agent. ## How to run? diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties index 1c21d32049..402538a83a 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties @@ -31,4 +31,8 @@ spring.graphql.graphiql.enabled=true spring.graphql.websocket.path=/graphql spring.quartz.job-store-type=memory +# OTEL configuration otel.propagators=tracecontext,baggage,sentry +otel.logs.exporter=none +otel.metrics.exporter=none +otel.traces.exporter=none diff --git a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/README.md b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/README.md index bd8d0af480..e8068dab25 100644 --- a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/README.md +++ b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/README.md @@ -1,6 +1,6 @@ # Sentry Sample Spring Boot -Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot). +Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) integrated with the [OpenTelemetry Spring Boot Starter](https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/). ## How to run? diff --git a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties index c7402eacc2..43d84aeb41 100644 --- a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties @@ -23,3 +23,9 @@ spring.datasource.username=sa spring.datasource.password= spring.graphql.graphiql.enabled=true spring.graphql.websocket.path=/graphql + +# OTEL configuration +otel.propagators=tracecontext,baggage,sentry +otel.logs.exporter=none +otel.metrics.exporter=none +otel.traces.exporter=none