-
- All Implemented Interfaces:
-
android.app.Application.ActivityLifecycleCallbacks
@ApiStatus.Internal() public class AppStartMetrics extends ActivityLifecycleCallbacksAdapter
An in-memory representation for app-metrics during app start. As the SDK can't be initialized that early, we can't use transactions or spans directly. Thus simple TimeSpans are used and later transformed into SDK specific txn/span data structures.
This class is also responsible for - determining the app start type (cold, warm) - determining if the app was launched in foreground
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceAppStartMetrics.HeadlessAppStartListenerpublic enumAppStartMetrics.AppStartType
-
Field Summary
Fields Modifier and Type Field Description private static volatile AppStartMetricsinstancepublic final static AutoClosableReentrantLockstaticLockprivate AppStartMetrics.AppStartTypeappStartTypeprivate final LazyEvaluator<Boolean>appLaunchedInForegroundprivate final TimeSpansdkInitTimeSpanprivate ITransactionProfilerappStartProfilerprivate IContinuousProfilerappStartContinuousProfilerprivate TracesSamplingDecisionappStartSamplingDecisionprivate volatile AppStartMetrics.HeadlessAppStartListenerheadlessAppStartListenerprivate SentryIdappStartTraceIdprivate StringappStartSentryTraceHeaderprivate StringappStartBaggageHeaderprivate SentryDateappStartEndTimeprivate ApplicationStartInfocachedStartInfoprivate final AppStartExtensionappStartExtension
-
Constructor Summary
Constructors Constructor Description AppStartMetrics()
-
Method Summary
Modifier and Type Method Description static AppStartMetricsgetInstance()AppStartMetrics.AppStartTypegetAppStartType()voidsetAppStartType(@NotNull() AppStartMetrics.AppStartType appStartType)voidsetAppLaunchedInForeground(boolean appLaunchedInForeground)TimeSpangetSdkInitTimeSpan()ITransactionProfilergetAppStartProfiler()voidsetAppStartProfiler(@Nullable() ITransactionProfiler appStartProfiler)IContinuousProfilergetAppStartContinuousProfiler()voidsetAppStartContinuousProfiler(@Nullable() IContinuousProfiler appStartContinuousProfiler)TracesSamplingDecisiongetAppStartSamplingDecision()voidsetAppStartSamplingDecision(@Nullable() TracesSamplingDecision appStartSamplingDecision)voidsetHeadlessAppStartListener(@Nullable() AppStartMetrics.HeadlessAppStartListener listener)SentryIdgetAppStartTraceId()voidsetAppStartTraceId(@Nullable() SentryId traceId)StringgetAppStartSentryTraceHeader()voidsetAppStartSentryTraceHeader(@Nullable() String appStartSentryTraceHeader)StringgetAppStartBaggageHeader()voidsetAppStartBaggageHeader(@Nullable() String appStartBaggageHeader)SentryDategetAppStartEndTime()voidsetAppStartEndTime(@Nullable() SentryDate appStartEndTime)voidsetCachedStartInfo(@Nullable() ApplicationStartInfo cachedStartInfo)AppStartExtensiongetAppStartExtension()TimeSpangetAppStartTimeSpan()TimeSpancreateProcessInitSpan()TimeSpangetApplicationOnCreateTimeSpan()StringgetAppStartReason()The reason the OS started the process, mapped from getReason. booleanisAppLaunchedInForeground()List<TimeSpan>getContentProviderOnCreateTimeSpans()Provides all collected content provider onCreate time spans List<ActivityLifecycleTimeSpan>getActivityLifecycleTimeSpans()voidaddActivityLifecycleTimeSpans(@NotNull() ActivityLifecycleTimeSpan timeSpan)voidonAppStartSpansSent()booleanshouldSendStartMeasurements(boolean ignoreForegroundCheck)booleanshouldSendStartMeasurements()longgetClassLoadedUptimeMs()TimeSpangetAppStartTimeSpanForHeadless()Returns a valid app start time span, bypassing the foreground check. TimeSpangetAppStartTimeSpanWithFallback(@NotNull() SentryAndroidOptions options)booleancanExtendAppStart()Whether the app start can still be extended: measurements haven't been sent yet, no activityhas been created, and the first frame hasn't been drawn. voidclear()voidsetClassLoadedUptimeMs(long classLoadedUptimeMs)static voidonApplicationCreate(@NotNull() Application application)Called by instrumentation static voidonApplicationPostCreate(@NotNull() Application application)Called by instrumentation voidregisterLifecycleCallbacks(@NotNull() Application application)Register a callback to check if an activity was started after the application was created. voidonActivityCreated(@NonNull() Activity activity, @Nullable() Bundle savedInstanceState)voidonActivityStarted(@NonNull() Activity activity)voidonActivityResumed(@NonNull() Activity activity)voidonActivityPaused(@NonNull() Activity activity)voidonActivityStopped(@NonNull() Activity activity)voidonActivityDestroyed(@NonNull() Activity activity)static voidonContentProviderCreate(@NotNull() ContentProvider contentProvider)Called by instrumentation static voidonContentProviderPostCreate(@NotNull() ContentProvider contentProvider)Called by instrumentation -
Methods inherited from class io.sentry.android.core.performance.ActivityLifecycleCallbacksAdapter
onActivitySaveInstanceState -
Methods inherited from class android.app.Application.ActivityLifecycleCallbacks
onActivityCreated, onActivityDestroyed, onActivityPaused, onActivityPostCreated, onActivityPostDestroyed, onActivityPostPaused, onActivityPostResumed, onActivityPostSaveInstanceState, onActivityPostStarted, onActivityPostStopped, onActivityPreCreated, onActivityPreDestroyed, onActivityPrePaused, onActivityPreResumed, onActivityPreSaveInstanceState, onActivityPreStarted, onActivityPreStopped, onActivityResumed, onActivitySaveInstanceState, onActivityStarted, onActivityStopped -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getInstance
@NotNull() static AppStartMetrics getInstance()
-
getAppStartType
@NotNull() AppStartMetrics.AppStartType getAppStartType()
-
setAppStartType
void setAppStartType(@NotNull() AppStartMetrics.AppStartType appStartType)
-
setAppLaunchedInForeground
void setAppLaunchedInForeground(boolean appLaunchedInForeground)
-
getSdkInitTimeSpan
@NotNull() TimeSpan getSdkInitTimeSpan()
-
getAppStartProfiler
@Nullable() ITransactionProfiler getAppStartProfiler()
-
setAppStartProfiler
void setAppStartProfiler(@Nullable() ITransactionProfiler appStartProfiler)
-
getAppStartContinuousProfiler
@Nullable() IContinuousProfiler getAppStartContinuousProfiler()
-
setAppStartContinuousProfiler
void setAppStartContinuousProfiler(@Nullable() IContinuousProfiler appStartContinuousProfiler)
-
getAppStartSamplingDecision
@Nullable() TracesSamplingDecision getAppStartSamplingDecision()
-
setAppStartSamplingDecision
void setAppStartSamplingDecision(@Nullable() TracesSamplingDecision appStartSamplingDecision)
-
setHeadlessAppStartListener
void setHeadlessAppStartListener(@Nullable() AppStartMetrics.HeadlessAppStartListener listener)
-
getAppStartTraceId
@Nullable() SentryId getAppStartTraceId()
-
setAppStartTraceId
void setAppStartTraceId(@Nullable() SentryId traceId)
-
getAppStartSentryTraceHeader
@Nullable() String getAppStartSentryTraceHeader()
-
setAppStartSentryTraceHeader
void setAppStartSentryTraceHeader(@Nullable() String appStartSentryTraceHeader)
-
getAppStartBaggageHeader
@Nullable() String getAppStartBaggageHeader()
-
setAppStartBaggageHeader
void setAppStartBaggageHeader(@Nullable() String appStartBaggageHeader)
-
getAppStartEndTime
@Nullable() SentryDate getAppStartEndTime()
-
setAppStartEndTime
void setAppStartEndTime(@Nullable() SentryDate appStartEndTime)
-
setCachedStartInfo
@TestOnly()@ApiStatus.Internal() void setCachedStartInfo(@Nullable() ApplicationStartInfo cachedStartInfo)
-
getAppStartExtension
@NotNull() AppStartExtension getAppStartExtension()
-
getAppStartTimeSpan
@NotNull() TimeSpan getAppStartTimeSpan()
-
createProcessInitSpan
@NotNull() TimeSpan createProcessInitSpan()
-
getApplicationOnCreateTimeSpan
@NotNull() TimeSpan getApplicationOnCreateTimeSpan()
-
getAppStartReason
@Nullable() String getAppStartReason()
The reason the OS started the process, mapped from getReason.Only available on API 35+ (when cachedStartInfo was resolved); returns
{@code null}otherwise or for an unmapped reason.
-
isAppLaunchedInForeground
boolean isAppLaunchedInForeground()
-
getContentProviderOnCreateTimeSpans
@NotNull() List<TimeSpan> getContentProviderOnCreateTimeSpans()
Provides all collected content provider onCreate time spans
-
getActivityLifecycleTimeSpans
@NotNull() List<ActivityLifecycleTimeSpan> getActivityLifecycleTimeSpans()
-
addActivityLifecycleTimeSpans
void addActivityLifecycleTimeSpans(@NotNull() ActivityLifecycleTimeSpan timeSpan)
-
onAppStartSpansSent
void onAppStartSpansSent()
-
shouldSendStartMeasurements
boolean shouldSendStartMeasurements(boolean ignoreForegroundCheck)
-
shouldSendStartMeasurements
boolean shouldSendStartMeasurements()
-
getClassLoadedUptimeMs
long getClassLoadedUptimeMs()
-
getAppStartTimeSpanForHeadless
@NotNull() TimeSpan getAppStartTimeSpanForHeadless()
Returns a valid app start time span, bypassing the foreground check. Tries appStartSpan first,falls back to sdkInitTimeSpan. Used for headless starts where appLaunchedInForeground is false.
-
getAppStartTimeSpanWithFallback
@NotNull() TimeSpan getAppStartTimeSpanWithFallback(@NotNull() SentryAndroidOptions options)
-
canExtendAppStart
boolean canExtendAppStart()
Whether the app start can still be extended: measurements haven't been sent yet, no activityhas been created, and the first frame hasn't been drawn. The foreground check is ignored soheadless app starts (broadcast/service) can also be extended.
-
clear
@TestOnly() void clear()
-
setClassLoadedUptimeMs
@TestOnly()@ApiStatus.Internal() void setClassLoadedUptimeMs(long classLoadedUptimeMs)
-
onApplicationCreate
static void onApplicationCreate(@NotNull() Application application)
Called by instrumentation
- Parameters:
application- The application object where onCreate was called on
-
onApplicationPostCreate
static void onApplicationPostCreate(@NotNull() Application application)
Called by instrumentation
- Parameters:
application- The application object where onCreate was called on
-
registerLifecycleCallbacks
void registerLifecycleCallbacks(@NotNull() Application application)
Register a callback to check if an activity was started after the application was created. Mustbe called from the main thread.
- Parameters:
application- The application object to register the callback to
-
onActivityCreated
void onActivityCreated(@NonNull() Activity activity, @Nullable() Bundle savedInstanceState)
-
onActivityStarted
void onActivityStarted(@NonNull() Activity activity)
-
onActivityResumed
void onActivityResumed(@NonNull() Activity activity)
-
onActivityPaused
void onActivityPaused(@NonNull() Activity activity)
-
onActivityStopped
void onActivityStopped(@NonNull() Activity activity)
-
onActivityDestroyed
void onActivityDestroyed(@NonNull() Activity activity)
-
onContentProviderCreate
static void onContentProviderCreate(@NotNull() ContentProvider contentProvider)
Called by instrumentation
- Parameters:
contentProvider- The content provider where onCreate was called on
-
onContentProviderPostCreate
static void onContentProviderPostCreate(@NotNull() ContentProvider contentProvider)
Called by instrumentation
- Parameters:
contentProvider- The content provider where onCreate was called on
-
-
-
-