Skip to content
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 constructor to JUL SentryHandler for disabling external config #4208

Merged
merged 3 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added `enableTraceIdGeneration` to the AndroidOptions. This allows Hybrid SDKs to "freeze" and control the trace and connect errors on different layers of the application ([4188](https://github.com/getsentry/sentry-java/pull/4188))
- Move to a single NetworkCallback listener to reduce number of IPC calls on Android ([#4164](https://github.com/getsentry/sentry-java/pull/4164))
- Add GraphQL Apollo Kotlin 4 integration ([#4166](https://github.com/getsentry/sentry-java/pull/4166))
- Add constructor to JUL `SentryHandler` for disabling external config ([#4208](https://github.com/getsentry/sentry-java/pull/4208))

### Fixes

Expand Down
1 change: 1 addition & 0 deletions sentry-jul/api/sentry-jul.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class io/sentry/jul/SentryHandler : java/util/logging/Handler {
public static final field THREAD_ID Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lio/sentry/SentryOptions;)V
public fun <init> (Lio/sentry/SentryOptions;Z)V
public fun close ()V
public fun flush ()V
public fun getMinimumBreadcrumbLevel ()Ljava/util/logging/Level;
Expand Down
23 changes: 19 additions & 4 deletions sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SentryHandler extends Handler {

/** Creates an instance of SentryHandler. */
public SentryHandler() {
this(new SentryOptions(), true);
this(new SentryOptions());
}

/**
Expand All @@ -60,17 +60,32 @@ public SentryHandler() {
* @param options the SentryOptions
*/
public SentryHandler(final @NotNull SentryOptions options) {
this(options, true);
this(options, true, true);
}

/**
* Creates an instance of SentryHandler.
*
* @param options the SentryOptions
* @param enableExternalConfiguration whether external options like sentry.properties and ENV vars
* should be parsed
*/
public SentryHandler(
final @NotNull SentryOptions options, final boolean enableExternalConfiguration) {
this(options, true, enableExternalConfiguration);
}

/** Creates an instance of SentryHandler. */
@TestOnly
SentryHandler(final @NotNull SentryOptions options, final boolean configureFromLogManager) {
SentryHandler(
final @NotNull SentryOptions options,
final boolean configureFromLogManager,
final boolean enableExternalConfiguration) {
setFilter(new DropSentryFilter());
if (configureFromLogManager) {
retrieveProperties();
}
options.setEnableExternalConfiguration(true);
options.setEnableExternalConfiguration(enableExternalConfiguration);
options.setInitPriority(InitPriority.LOWEST);
options.setSdkVersion(createSdkVersion(options));
Sentry.init(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SentryHandlerTest {
options.setTransportFactory { _, _ -> transport }
contextTags?.forEach { options.addContextTag(it) }
logger = Logger.getLogger("jul.SentryHandlerTest")
handler = SentryHandler(options, configureWithLogManager)
handler = SentryHandler(options, configureWithLogManager, true)
handler.setMinimumBreadcrumbLevel(minimumBreadcrumbLevel)
handler.setMinimumEventLevel(minimumEventLevel)
handler.level = Level.ALL
Expand Down
Loading