Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bd0c3b4
Check for mixed SDK versions
adinauer Mar 18, 2025
f50173b
Format code
getsentry-bot Mar 20, 2025
a8875cf
format + api
adinauer Mar 20, 2025
c0eea6a
Init noops if mixed versions detected
adinauer Mar 20, 2025
5c09766
Add BuildConfig
adinauer Mar 20, 2025
735ff28
config entries for agentless module sdk names
adinauer Mar 20, 2025
fe20321
Add MANIFEST.MF for JARs
adinauer Mar 20, 2025
901830d
Throw on startup; use manifests for backend; reuse code for otel
adinauer Mar 21, 2025
65a7a6f
Format code
getsentry-bot Mar 21, 2025
62cb98f
Merge branch 'main' into feat/crash-on-startup-with-mixed-versions
adinauer Mar 24, 2025
954610d
Format code
getsentry-bot Mar 24, 2025
8144647
changelog
adinauer Mar 24, 2025
7d1942e
api
adinauer Mar 24, 2025
f062c3e
Merge branch 'main' into feat/manifest-for-jars
adinauer Mar 24, 2025
e72dff6
changelog
adinauer Mar 24, 2025
72c554b
Merge branch 'main' into feat/detect-mixed-sdk-versions
adinauer Mar 24, 2025
60e4cd3
Merge branch 'feat/detect-mixed-sdk-versions' into feat/noop-on-mixed…
adinauer Mar 24, 2025
b1ae3b4
Merge branch 'feat/noop-on-mixed-versions-android' into feat/manifest…
adinauer Mar 24, 2025
e13f518
Merge branch 'feat/manifest-for-jars' into feat/crash-on-startup-with…
adinauer Mar 24, 2025
c3d50ab
Remove duplicate addPackage calls
adinauer Mar 25, 2025
8185388
remove test assertion for package
adinauer Mar 25, 2025
f8ba72d
Introduce fatal SDK logger
adinauer Mar 26, 2025
04db954
Format code
getsentry-bot Mar 26, 2025
dac2bad
Merge branch 'main' into feat/fatal-logger
adinauer Mar 27, 2025
1549087
changelog
adinauer Mar 27, 2025
5e48870
api
adinauer Mar 27, 2025
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- Increase http timeouts from 5s to 30s to have a better chance of events being delivered without retry ([#4276](https://github.com/getsentry/sentry-java/pull/4276))
- Add `MANIFEST.MF` to Sentry JARs ([#4272](https://github.com/getsentry/sentry-java/pull/4272))
- Retain baggage sample rate/rand values as doubles ([#4279](https://github.com/getsentry/sentry-java/pull/4279))
- Introduce fatal SDK logger ([#4288](https://github.com/getsentry/sentry-java/pull/4288))
- We use this to print out messages when there is a problem that prevents the SDK from working correctly.
- One example for this is when the SDK has been configured with mixed dependency versions where we print out details, which module and version are affected.

### Fixes

Expand Down
9 changes: 9 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public final class io/sentry/android/core/AndroidDateUtils {
public static fun getCurrentSentryDateTime ()Lio/sentry/SentryDate;
}

public final class io/sentry/android/core/AndroidFatalLogger : io/sentry/ILogger {
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
public fun isEnabled (Lio/sentry/SentryLevel;)Z
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Throwable;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V
}

public final class io/sentry/android/core/AndroidLogger : io/sentry/ILogger {
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.sentry.android.core;

import android.util.Log;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public final class AndroidFatalLogger implements ILogger {

private final @NotNull String tag;

public AndroidFatalLogger() {
this("Sentry");
}

public AndroidFatalLogger(final @NotNull String tag) {
this.tag = tag;
}

@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Object... args) {
if (args == null || args.length == 0) {
Log.println(toLogcatLevel(level), tag, message);
} else {
Log.println(toLogcatLevel(level), tag, String.format(message, args));
}
}

@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(
final @NotNull SentryLevel level,
final @Nullable Throwable throwable,
final @NotNull String message,
final @Nullable Object... args) {
if (args == null || args.length == 0) {
log(level, message, throwable);
} else {
log(level, String.format(message, args), throwable);
}
}

@Override
public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Throwable throwable) {
Log.wtf(tag, message, throwable);
}

@Override
public boolean isEnabled(@Nullable SentryLevel level) {
return true;
}

private int toLogcatLevel(final @NotNull SentryLevel sentryLevel) {
return Log.ASSERT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static void loadDefaultAndMetadataOptions(

// Firstly set the logger, if `debug=true` configured, logging can start asap.
options.setLogger(logger);
options.setFatalLogger(new AndroidFatalLogger());

options.setDefaultScopeType(ScopeType.CURRENT);
options.setOpenTelemetryMode(SentryOpenTelemetryMode.OFF);
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,7 @@ public class io/sentry/SentryOptions {
public fun getEventProcessors ()Ljava/util/List;
public fun getExecutorService ()Lio/sentry/ISentryExecutorService;
public fun getExperimental ()Lio/sentry/ExperimentalOptions;
public fun getFatalLogger ()Lio/sentry/ILogger;
public fun getFlushTimeoutMillis ()J
public fun getFullyDisplayedReporter ()Lio/sentry/FullyDisplayedReporter;
public fun getGestureTargetLocators ()Ljava/util/List;
Expand Down Expand Up @@ -3196,6 +3197,7 @@ public class io/sentry/SentryOptions {
public fun setEnvelopeReader (Lio/sentry/IEnvelopeReader;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setExecutorService (Lio/sentry/ISentryExecutorService;)V
public fun setFatalLogger (Lio/sentry/ILogger;)V
public fun setFlushTimeoutMillis (J)V
public fun setForceInit (Z)V
public fun setFullyDisplayedReporter (Lio/sentry/FullyDisplayedReporter;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public DefaultVersionDetector(final @NotNull SentryOptions options) {

@Override
public boolean checkForMixedVersions() {
return SentryIntegrationPackageStorage.getInstance().checkForMixedVersions(options.getLogger());
return SentryIntegrationPackageStorage.getInstance()
.checkForMixedVersions(options.getFatalLogger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ManifestVersionDetector(final @NotNull SentryOptions options) {
@Override
public boolean checkForMixedVersions() {
ManifestVersionReader.getInstance().readManifestFiles();
return SentryIntegrationPackageStorage.getInstance().checkForMixedVersions(options.getLogger());
return SentryIntegrationPackageStorage.getInstance()
.checkForMixedVersions(options.getFatalLogger());
}
}
7 changes: 7 additions & 0 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
.getLogger()
.log(SentryLevel.INFO, "GlobalHubMode: '%s'", String.valueOf(globalHubModeToUse));
Sentry.globalHubMode = globalHubModeToUse;
initFatalLogger(options);
final boolean shouldInit =
InitUtil.shouldInit(globalScope.getOptions(), options, isEnabled());
if (shouldInit) {
Expand Down Expand Up @@ -392,6 +393,12 @@ private static void initLogger(final @NotNull SentryOptions options) {
}
}

private static void initFatalLogger(final @NotNull SentryOptions options) {
if (options.getFatalLogger() instanceof NoOpLogger) {
options.setFatalLogger(new SystemOutLogger());
}
}

private static void initScopesStorage(SentryOptions options) {
getScopesStorage().close();
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
Expand Down
22 changes: 22 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public class SentryOptions {
/** Logger interface to log useful debugging information if debug is enabled */
private @NotNull ILogger logger = NoOpLogger.getInstance();

@ApiStatus.Experimental private @NotNull ILogger fatalLogger = NoOpLogger.getInstance();

/** minimum LogLevel to be used if debug is enabled */
private @NotNull SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL;

Expand Down Expand Up @@ -646,6 +648,26 @@ public void setLogger(final @Nullable ILogger logger) {
this.logger = (logger == null) ? NoOpLogger.getInstance() : new DiagnosticLogger(this, logger);
}

/**
* Returns the Logger interface for logging important SDK messages
*
* @return the logger for fatal SDK messages
*/
@ApiStatus.Experimental
public @NotNull ILogger getFatalLogger() {
return fatalLogger;
}

/**
* Sets the Logger interface for important SDK messages. If null, logger will be NoOp
*
* @param logger the logger for fatal SDK messages
*/
@ApiStatus.Experimental
public void setFatalLogger(final @Nullable ILogger logger) {
this.fatalLogger = (logger == null) ? NoOpLogger.getInstance() : logger;
}

/**
* Returns the minimum LogLevel
*
Expand Down
Loading