Skip to content

Commit

Permalink
Add SENTRY_AUTO_INIT env var to control OpenTelemetry Agent init
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Dec 2, 2022
1 parent ecf9680 commit b0526ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions sentry-opentelemetry/sentry-opentelemetry-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ Sentry.init(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public final class SentryAutoConfigurationCustomizerProvider

@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
final @Nullable String sentryPropertiesFile = System.getenv("SENTRY_PROPERTIES_FILE");
final @Nullable String sentryDsn = System.getenv("SENTRY_DSN");

if (sentryPropertiesFile != null || sentryDsn != null) {
if (isSentryAutoInitEnabled()) {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
Expand All @@ -43,6 +40,19 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
.addPropertiesSupplier(this::getDefaultProperties);
}

private boolean isSentryAutoInitEnabled() {
final @Nullable String sentryAutoInit = System.getenv("SENTRY_AUTO_INIT");

if (sentryAutoInit != null) {
return "true".equalsIgnoreCase(sentryAutoInit);
} else {
final @Nullable String sentryPropertiesFile = System.getenv("SENTRY_PROPERTIES_FILE");
final @Nullable String sentryDsn = System.getenv("SENTRY_DSN");

return sentryPropertiesFile != null || sentryDsn != null;
}
}

private @Nullable SdkVersion createSdkVersion(final @NotNull SentryOptions sentryOptions) {
SdkVersion sdkVersion = sentryOptions.getSdkVersion();

Expand Down

0 comments on commit b0526ec

Please sign in to comment.