-
-
Notifications
You must be signed in to change notification settings - Fork 472
Feat: Measure app start time #1487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
341b832
Feat: App start metric
marandaneto e91becd
Update CHANGELOG.md
marandaneto 7c38b2c
draft
marandaneto 13a44ca
add tests
marandaneto f2afe1b
fix
marandaneto 8866ec1
merge
marandaneto 7480dfb
review
marandaneto b526827
Merge branch 'main' into feat/app-start-metric
marandaneto 121876a
timestamp
marandaneto 51751e5
ref
marandaneto a62f437
api dump
marandaneto 4f3001f
comment
marandaneto dd388a8
fix tests
marandaneto 30f0e00
fix
marandaneto b8296ef
fix
marandaneto 2b554bb
fix
marandaneto 82f9d2f
format
marandaneto a94e30f
fix
marandaneto 137db33
tests
marandaneto 51297b5
ui load op for ui transactions
marandaneto 65f8a0d
fix
marandaneto b1a88c3
fix
marandaneto c43cb3e
rename span ops
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
sentry-android-core/src/main/java/io/sentry/android/core/AppStartState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package io.sentry.android.core; | ||
|
|
||
| import android.os.SystemClock; | ||
| import java.util.Date; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.jetbrains.annotations.TestOnly; | ||
|
|
||
| /** AppStartState holds the state of the App Start metric and appStartTime */ | ||
| final class AppStartState { | ||
|
|
||
| private static @NotNull AppStartState instance = new AppStartState(); | ||
|
|
||
| private @Nullable Long appStartMillis; | ||
|
|
||
| private @Nullable Long appStartEndMillis; | ||
|
|
||
| /** The type of App start coldStart=true -> Cold start, coldStart=false -> Warm start */ | ||
| private boolean coldStart; | ||
|
|
||
| /** appStart as a Date used in the App's Context */ | ||
| private @Nullable Date appStartTime; | ||
|
marandaneto marked this conversation as resolved.
|
||
|
|
||
| private AppStartState() {} | ||
|
|
||
| static @NotNull AppStartState getInstance() { | ||
| return instance; | ||
| } | ||
|
|
||
| @TestOnly | ||
| void resetInstance() { | ||
| instance = new AppStartState(); | ||
| } | ||
|
|
||
| synchronized void setAppStartEnd() { | ||
| setAppStartEnd(SystemClock.uptimeMillis()); | ||
| } | ||
|
|
||
| @TestOnly | ||
| void setAppStartEnd(final long appStartEndMillis) { | ||
| this.appStartEndMillis = appStartEndMillis; | ||
| } | ||
|
|
||
| @Nullable | ||
| synchronized Long getAppStartInterval() { | ||
| if (appStartMillis == null || appStartEndMillis == null) { | ||
| return null; | ||
| } | ||
| return appStartEndMillis - appStartMillis; | ||
| } | ||
|
|
||
| boolean isColdStart() { | ||
| return coldStart; | ||
| } | ||
|
|
||
| synchronized void setColdStart(final boolean coldStart) { | ||
| this.coldStart = coldStart; | ||
| } | ||
|
|
||
| @Nullable | ||
| Date getAppStartTime() { | ||
| return appStartTime; | ||
| } | ||
|
|
||
| synchronized void setAppStartTime(final long appStartMillis, final @NotNull Date appStartTime) { | ||
| // method is synchronized because the SDK may by init. on a background thread. | ||
|
marandaneto marked this conversation as resolved.
|
||
| if (this.appStartTime != null && this.appStartMillis != null) { | ||
| return; | ||
| } | ||
| this.appStartTime = appStartTime; | ||
| this.appStartMillis = appStartMillis; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...y-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package io.sentry.android.core; | ||
|
|
||
| import static io.sentry.android.core.ActivityLifecycleIntegration.APP_START_COLD; | ||
| import static io.sentry.android.core.ActivityLifecycleIntegration.APP_START_WARM; | ||
|
|
||
| import io.sentry.EventProcessor; | ||
| import io.sentry.protocol.MeasurementValue; | ||
| import io.sentry.protocol.SentrySpan; | ||
| import io.sentry.protocol.SentryTransaction; | ||
| import java.util.List; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** Event Processor responsible for adding Android metrics to transactions */ | ||
| final class PerformanceAndroidEventProcessor implements EventProcessor { | ||
|
|
||
| private final boolean tracingEnabled; | ||
|
|
||
| private boolean sentStartMeasurement = false; | ||
|
|
||
| PerformanceAndroidEventProcessor(final @NotNull SentryAndroidOptions options) { | ||
| tracingEnabled = options.isTracingEnabled(); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized @NotNull SentryTransaction process( | ||
| @NotNull SentryTransaction transaction, @Nullable Object hint) { | ||
| // the app start measurement is only sent once and only if the transaction has | ||
| // the app.start span, which is automatically created by the SDK. | ||
| if (!sentStartMeasurement && tracingEnabled && hasAppStartSpan(transaction.getSpans())) { | ||
| final Long appStartUpInterval = AppStartState.getInstance().getAppStartInterval(); | ||
| // if appStartUpInterval is null, metrics are not ready to be sent | ||
| if (appStartUpInterval != null) { | ||
| final MeasurementValue value = new MeasurementValue((float) appStartUpInterval); | ||
|
|
||
| final String appStartKey = | ||
| AppStartState.getInstance().isColdStart() ? "app_start_cold" : "app_start_warm"; | ||
|
|
||
| transaction.getMeasurements().put(appStartKey, value); | ||
| sentStartMeasurement = true; | ||
| } | ||
| } | ||
|
|
||
| return transaction; | ||
| } | ||
|
|
||
| private boolean hasAppStartSpan(final @NotNull List<SentrySpan> spans) { | ||
| for (final SentrySpan span : spans) { | ||
| if (span.getOp().contentEquals(APP_START_COLD) | ||
| || span.getOp().contentEquals(APP_START_WARM)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.