Skip to content
Merged
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- Add init priority settings ([#3674](https://github.com/getsentry/sentry-java/pull/3674))
- You may now set `forceInit=true` (`force-init` for `.properties` files) to ensure a call to Sentry.init / SentryAndroid.init takes effect
- Add force init option to Android Manifest
- Add force init option to Android Manifest ([#3675](https://github.com/getsentry/sentry-java/pull/3675))
- Use `<meta-data android:name="io.sentry.force-init" android:value="true" />` to ensure Sentry Android auto init is not easily overwritten

### Fixes
Expand Down
10 changes: 5 additions & 5 deletions sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.jakewharton.nopen.annotation.Open;
import io.sentry.Breadcrumb;
import io.sentry.Hint;
import io.sentry.InitPriority;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryEvent;
Expand Down Expand Up @@ -69,11 +70,10 @@ public SentryHandler(final @NotNull SentryOptions options) {
if (configureFromLogManager) {
retrieveProperties();
}
if (!Sentry.isEnabled()) {
options.setEnableExternalConfiguration(true);
options.setSdkVersion(createSdkVersion(options));
Sentry.init(options);
}
options.setEnableExternalConfiguration(true);
options.setInitPriority(InitPriority.LOWEST);
options.setSdkVersion(createSdkVersion(options));
Sentry.init(options);
addPackageAndIntegrationInfo();
}

Expand Down
42 changes: 21 additions & 21 deletions sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.Hint;
import io.sentry.IScopes;
import io.sentry.ITransportFactory;
import io.sentry.InitPriority;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryEvent;
Expand Down Expand Up @@ -116,28 +117,27 @@ public SentryAppender(

@Override
public void start() {
if (!Sentry.isEnabled()) {
try {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
options.setDsn(dsn);
if (debug != null) {
options.setDebug(debug);
try {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
options.setInitPriority(InitPriority.LOWEST);
options.setDsn(dsn);
if (debug != null) {
options.setDebug(debug);
}
options.setSentryClientName(
BuildConfig.SENTRY_LOG4J2_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
if (contextTags != null) {
for (final String contextTag : contextTags) {
options.addContextTag(contextTag);
}
options.setSentryClientName(
BuildConfig.SENTRY_LOG4J2_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
if (contextTags != null) {
for (final String contextTag : contextTags) {
options.addContextTag(contextTag);
}
}
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
});
} catch (IllegalArgumentException e) {
LOGGER.warn("Failed to init Sentry during appender initialization: " + e.getMessage());
}
}
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
});
} catch (IllegalArgumentException e) {
LOGGER.warn("Failed to init Sentry during appender initialization: " + e.getMessage());
}
addPackageAndIntegrationInfo();
super.start();
Expand Down
33 changes: 16 additions & 17 deletions sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.sentry.DateUtils;
import io.sentry.Hint;
import io.sentry.ITransportFactory;
import io.sentry.InitPriority;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryEvent;
Expand Down Expand Up @@ -49,24 +50,22 @@ public class SentryAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {

@Override
public void start() {
// NOTE: logback.xml properties will only be applied if the SDK has not yet been initialized
if (!Sentry.isEnabled()) {
if (options.getDsn() == null || !options.getDsn().endsWith("_IS_UNDEFINED")) {
options.setEnableExternalConfiguration(true);
options.setSentryClientName(
BuildConfig.SENTRY_LOGBACK_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
try {
Sentry.init(options);
} catch (IllegalArgumentException e) {
addWarn("Failed to init Sentry during appender initialization: " + e.getMessage());
}
} else {
options
.getLogger()
.log(SentryLevel.WARNING, "DSN is null. SentryAppender is not being initialized");
if (options.getDsn() == null || !options.getDsn().endsWith("_IS_UNDEFINED")) {
options.setEnableExternalConfiguration(true);
options.setInitPriority(InitPriority.LOWEST);
options.setSentryClientName(
BuildConfig.SENTRY_LOGBACK_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
try {
Sentry.init(options);
} catch (IllegalArgumentException e) {
addWarn("Failed to init Sentry during appender initialization: " + e.getMessage());
}
} else if (!Sentry.isEnabled()) {
options
.getLogger()
.log(SentryLevel.WARNING, "DSN is null. SentryAppender is not being initialized");
}
addPackageAndIntegrationInfo();
super.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.sentry.InitPriority;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryOptions;
Expand Down Expand Up @@ -50,6 +51,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
options.setInitPriority(InitPriority.HIGH);
options.setIgnoredSpanOrigins(SpanUtils.ignoredSpanOriginsForOpenTelemetry());
options.setSpanFactory(spanFactory);
final @Nullable SdkVersion sdkVersion = createSdkVersion(options, versionInfoHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.sentry.EventProcessor;
import io.sentry.IScopes;
import io.sentry.ITransportFactory;
import io.sentry.InitPriority;
import io.sentry.Integration;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
Expand Down Expand Up @@ -133,6 +134,7 @@ static class HubConfiguration {
options.setSentryClientName(
BuildConfig.SENTRY_SPRING_BOOT_JAKARTA_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
options.setInitPriority(InitPriority.LOW);
addPackageAndIntegrationInfo();
// Spring Boot sets ignored exceptions in runtime using reflection - where the generic
// information is lost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.sentry.EventProcessor;
import io.sentry.IScopes;
import io.sentry.ITransportFactory;
import io.sentry.InitPriority;
import io.sentry.Integration;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
Expand Down Expand Up @@ -131,6 +132,7 @@ static class HubConfiguration {
options.setSentryClientName(
BuildConfig.SENTRY_SPRING_BOOT_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
options.setSdkVersion(createSdkVersion(options));
options.setInitPriority(InitPriority.LOW);
addPackageAndIntegrationInfo();
// Spring Boot sets ignored exceptions in runtime using reflection - where the generic
// information is lost
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.spring.jakarta;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.InitPriority;
import io.sentry.ScopesAdapter;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryOptions;
Expand Down Expand Up @@ -46,6 +47,7 @@ private void registerSentryOptions(
builder.addPropertyValue("enableExternalConfiguration", true);
builder.addPropertyValue("sentryClientName", BuildConfig.SENTRY_SPRING_JAKARTA_SDK_NAME);
builder.addPropertyValue("sdkVersion", createSdkVersion());
builder.addPropertyValue("initPriority", InitPriority.LOW);
addPackageAndIntegrationInfo();
if (annotationAttributes.containsKey("sendDefaultPii")) {
builder.addPropertyValue("sendDefaultPii", annotationAttributes.getBoolean("sendDefaultPii"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.spring;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.InitPriority;
import io.sentry.ScopesAdapter;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryOptions;
Expand Down Expand Up @@ -46,6 +47,7 @@ private void registerSentryOptions(
builder.addPropertyValue("enableExternalConfiguration", true);
builder.addPropertyValue("sentryClientName", BuildConfig.SENTRY_SPRING_SDK_NAME);
builder.addPropertyValue("sdkVersion", createSdkVersion());
builder.addPropertyValue("initPriority", InitPriority.LOW);
addPackageAndIntegrationInfo();
if (annotationAttributes.containsKey("sendDefaultPii")) {
builder.addPropertyValue("sendDefaultPii", annotationAttributes.getBoolean("sendDefaultPii"));
Expand Down
14 changes: 7 additions & 7 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@ private static synchronized void init(
"You are running Android. Please, use SentryAndroid.init. "
+ options.getClass().getName());
}
if (isEnabled()) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Sentry has been already initialized. Previous configuration will be overwritten.");
}

if (!preInitConfigurations(options)) {
return;
Expand All @@ -288,6 +281,13 @@ private static synchronized void init(
Sentry.globalHubMode = globalHubMode;
final boolean shouldInit = InitUtil.shouldInit(globalScope.getOptions(), options, isEnabled());
if (shouldInit) {
if (isEnabled()) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Sentry has been already initialized. Previous configuration will be overwritten.");
}
globalScope.replaceOptions(options);

final IScopes scopes = getCurrentScopes();
Expand Down