Skip to content

Commit

Permalink
Merge 80ec3f2 into 2a3dd50
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi authored Nov 30, 2023
2 parents 2a3dd50 + 80ec3f2 commit 3fd1e60
Show file tree
Hide file tree
Showing 32 changed files with 1,553 additions and 540 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 7.0.0

### Features

- (Internal, Experimental) Attach spans for Application, ContentProvider, and Activities to app-start ([#3057](https://github.com/getsentry/sentry-java/pull/3057))

## Unreleased

Version 7 of the Sentry Android/Java SDK brings a variety of features and fixes. The most notable changes are:
- Bumping `minSdk` level to 19 (Android 4.4)
- The SDK will now listen to connectivity changes and try to re-upload cached events when internet connection is re-established additionally to uploading events on app restart
Expand Down
111 changes: 92 additions & 19 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ public final class io/sentry/android/core/AppLifecycleIntegration : io/sentry/In
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
}

public final class io/sentry/android/core/AppStartState {
public fun getAppStartEndTime ()Lio/sentry/SentryDate;
public fun getAppStartInterval ()Ljava/lang/Long;
public fun getAppStartMillis ()Ljava/lang/Long;
public fun getAppStartTime ()Lio/sentry/SentryDate;
public static fun getInstance ()Lio/sentry/android/core/AppStartState;
public fun isColdStart ()Ljava/lang/Boolean;
public fun reset ()V
public fun setAppStartMillis (J)V
}

public final class io/sentry/android/core/AppState {
public static fun getInstance ()Lio/sentry/android/core/AppState;
public fun isInBackground ()Ljava/lang/Boolean;
Expand All @@ -155,6 +144,7 @@ public final class io/sentry/android/core/BuildInfoProvider {
}

public final class io/sentry/android/core/ContextUtils {
public static fun isForegroundImportance ()Z
}

public class io/sentry/android/core/CurrentActivityHolder {
Expand Down Expand Up @@ -276,6 +266,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun isEnableNetworkEventBreadcrumbs ()Z
public fun isEnableRootCheck ()Z
public fun isEnableScopeSync ()Z
public fun isEnableStarfish ()Z
public fun isEnableSystemEventBreadcrumbs ()Z
public fun isReportHistoricalAnrs ()Z
public fun setAnrEnabled (Z)V
Expand All @@ -298,6 +289,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setEnableNetworkEventBreadcrumbs (Z)V
public fun setEnableRootCheck (Z)V
public fun setEnableScopeSync (Z)V
public fun setEnableStarfish (Z)V
public fun setEnableSystemEventBreadcrumbs (Z)V
public fun setNativeSdkName (Ljava/lang/String;)V
public fun setProfilingTracesHz (I)V
Expand Down Expand Up @@ -335,17 +327,12 @@ public final class io/sentry/android/core/SentryLogcatAdapter {
public static fun wtf (Ljava/lang/String;Ljava/lang/Throwable;)I
}

public final class io/sentry/android/core/SentryPerformanceProvider : android/app/Application$ActivityLifecycleCallbacks {
public final class io/sentry/android/core/SentryPerformanceProvider {
public fun <init> ()V
public fun attachInfo (Landroid/content/Context;Landroid/content/pm/ProviderInfo;)V
public fun getActivityCallback ()Landroid/app/Application$ActivityLifecycleCallbacks;
public fun getType (Landroid/net/Uri;)Ljava/lang/String;
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
public fun onActivityPaused (Landroid/app/Activity;)V
public fun onActivityResumed (Landroid/app/Activity;)V
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityStarted (Landroid/app/Activity;)V
public fun onActivityStopped (Landroid/app/Activity;)V
public fun onAppLaunched ()V
public fun onCreate ()Z
}

Expand Down Expand Up @@ -397,3 +384,89 @@ public final class io/sentry/android/core/cache/AndroidEnvelopeCache : io/sentry
public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
}

public class io/sentry/android/core/performance/ActivityLifecycleCallbacksAdapter : android/app/Application$ActivityLifecycleCallbacks {
public fun <init> ()V
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
public fun onActivityPaused (Landroid/app/Activity;)V
public fun onActivityResumed (Landroid/app/Activity;)V
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityStarted (Landroid/app/Activity;)V
public fun onActivityStopped (Landroid/app/Activity;)V
}

public class io/sentry/android/core/performance/ActivityLifecycleTimeSpan : java/lang/Comparable {
public final field onCreate Lio/sentry/android/core/performance/TimeSpan;
public final field onStart Lio/sentry/android/core/performance/TimeSpan;
public fun <init> ()V
public fun compareTo (Lio/sentry/android/core/performance/ActivityLifecycleTimeSpan;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
}

public class io/sentry/android/core/performance/AppStartMetrics {
public fun <init> ()V
public fun addActivityLifecycleTimeSpans (Lio/sentry/android/core/performance/ActivityLifecycleTimeSpan;)V
public fun clear ()V
public fun getActivityLifecycleTimeSpans ()Ljava/util/List;
public fun getAppStartTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
public fun getAppStartType ()Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
public fun getApplicationOnCreateTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
public fun getContentProviderOnCreateTimeSpans ()Ljava/util/List;
public static fun getInstance ()Lio/sentry/android/core/performance/AppStartMetrics;
public fun getLegacyAppStartTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
public fun isAppLaunchedInForeground ()Z
public static fun onApplicationCreate (Landroid/app/Application;)V
public static fun onApplicationPostCreate (Landroid/app/Application;)V
public static fun onContentProviderCreate (Landroid/content/ContentProvider;)V
public static fun onContentProviderPostCreate (Landroid/content/ContentProvider;)V
public fun setAppStartType (Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;)V
}

public final class io/sentry/android/core/performance/AppStartMetrics$AppStartType : java/lang/Enum {
public static final field COLD Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
public static final field UNKNOWN Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
public static final field WARM Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
public static fun values ()[Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;
}

public class io/sentry/android/core/performance/NextDrawListener : android/view/View$OnAttachStateChangeListener, android/view/ViewTreeObserver$OnDrawListener {
protected fun <init> (Landroid/os/Handler;Ljava/lang/Runnable;)V
public static fun forActivity (Landroid/app/Activity;Ljava/lang/Runnable;)Lio/sentry/android/core/performance/NextDrawListener;
public fun onDraw ()V
public fun onViewAttachedToWindow (Landroid/view/View;)V
public fun onViewDetachedFromWindow (Landroid/view/View;)V
public fun unregister ()V
}

public class io/sentry/android/core/performance/TimeSpan : java/lang/Comparable {
public fun <init> ()V
public fun compareTo (Lio/sentry/android/core/performance/TimeSpan;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun getDescription ()Ljava/lang/String;
public fun getDurationMs ()J
public fun getProjectedStopTimestamp ()Lio/sentry/SentryDate;
public fun getProjectedStopTimestampMs ()J
public fun getProjectedStopTimestampS ()D
public fun getStartTimestamp ()Lio/sentry/SentryDate;
public fun getStartTimestampMs ()J
public fun getStartTimestampS ()D
public fun getStartUptimeMs ()J
public fun hasNotStarted ()Z
public fun hasNotStopped ()Z
public fun hasStarted ()Z
public fun hasStopped ()Z
public fun reset ()V
public fun setDescription (Ljava/lang/String;)V
public fun setStartUnixTimeMs (J)V
public fun setStartedAt (J)V
public fun setStoppedAt (J)V
public fun start ()V
public fun stop ()V
}

public class io/sentry/android/core/performance/WindowContentChangedCallback : io/sentry/android/core/internal/gestures/WindowCallbackAdapter {
public fun <init> (Landroid/view/Window$Callback;Ljava/lang/Runnable;)V
public fun onContentChanged ()V
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import io.sentry.TransactionOptions;
import io.sentry.android.core.internal.util.ClassUtil;
import io.sentry.android.core.internal.util.FirstDrawDoneListener;
import io.sentry.android.core.performance.AppStartMetrics;
import io.sentry.android.core.performance.TimeSpan;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.util.Objects;
Expand Down Expand Up @@ -70,7 +72,6 @@ public final class ActivityLifecycleIntegration
private boolean isAllActivityCallbacksAvailable;

private boolean firstActivityCreated = false;
private final boolean foregroundImportance;

private @Nullable FullyDisplayedReporter fullyDisplayedReporter = null;
private @Nullable ISpan appStartSpan;
Expand Down Expand Up @@ -100,10 +101,6 @@ public ActivityLifecycleIntegration(
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.Q) {
isAllActivityCallbacksAvailable = true;
}

// we only track app start for processes that will show an Activity (full launch).
// Here we check the process importance which will tell us that.
foregroundImportance = ContextUtils.isForegroundImportance();
}

@Override
Expand Down Expand Up @@ -182,15 +179,27 @@ private void startTracing(final @NotNull Activity activity) {
if (!performanceEnabled) {
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
TracingUtils.startNewTrace(hub);
} else if (performanceEnabled) {
} else {
// as we allow a single transaction running on the bound Scope, we finish the previous ones
stopPreviousTransactions();

final String activityName = getActivityName(activity);

final SentryDate appStartTime =
foregroundImportance ? AppStartState.getInstance().getAppStartTime() : null;
final Boolean coldStart = AppStartState.getInstance().isColdStart();
final @Nullable SentryDate appStartTime;
final @Nullable Boolean coldStart;
final TimeSpan appStartTimeSpan = getAppStartTimeSpan();

// we only track app start for processes that will show an Activity (full launch).
// Here we check the process importance which will tell us that.
final boolean foregroundImportance = ContextUtils.isForegroundImportance();
if (foregroundImportance && appStartTimeSpan.hasStarted()) {
appStartTime = appStartTimeSpan.getStartTimestamp();
coldStart =
AppStartMetrics.getInstance().getAppStartType() == AppStartMetrics.AppStartType.COLD;
} else {
appStartTime = null;
coldStart = null;
}

final TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.setDeadlineTimeout(
Expand Down Expand Up @@ -407,6 +416,7 @@ public synchronized void onActivityStarted(final @NotNull Activity activity) {
@Override
public synchronized void onActivityResumed(final @NotNull Activity activity) {
if (performanceEnabled) {

final @Nullable ISpan ttidSpan = ttidSpanMap.get(activity);
final @Nullable ISpan ttfdSpan = ttfdSpanMap.get(activity);
final View rootView = activity.findViewById(android.R.id.content);
Expand Down Expand Up @@ -536,13 +546,13 @@ private void cancelTtfdAutoClose() {

private void onFirstFrameDrawn(final @Nullable ISpan ttfdSpan, final @Nullable ISpan ttidSpan) {
// app start span
@Nullable final SentryDate appStartStartTime = AppStartState.getInstance().getAppStartTime();
@Nullable final SentryDate appStartEndTime = AppStartState.getInstance().getAppStartEndTime();
final @NotNull TimeSpan appStartTimeSpan = getAppStartTimeSpan();

// in case the SentryPerformanceProvider is disabled it does not set the app start times,
// and we need to set the end time manually here,
// the start time gets set manually in SentryAndroid.init()
if (appStartStartTime != null && appStartEndTime == null) {
AppStartState.getInstance().setAppStartEnd();
if (appStartTimeSpan.hasStarted() && appStartTimeSpan.hasNotStopped()) {
appStartTimeSpan.stop();
}
finishAppStartSpan();

Expand Down Expand Up @@ -626,7 +636,15 @@ private void setColdStart(final @Nullable Bundle savedInstanceState) {
if (!firstActivityCreated) {
// if Activity has savedInstanceState then its a warm start
// https://developer.android.com/topic/performance/vitals/launch-time#warm
AppStartState.getInstance().setColdStart(savedInstanceState == null);
// SentryPerformanceProvider sets this already
// pre-starfish: back-fill with best guess
if (options != null && !options.isEnableStarfish()) {
AppStartMetrics.getInstance()
.setAppStartType(
savedInstanceState == null
? AppStartMetrics.AppStartType.COLD
: AppStartMetrics.AppStartType.WARM);
}
}
}

Expand Down Expand Up @@ -662,9 +680,18 @@ private void setColdStart(final @Nullable Bundle savedInstanceState) {
}

private void finishAppStartSpan() {
final @Nullable SentryDate appStartEndTime = AppStartState.getInstance().getAppStartEndTime();
final @NotNull TimeSpan appStartTimeSpan = getAppStartTimeSpan();
final @Nullable SentryDate appStartEndTime = appStartTimeSpan.getProjectedStopTimestamp();
if (performanceEnabled && appStartEndTime != null) {
finishSpan(appStartSpan, appStartEndTime);
}
}

private @NotNull TimeSpan getAppStartTimeSpan() {
final @NotNull TimeSpan appStartTimeSpan =
options.isEnableStarfish()
? AppStartMetrics.getInstance().getAppStartTimeSpan()
: AppStartMetrics.getInstance().getLegacyAppStartTimeSpan();
return appStartTimeSpan;
}
}
Loading

0 comments on commit 3fd1e60

Please sign in to comment.