Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2706,6 +2706,7 @@ public final class io/sentry/SentryInstantDateProvider : io/sentry/SentryDatePro
public final class io/sentry/SentryIntegrationPackageStorage {
public fun addIntegration (Ljava/lang/String;)V
public fun addPackage (Ljava/lang/String;Ljava/lang/String;)V
public fun checkForMixedVersions (Lio/sentry/ILogger;)Z
public fun clearStorage ()V
public static fun getInstance ()Lio/sentry/SentryIntegrationPackageStorage;
public fun getIntegrations ()Ljava/util/Set;
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
.log(SentryLevel.ERROR, "The BeforeEnvelope callback threw an exception.", e);
}
}

SentryIntegrationPackageStorage.getInstance().checkForMixedVersions(options.getLogger());

if (hint == null) {
transport.send(envelope);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public final class SentryIntegrationPackageStorage {
private static volatile @Nullable SentryIntegrationPackageStorage INSTANCE;
private static final @NotNull AutoClosableReentrantLock staticLock =
new AutoClosableReentrantLock();
private static volatile @Nullable Boolean mixedVersionsDetected = null;
private static final @NotNull AutoClosableReentrantLock mixedVersionsLock =
new AutoClosableReentrantLock();

public static @NotNull SentryIntegrationPackageStorage getInstance() {
if (INSTANCE == null) {
Expand Down Expand Up @@ -64,12 +67,48 @@ public void addPackage(final @NotNull String name, final @NotNull String version

SentryPackage newPackage = new SentryPackage(name, version);
packages.add(newPackage);
try (final @NotNull ISentryLifecycleToken ignored = mixedVersionsLock.acquire()) {
mixedVersionsDetected = null;
}
}

public @NotNull Set<SentryPackage> getPackages() {
return packages;
}

public boolean checkForMixedVersions(final @NotNull ILogger logger) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess would be nice to have a test for this (if not yet)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah will PR one

final @Nullable Boolean mixedVersionsDetectedBefore = mixedVersionsDetected;
if (mixedVersionsDetectedBefore != null) {
return mixedVersionsDetectedBefore;
}
try (final @NotNull ISentryLifecycleToken ignored = mixedVersionsLock.acquire()) {
final @NotNull String sdkVersion = BuildConfig.VERSION_NAME;
boolean mixedVersionsDetectedThisCheck = false;

for (SentryPackage pkg : packages) {
if (pkg.getName().startsWith("maven:io.sentry:")
&& !sdkVersion.equalsIgnoreCase(pkg.getVersion())) {
logger.log(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking if we should introduce a method that force-logs regardless of the debug and diagnosticLevel values set and use it here, wdyt?

SentryLevel.ERROR,
"The Sentry SDK has been configured with mixed versions. Expected %s to match core SDK version %s but was %s",
pkg.getName(),
sdkVersion,
pkg.getVersion());
mixedVersionsDetectedThisCheck = true;
}
}

if (mixedVersionsDetectedThisCheck) {
logger.log(SentryLevel.ERROR, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
logger.log(SentryLevel.ERROR, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
logger.log(SentryLevel.ERROR, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
logger.log(SentryLevel.ERROR, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
}
mixedVersionsDetected = mixedVersionsDetectedThisCheck;
Comment thread
romtsn marked this conversation as resolved.
return mixedVersionsDetectedThisCheck;
}
}

@TestOnly
public void clearStorage() {
integrations.clear();
Expand Down
Loading