Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ agp = "9.5.1"
sqlite = "2.6.2"
sqliteRc = "2.8.0-alpha03" # Required by Room3 3.0.0-rc*
slf4j = "1.7.30"
spotless = "8.8.0"
spotless = "8.11.0"
springboot2 = "2.7.18"
springboot3 = "3.5.0"
springboot4 = "4.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,15 @@ private void runSafelyOnUiThread(final Runnable runnable, final String tag) {
if (AndroidThreadChecker.getInstance().isMainThread()) {
runnable.run();
} else {
handler.post(
() -> {
try {
runnable.run();
} catch (Throwable ignored) {
if (tag != null) {
options.getLogger().log(SentryLevel.WARNING, "Failed to execute " + tag);
}
}
});
handler.post(() -> {
try {
runnable.run();
} catch (Throwable ignored) {
if (tag != null) {
options.getLogger().log(SentryLevel.WARNING, "Failed to execute " + tag);
}
}
});
}
} catch (Throwable ignored) {
if (tag != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,21 @@ private void startTracing(final @NotNull Activity activity) {
transactionOptions.setTrimEnd(true);
}
transactionOptions.setWaitForChildren(true);
transactionOptions.setTransactionFinishedCallback(
(finishingTransaction) -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(
unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});
transactionOptions.setTransactionFinishedCallback(finishingTransaction -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});

// This will be the start timestamp of the transaction, as well as the ttid/ttfd spans
final @NotNull SentryDate ttidStartTime;
Expand Down Expand Up @@ -407,10 +405,9 @@ private void startTracing(final @NotNull Activity activity) {
}

// lets bind to the scope so other integrations can pick it up
scopes.configureScope(
scope -> {
applyScope(scope, transaction);
});
scopes.configureScope(scope -> {
applyScope(scope, transaction);
});

activitiesWithOngoingTransactions.put(activity, transaction);
}
Expand Down Expand Up @@ -478,32 +475,30 @@ private boolean isWithinAppStartContinuationWindow(final @NotNull SentryDate uiL

@VisibleForTesting
void applyScope(final @NotNull IScope scope, final @NotNull ITransaction transaction) {
scope.withTransaction(
scopeTransaction -> {
// we'd not like to overwrite existent transactions bound to the Scope
// manually.
if (scopeTransaction == null) {
scope.setTransaction(transaction);
} else if (options != null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Transaction '%s' won't be bound to the Scope since there's one already in there.",
transaction.getName());
}
});
scope.withTransaction(scopeTransaction -> {
// we'd not like to overwrite existent transactions bound to the Scope
// manually.
if (scopeTransaction == null) {
scope.setTransaction(transaction);
} else if (options != null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Transaction '%s' won't be bound to the Scope since there's one already in there.",
transaction.getName());
}
});
}

@VisibleForTesting
@SuppressWarnings("ReferenceEquality")
void clearScope(final @NotNull IScope scope, final @NotNull ITransaction transaction) {
scope.withTransaction(
scopeTransaction -> {
if (scopeTransaction == transaction) {
scope.clearTransaction();
}
});
scope.withTransaction(scopeTransaction -> {
if (scopeTransaction == transaction) {
scope.clearTransaction();
}
});
}

private boolean isRunningTransactionOrTrace(final @NotNull Activity activity) {
Expand Down Expand Up @@ -542,10 +537,9 @@ private void finishTransaction(
if (scopes != null) {
// make sure to remove the transaction from scope, as it may contain running children,
// therefore `finish` method will not remove it from scope
scopes.configureScope(
scope -> {
clearScope(scope, transaction);
});
scopes.configureScope(scope -> {
clearScope(scope, transaction);
});
}
}
}
Expand Down Expand Up @@ -1066,10 +1060,8 @@ private void onHeadlessAppStart() {
// Persist the end time (covering every finish path: user finish, first frame, deadline) so a
// later ui.load can tell whether it is close enough to continue this trace; without it the
// continuation window is unbounded.
txnOptions.setTransactionFinishedCallback(
finishedTransaction ->
AppStartMetrics.getInstance()
.setAppStartEndTime(finishedTransaction.getFinishDate()));
txnOptions.setTransactionFinishedCallback(finishedTransaction ->
AppStartMetrics.getInstance().setAppStartEndTime(finishedTransaction.getFinishDate()));
}

