Skip to content

Commit 6e875e6

Browse files
Merge branch '7.x.x' into kw-fix-not-registering-app-integrations-on-context-wrappers
2 parents be28f39 + 98fe7b0 commit 6e875e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2920
-476
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# Changelog
22

3+
## 7.22.5
4+
5+
### Fixes
6+
7+
- Session Replay: Change bitmap config to `ARGB_8888` for screenshots ([#4282](https://github.com/getsentry/sentry-java/pull/4282))
8+
9+
## 7.22.4
10+
11+
### Fixes
12+
13+
- Session Replay: Fix crash when a navigation breadcrumb does not have "to" destination ([#4185](https://github.com/getsentry/sentry-java/pull/4185))
14+
- Session Replay: Cap video segment duration to maximum 5 minutes to prevent endless video encoding in background ([#4185](https://github.com/getsentry/sentry-java/pull/4185))
15+
- Avoid logging an error when a float is passed in the manifest ([#4266](https://github.com/getsentry/sentry-java/pull/4266))
16+
17+
## 7.22.3
18+
19+
### Fixes
20+
21+
- Reduce excessive CPU usage when serializing breadcrumbs to disk for ANRs ([#4181](https://github.com/getsentry/sentry-java/pull/4181))
22+
23+
## 7.22.2
24+
25+
### Fixes
26+
27+
- Fix AbstractMethodError when using SentryTraced for Jetpack Compose ([#4256](https://github.com/getsentry/sentry-java/pull/4256))
28+
29+
## 7.22.1
30+
31+
### Fixes
32+
33+
- Fix Ensure app start type is set, even when ActivityLifecycleIntegration is not running ([#4216](https://github.com/getsentry/sentry-java/pull/4216))
34+
- Fix properly reset application/content-provider timespans for warm app starts ([#4244](https://github.com/getsentry/sentry-java/pull/4244))
35+
336
## 7.22.0
437

538
### Fixes

buildSrc/src/main/java/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ object Config {
202202
val msgpack = "org.msgpack:msgpack-core:0.9.8"
203203
val leakCanaryInstrumentation = "com.squareup.leakcanary:leakcanary-android-instrumentation:2.14"
204204
val composeUiTestJunit4 = "androidx.compose.ui:ui-test-junit4:$composeVersion"
205+
val okio = "com.squareup.okio:okio:1.13.0"
205206
}
206207

207208
object QualityPlugins {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android.useAndroidX=true
1313
android.defaults.buildfeatures.buildconfig=true
1414

1515
# Release information
16-
versionName=7.22.0
16+
versionName=7.22.5
1717

1818
# Override the SDK name on native crashes on Android
1919
sentryAndroidSdkName=sentry.native.android

sentry-android-core/api/sentry-android-core.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,15 @@ public class io/sentry/android/core/performance/AppStartMetrics : io/sentry/andr
447447
public static fun getInstance ()Lio/sentry/android/core/performance/AppStartMetrics;
448448
public fun getSdkInitTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
449449
public fun isAppLaunchedInForeground ()Z
450-
public fun isColdStartValid ()Z
451450
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
451+
public fun onActivityDestroyed (Landroid/app/Activity;)V
452+
public fun onActivityStarted (Landroid/app/Activity;)V
452453
public fun onAppStartSpansSent ()V
453454
public static fun onApplicationCreate (Landroid/app/Application;)V
454455
public static fun onApplicationPostCreate (Landroid/app/Application;)V
455456
public static fun onContentProviderCreate (Landroid/content/ContentProvider;)V
456457
public static fun onContentProviderPostCreate (Landroid/content/ContentProvider;)V
457-
public fun registerApplicationForegroundCheck (Landroid/app/Application;)V
458-
public fun restartAppStart (J)V
458+
public fun registerLifecycleCallbacks (Landroid/app/Application;)V
459459
public fun setAppLaunchedInForeground (Z)V
460460
public fun setAppStartProfiler (Lio/sentry/ITransactionProfiler;)V
461461
public fun setAppStartSamplingDecision (Lio/sentry/TracesSamplingDecision;)V

sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public synchronized void onActivityCreated(
397397
if (!isAllActivityCallbacksAvailable) {
398398
onActivityPreCreated(activity, savedInstanceState);
399399
}
400-
setColdStart(savedInstanceState);
401400
if (hub != null && options != null && options.isEnableScreenTracking()) {
402401
final @Nullable String activityClassName = ClassUtil.getClassName(activity);
403402
hub.configureScope(scope -> scope.setScreen(activityClassName));
@@ -554,15 +553,13 @@ public synchronized void onActivityDestroyed(final @NotNull Activity activity) {
554553
// if the activity is opened again and not in memory, transactions will be created normally.
555554
activitiesWithOngoingTransactions.remove(activity);
556555

557-
if (activitiesWithOngoingTransactions.isEmpty()) {
556+
if (activitiesWithOngoingTransactions.isEmpty() && !activity.isChangingConfigurations()) {
558557
clear();
559558
}
560559
}
561560

562561
private void clear() {
563562
firstActivityCreated = false;
564-
lastPausedTime = new SentryNanotimeDate(new Date(0), 0);
565-
lastPausedUptimeMillis = 0;
566563
activityLifecycleMap.clear();
567564
}
568565

@@ -705,27 +702,6 @@ WeakHashMap<Activity, ISpan> getTtfdSpanMap() {
705702
return ttfdSpanMap;
706703
}
707704

708-
private void setColdStart(final @Nullable Bundle savedInstanceState) {
709-
if (!firstActivityCreated) {
710-
final @NotNull TimeSpan appStartSpan = AppStartMetrics.getInstance().getAppStartTimeSpan();
711-
// If the app start span already started and stopped, it means the app restarted without
712-
// killing the process, so we are in a warm start
713-
// If the app has an invalid cold start, it means it was started in the background, like
714-
// via BroadcastReceiver, so we consider it a warm start
715-
if ((appStartSpan.hasStarted() && appStartSpan.hasStopped())
716-
|| (!AppStartMetrics.getInstance().isColdStartValid())) {
717-
AppStartMetrics.getInstance().restartAppStart(lastPausedUptimeMillis);
718-
AppStartMetrics.getInstance().setAppStartType(AppStartMetrics.AppStartType.WARM);
719-
} else {
720-
AppStartMetrics.getInstance()
721-
.setAppStartType(
722-
savedInstanceState == null
723-
? AppStartMetrics.AppStartType.COLD
724-
: AppStartMetrics.AppStartType.WARM);
725-
}
726-
}
727-
}
728-
729705
private @NotNull String getTtidDesc(final @NotNull String activityName) {
730706
return activityName + " initial display";
731707
}

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ static void initializeIntegrationsAndProcessors(
143143
new AndroidConnectionStatusProvider(context, options.getLogger(), buildInfoProvider));
144144
}
145145

146+
if (options.getCacheDirPath() != null) {
147+
options.addScopeObserver(new PersistingScopeObserver(options));
148+
options.addOptionsObserver(new PersistingOptionsObserver(options));
149+
}
150+
146151
options.addEventProcessor(new DeduplicateMultithreadedEventProcessor(options));
147152
options.addEventProcessor(
148153
new DefaultAndroidEventProcessor(context, buildInfoProvider, options));
@@ -221,13 +226,6 @@ static void initializeIntegrationsAndProcessors(
221226
}
222227
}
223228
options.setTransactionPerformanceCollector(new DefaultTransactionPerformanceCollector(options));
224-
225-
if (options.getCacheDirPath() != null) {
226-
if (options.isEnableScopePersistence()) {
227-
options.addScopeObserver(new PersistingScopeObserver(options));
228-
}
229-
options.addOptionsObserver(new PersistingOptionsObserver(options));
230-
}
231229
}
232230

233231
static void installDefaultIntegrations(
@@ -273,6 +271,8 @@ static void installDefaultIntegrations(
273271
// AppLifecycleIntegration has to be installed before AnrIntegration, because AnrIntegration
274272
// relies on AppState set by it
275273
options.addIntegration(new AppLifecycleIntegration());
274+
// AnrIntegration must be installed before ReplayIntegration, as ReplayIntegration relies on
275+
// it to set the replayId in case of an ANR
276276
options.addIntegration(AnrIntegrationFactory.create(context, buildInfoProvider));
277277

278278
// registerActivityLifecycleCallbacks is only available on AppContext

sentry-android-core/src/main/java/io/sentry/android/core/AnrV2EventProcessor.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.sentry.SentryEvent;
3434
import io.sentry.SentryExceptionFactory;
3535
import io.sentry.SentryLevel;
36+
import io.sentry.SentryOptions;
3637
import io.sentry.SentryStackTraceFactory;
3738
import io.sentry.SpanContext;
3839
import io.sentry.android.core.internal.util.CpuInfoUtils;
@@ -83,13 +84,16 @@ public final class AnrV2EventProcessor implements BackfillingEventProcessor {
8384

8485
private final @NotNull SentryExceptionFactory sentryExceptionFactory;
8586

87+
private final @Nullable PersistingScopeObserver persistingScopeObserver;
88+
8689
public AnrV2EventProcessor(
8790
final @NotNull Context context,
8891
final @NotNull SentryAndroidOptions options,
8992
final @NotNull BuildInfoProvider buildInfoProvider) {
9093
this.context = ContextUtils.getApplicationContext(context);
9194
this.options = options;
9295
this.buildInfoProvider = buildInfoProvider;
96+
this.persistingScopeObserver = options.findPersistingScopeObserver();
9397

9498
final SentryStackTraceFactory sentryStackTraceFactory =
9599
new SentryStackTraceFactory(this.options);
@@ -188,8 +192,7 @@ private boolean sampleReplay(final @NotNull SentryEvent event) {
188192
}
189193

190194
private void setReplayId(final @NotNull SentryEvent event) {
191-
@Nullable
192-
String persistedReplayId = PersistingScopeObserver.read(options, REPLAY_FILENAME, String.class);
195+
@Nullable String persistedReplayId = readFromDisk(options, REPLAY_FILENAME, String.class);
193196
final @NotNull File replayFolder =
194197
new File(options.getCacheDirPath(), "replay_" + persistedReplayId);
195198
if (!replayFolder.exists()) {
@@ -224,8 +227,7 @@ private void setReplayId(final @NotNull SentryEvent event) {
224227
}
225228

226229
private void setTrace(final @NotNull SentryEvent event) {
227-
final SpanContext spanContext =
228-
PersistingScopeObserver.read(options, TRACE_FILENAME, SpanContext.class);
230+
final SpanContext spanContext = readFromDisk(options, TRACE_FILENAME, SpanContext.class);
229231
if (event.getContexts().getTrace() == null) {
230232
if (spanContext != null
231233
&& spanContext.getSpanId() != null
@@ -236,8 +238,7 @@ private void setTrace(final @NotNull SentryEvent event) {
236238
}
237239

238240
private void setLevel(final @NotNull SentryEvent event) {
239-
final SentryLevel level =
240-
PersistingScopeObserver.read(options, LEVEL_FILENAME, SentryLevel.class);
241+
final SentryLevel level = readFromDisk(options, LEVEL_FILENAME, SentryLevel.class);
241242
if (event.getLevel() == null) {
242243
event.setLevel(level);
243244
}
@@ -246,7 +247,7 @@ private void setLevel(final @NotNull SentryEvent event) {
246247
@SuppressWarnings("unchecked")
247248
private void setFingerprints(final @NotNull SentryEvent event, final @NotNull Object hint) {
248249
final List<String> fingerprint =
249-
(List<String>) PersistingScopeObserver.read(options, FINGERPRINT_FILENAME, List.class);
250+
(List<String>) readFromDisk(options, FINGERPRINT_FILENAME, List.class);
250251
if (event.getFingerprints() == null) {
251252
event.setFingerprints(fingerprint);
252253
}
@@ -262,16 +263,14 @@ private void setFingerprints(final @NotNull SentryEvent event, final @NotNull Ob
262263
}
263264

264265
private void setTransaction(final @NotNull SentryEvent event) {
265-
final String transaction =
266-
PersistingScopeObserver.read(options, TRANSACTION_FILENAME, String.class);
266+
final String transaction = readFromDisk(options, TRANSACTION_FILENAME, String.class);
267267
if (event.getTransaction() == null) {
268268
event.setTransaction(transaction);
269269
}
270270
}
271271

272272
private void setContexts(final @NotNull SentryBaseEvent event) {
273-
final Contexts persistedContexts =
274-
PersistingScopeObserver.read(options, CONTEXTS_FILENAME, Contexts.class);
273+
final Contexts persistedContexts = readFromDisk(options, CONTEXTS_FILENAME, Contexts.class);
275274
if (persistedContexts == null) {
276275
return;
277276
}
@@ -291,7 +290,7 @@ private void setContexts(final @NotNull SentryBaseEvent event) {
291290
@SuppressWarnings("unchecked")
292291
private void setExtras(final @NotNull SentryBaseEvent event) {
293292
final Map<String, Object> extras =
294-
(Map<String, Object>) PersistingScopeObserver.read(options, EXTRAS_FILENAME, Map.class);
293+
(Map<String, Object>) readFromDisk(options, EXTRAS_FILENAME, Map.class);
295294
if (extras == null) {
296295
return;
297296
}
@@ -309,14 +308,12 @@ private void setExtras(final @NotNull SentryBaseEvent event) {
309308
@SuppressWarnings("unchecked")
310309
private void setBreadcrumbs(final @NotNull SentryBaseEvent event) {
311310
final List<Breadcrumb> breadcrumbs =
312-
(List<Breadcrumb>)
313-
PersistingScopeObserver.read(
314-
options, BREADCRUMBS_FILENAME, List.class, new Breadcrumb.Deserializer());
311+
(List<Breadcrumb>) readFromDisk(options, BREADCRUMBS_FILENAME, List.class);
315312
if (breadcrumbs == null) {
316313
return;
317314
}
318315
if (event.getBreadcrumbs() == null) {
319-
event.setBreadcrumbs(new ArrayList<>(breadcrumbs));
316+
event.setBreadcrumbs(breadcrumbs);
320317
} else {
321318
event.getBreadcrumbs().addAll(breadcrumbs);
322319
}
@@ -326,7 +323,7 @@ private void setBreadcrumbs(final @NotNull SentryBaseEvent event) {
326323
private void setScopeTags(final @NotNull SentryBaseEvent event) {
327324
final Map<String, String> tags =
328325
(Map<String, String>)
329-
PersistingScopeObserver.read(options, PersistingScopeObserver.TAGS_FILENAME, Map.class);
326+
readFromDisk(options, PersistingScopeObserver.TAGS_FILENAME, Map.class);
330327
if (tags == null) {
331328
return;
332329
}
@@ -343,19 +340,29 @@ private void setScopeTags(final @NotNull SentryBaseEvent event) {
343340

344341
private void setUser(final @NotNull SentryBaseEvent event) {
345342
if (event.getUser() == null) {
346-
final User user = PersistingScopeObserver.read(options, USER_FILENAME, User.class);
343+
final User user = readFromDisk(options, USER_FILENAME, User.class);
347344
event.setUser(user);
348345
}
349346
}
350347

351348
private void setRequest(final @NotNull SentryBaseEvent event) {
352349
if (event.getRequest() == null) {
353-
final Request request =
354-
PersistingScopeObserver.read(options, REQUEST_FILENAME, Request.class);
350+
final Request request = readFromDisk(options, REQUEST_FILENAME, Request.class);
355351
event.setRequest(request);
356352
}
357353
}
358354

355+
private <T> @Nullable T readFromDisk(
356+
final @NotNull SentryOptions options,
357+
final @NotNull String fileName,
358+
final @NotNull Class<T> clazz) {
359+
if (persistingScopeObserver == null) {
360+
return null;
361+
}
362+
363+
return persistingScopeObserver.read(options, fileName, clazz);
364+
}
365+
359366
// endregion
360367

361368
// region options persisted values

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,10 @@ private static boolean readBool(
494494
private static @NotNull Double readDouble(
495495
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
496496
// manifest meta-data only reads float
497-
final Double value = ((Number) metadata.getFloat(key, metadata.getInt(key, -1))).doubleValue();
497+
double value = ((Float) metadata.getFloat(key, -1)).doubleValue();
498+
if (value == -1) {
499+
value = ((Integer) metadata.getInt(key, -1)).doubleValue();
500+
}
498501
logger.log(SentryLevel.DEBUG, key + " read: " + value);
499502
return value;
500503
}

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static synchronized void init(
152152
}
153153
}
154154
if (context.getApplicationContext() instanceof Application) {
155-
appStartMetrics.registerApplicationForegroundCheck(
155+
appStartMetrics.registerLifecycleCallbacks(
156156
(Application) context.getApplicationContext());
157157
}
158158
final @NotNull TimeSpan sdkInitTimeSpan = appStartMetrics.getSdkInitTimeSpan();

0 commit comments

Comments
 (0)