-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
Extract Activity Breadcrumbs generation into own Integration #3064
Merged
Merged
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d59ca3f
Attach app-start spans
markushi 4232431
Merge branch 'main' into feat/app-start-spans
markushi 69aca74
Update Changelog
markushi e856b81
Fix tests
markushi 1de2330
Extract Activity Breadcrumbs into own integration
markushi 0c2d3d3
Update changelog
markushi aea2a36
Implement PR feedback
markushi fe3586d
Merge branch 'main' into feat/app-start-spans
markushi 80ec3f2
Fix merge
markushi 1a0fcee
Address PR feedback, improve tests
markushi dd32cf3
Merge branch 'main' into feat/app-start-spans
markushi 1141aed
Update Changelog
markushi 1408c76
Merge branch 'feat/app-start-spans' into feat/activity-lifecycle-brea…
markushi 1a66cce
Implement PR feedback
markushi d43311a
Rename starfish to performance-v2
markushi 3257c66
Address PR feedback
markushi a93402a
Address PR feedback
markushi ee245e7
Merge branch 'main' into feat/app-start-spans
markushi b8a1b57
[Starfish] Attach app start spans to app.start.cold txn (#3067)
markushi 5d7b99b
Merge branch 'feat/app-start-spans' into feat/activity-lifecycle-brea…
markushi 59f2b2d
Fix copy/pasta
markushi 4077bae
Merge branch 'main' into feat/activity-lifecycle-breadcrumbs
markushi 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 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 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
125 changes: 125 additions & 0 deletions
125
sentry-android-core/src/main/java/io/sentry/android/core/ActivityBreadcrumbsIntegration.java
This file contains 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,125 @@ | ||
package io.sentry.android.core; | ||
|
||
import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY; | ||
import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.os.Bundle; | ||
import io.sentry.Breadcrumb; | ||
import io.sentry.Hint; | ||
import io.sentry.IHub; | ||
import io.sentry.Integration; | ||
import io.sentry.SentryLevel; | ||
import io.sentry.SentryOptions; | ||
import io.sentry.util.Objects; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** Automatically adds breadcrumbs for Activity Lifecycle Events. */ | ||
public final class ActivityBreadcrumbsIntegration | ||
implements Integration, Closeable, Application.ActivityLifecycleCallbacks { | ||
|
||
private final @NotNull Application application; | ||
private @Nullable IHub hub; | ||
private boolean enabled; | ||
|
||
public ActivityBreadcrumbsIntegration(final @NotNull Application application) { | ||
this.application = Objects.requireNonNull(application, "Application is required"); | ||
} | ||
|
||
@Override | ||
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) { | ||
final SentryAndroidOptions androidOptions = | ||
Objects.requireNonNull( | ||
(options instanceof SentryAndroidOptions) ? (SentryAndroidOptions) options : null, | ||
"SentryAndroidOptions is required"); | ||
|
||
this.hub = Objects.requireNonNull(hub, "Hub is required"); | ||
this.enabled = androidOptions.isEnableActivityLifecycleBreadcrumbs(); | ||
options | ||
.getLogger() | ||
.log(SentryLevel.DEBUG, "ActivityBreadcrumbsIntegration enabled: %s", enabled); | ||
|
||
if (enabled) { | ||
application.registerActivityLifecycleCallbacks(this); | ||
options.getLogger().log(SentryLevel.DEBUG, "ActivityBreadcrumbIntegration installed."); | ||
addIntegrationToSdkVersion(getClass()); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (enabled) { | ||
application.unregisterActivityLifecycleCallbacks(this); | ||
if (hub != null) { | ||
hub.getOptions() | ||
.getLogger() | ||
.log(SentryLevel.DEBUG, "ActivityBreadcrumbsIntegration removed."); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void onActivityCreated( | ||
final @NotNull Activity activity, final @Nullable Bundle savedInstanceState) { | ||
addBreadcrumb(activity, "created"); | ||
} | ||
|
||
@Override | ||
public synchronized void onActivityStarted(final @NotNull Activity activity) { | ||
addBreadcrumb(activity, "started"); | ||
} | ||
|
||
@SuppressLint("NewApi") | ||
@Override | ||
public synchronized void onActivityResumed(final @NotNull Activity activity) { | ||
addBreadcrumb(activity, "resumed"); | ||
} | ||
|
||
@Override | ||
public synchronized void onActivityPaused(final @NotNull Activity activity) { | ||
addBreadcrumb(activity, "paused"); | ||
} | ||
|
||
@Override | ||
public synchronized void onActivityStopped(final @NotNull Activity activity) { | ||
addBreadcrumb(activity, "stopped"); | ||
} | ||
|
||
@Override | ||
public synchronized void onActivitySaveInstanceState( | ||
final @NotNull Activity activity, final @NotNull Bundle outState) { | ||
addBreadcrumb(activity, "saveInstanceState"); | ||
} | ||
|
||
@Override | ||
public synchronized void onActivityDestroyed(final @NotNull Activity activity) { | ||
addBreadcrumb(activity, "destroyed"); | ||
} | ||
|
||
private void addBreadcrumb(final @NotNull Activity activity, final @NotNull String state) { | ||
if (hub == null) { | ||
return; | ||
} | ||
|
||
final Breadcrumb breadcrumb = new Breadcrumb(); | ||
breadcrumb.setType("navigation"); | ||
breadcrumb.setData("state", state); | ||
breadcrumb.setData("screen", getActivityName(activity)); | ||
breadcrumb.setCategory("ui.lifecycle"); | ||
breadcrumb.setLevel(SentryLevel.INFO); | ||
|
||
final Hint hint = new Hint(); | ||
hint.set(ANDROID_ACTIVITY, activity); | ||
|
||
hub.addBreadcrumb(breadcrumb, hint); | ||
} | ||
|
||
private @NotNull String getActivityName(final @NotNull Activity activity) { | ||
return activity.getClass().getSimpleName(); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably copy-pasta?