final @NotNull TransactionContext txnContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,22 @@ private void sendChunks(final @NotNull IScopes scopes, final @NotNull SentryOpti
try {
options
.getExecutorService()
.submit(
() -> {
// SDK is closed, we don't send the chunks
if (isClosed.get()) {
return;
}
final ArrayList<ProfileChunk> payloads = new ArrayList<>(payloadBuilders.size());
try (final @NotNull ISentryLifecycleToken ignored = payloadLock.acquire()) {
for (ProfileChunk.Builder builder : payloadBuilders) {
payloads.add(builder.build(options));
}
payloadBuilders.clear();
}
for (ProfileChunk payload : payloads) {
scopes.captureProfileChunk(payload);
}
});
.submit(() -> {
// SDK is closed, we don't send the chunks
if (isClosed.get()) {
return;
}
final ArrayList<ProfileChunk> payloads = new ArrayList<>(payloadBuilders.size());
try (final @NotNull ISentryLifecycleToken ignored = payloadLock.acquire()) {
for (ProfileChunk.Builder builder : payloadBuilders) {
payloads.add(builder.build(options));
}
payloadBuilders.clear();
}
for (ProfileChunk payload : payloads) {
scopes.captureProfileChunk(payload);
}
});
} catch (Throwable e) {
options.getLogger().log(SentryLevel.DEBUG, "Failed to send profile chunks.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ private void register(
try {
options
.getExecutorService()
.submit(
() -> {
try (final @NotNull ISentryLifecycleToken ignored = startLock.acquire()) {
if (!isClosed) {
startAnrWatchdog(scopes, options);
}
}
});
.submit(() -> {
try (final @NotNull ISentryLifecycleToken ignored = startLock.acquire()) {
if (!isClosed) {
startAnrWatchdog(scopes, options);
}
}
});
} catch (Throwable e) {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,45 +98,42 @@ private ContextUtils() {}
*/
@SuppressLint("NewApi")
private static final @NotNull AndroidLazyEvaluator<PackageInfo> staticPackageInfo33 =
new AndroidLazyEvaluator<>(
context -> {
try {
return context
.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(0));
} catch (Throwable e) {
return null;
}
});
new AndroidLazyEvaluator<>(context -> {
try {
return context
.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(0));
} catch (Throwable e) {
return null;
}
});

private static final @NotNull AndroidLazyEvaluator<PackageInfo> staticPackageInfo =
new AndroidLazyEvaluator<>(
context -> {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (Throwable e) {
return null;
}
});
new AndroidLazyEvaluator<>(context -> {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (Throwable e) {
return null;
}
});

private static final @NotNull AndroidLazyEvaluator<String> applicationName =
new AndroidLazyEvaluator<>(
context -> {
try {
final ApplicationInfo applicationInfo = context.getApplicationInfo();
final int stringId = applicationInfo.labelRes;
if (stringId == 0) {
if (applicationInfo.nonLocalizedLabel != null) {
return applicationInfo.nonLocalizedLabel.toString();
}
return context.getPackageManager().getApplicationLabel(applicationInfo).toString();
} else {
return context.getString(stringId);
}
} catch (Throwable e) {
return null;
new AndroidLazyEvaluator<>(context -> {
try {
final ApplicationInfo applicationInfo = context.getApplicationInfo();
final int stringId = applicationInfo.labelRes;
if (stringId == 0) {
if (applicationInfo.nonLocalizedLabel != null) {
return applicationInfo.nonLocalizedLabel.toString();
}
});
return context.getPackageManager().getApplicationLabel(applicationInfo).toString();
} else {
return context.getString(stringId);
}
} catch (Throwable e) {
return null;
}
});

/**
* Since this applicationInfo uses the same flag (METADATA) we can assume it's static and cache it
Expand All @@ -145,30 +142,28 @@ private ContextUtils() {}
*/
@SuppressLint("NewApi")
private static final @NotNull AndroidLazyEvaluator<ApplicationInfo> staticAppInfo33 =
new AndroidLazyEvaluator<>(
context -> {
try {
return context
.getPackageManager()
.getApplicationInfo(
context.getPackageName(),
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA));
} catch (Throwable e) {
return null;
}
});
new AndroidLazyEvaluator<>(context -> {
try {
return context
.getPackageManager()
.getApplicationInfo(
context.getPackageName(),
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA));
} catch (Throwable e) {
return null;
}
});

private static final @NotNull AndroidLazyEvaluator<ApplicationInfo> staticAppInfo =
new AndroidLazyEvaluator<>(
context -> {
try {
return context
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
} catch (Throwable e) {
return null;
}
});
new AndroidLazyEvaluator<>(context -> {
try {
return context
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
} catch (Throwable e) {
return null;
}
});

/**
* Return the Application's PackageInfo if possible, or null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ public final void register(final @NotNull IScopes scopes, final @NotNull SentryO
try {
options
.getExecutorService()
.submit(
() -> {
try (final @NotNull ISentryLifecycleToken ignored = startLock.acquire()) {
if (!isClosed) {
startOutboxSender(scopes, options, path);
}
}
});
.submit(() -> {
try (final @NotNull ISentryLifecycleToken ignored = startLock.acquire()) {
if (!isClosed) {
startOutboxSender(scopes, options, path);
}
}
});
} catch (Throwable e) {
logger.log(
SentryLevel.DEBUG,
Expand Down
Loading
Loading