-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Feature: Android profiling traces #1897
Feature: Android profiling traces #1897
Conversation
added a transaction listener (noOp on java sdk) that starts/stops android profiling when a transaction starts or is finished added an envelope generation method from android trace file added following SentryOptions: profilingTracesDirPath, profilingEnabled, maxTraceFileSize, profilingTracesIntervalMs, transactionListener
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
AndroidTraceTransactionListener now takes Hub in the constructor (for testability)
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
…e schedule() method ITransactionListener.onTransactionFinish() now returns a ProfilingTraceData, used to add the item to the transaction's envelope added io.sentry.traces.profiling-enable to manifest options profiling is now enabled by default
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
moved profilingTracesDirPath and profilingTracesIntervalMillis to SentryAndroidOptions updated ProfilingTraceData to be the payload of the profiling envelope item
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.
Some minor things, but LGTM 🚀
The tests are still missing, are you going to add them? Also, the PR is targeting main
, I think I'd rather target some integration branch for now, if you want to add more stuff (like tests) in other PRs.
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java
Outdated
Show resolved
Hide resolved
private final transient @NotNull File traceFile; | ||
|
||
// Device metadata | ||
private final int android_api_level; |
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.
hm, I feel like checkstyle/spotless would yell here, because we should use camelCase
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.
I ran it, but it didn't care at all. If we get rid of Gson then i can create a custom method that creates a json and use camelCase names for the variables
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.
We got rid of Gson on Java v6 https://github.com/getsentry/sentry-java/tree/6.x.x
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTraceTransactionListener.java
Outdated
Show resolved
Hide resolved
For the serialization, should i rebase this branch to the 6.x.x branch and adapt to the ser/deser used there? |
Codecov Report
@@ Coverage Diff @@
## feat/profiling/android #1897 +/- ##
============================================================
- Coverage 75.46% 74.70% -0.76%
- Complexity 2248 2260 +12
============================================================
Files 225 228 +3
Lines 8036 8145 +109
Branches 851 867 +16
============================================================
+ Hits 6064 6085 +21
- Misses 1562 1646 +84
- Partials 410 414 +4
Continue to review full report at Codecov.
|
I'd rather merge to the feature branch you already have. |
+1 on merging first. Wrt 6.0 perhaps we need a bigger discussion and commitment from folks and set a timeline (making sure it doesn't negatively affect tracing's goals). |
sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java
Outdated
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java
Outdated
Show resolved
Hide resolved
return null; | ||
} | ||
|
||
// The payload of the profiling item is a json that includes the trace file encoded with base64 |
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.
Usually, base64 is 1/3 bigger, is there a reason to do so? Envelopes are able to send binary format.
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.
We agreed with @phacops, our backend guy, that will expect a base64 string.
Also, the payload of the profile envelope is a json, so a string is a natural fit
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.
I see, since it's a file, I was expecting to be an attachment that could be sent in bytes.
Reading the code now I understand, the envelope type is profile
, which is a JSON of the ProfilingTraceData
class, that contains a stacktrace
field, and this field has the profiling file content in base64.
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.
yep
…, instead of deleting the whole dir and recreating it in the main thread AndroidTransactionProfiler now takes a buildInfoProvider in ctor profile envelope item now uses a CachedItem to read the trace file in the background
…, instead of deleting the whole dir and recreating it in the main thread AndroidTransactionProfiler now takes a buildInfoProvider in ctor profile envelope item now uses a CachedItem to read the trace file in the background
-device_is_emulator -device_cpu_frequencies -device_physical_memory_bytes -duration_ns added context to AndroidTransactionProfiler instead of packageInfo to retrieve memory info added isEmulator() to BuildInfoProvider
I had to add few fields for the profiling envelope, so i made a few changes, but these should be the last one! |
-stacktrace -> sampled_profile -stacktrace_id -> profile_id
-stacktrace -> sampled_profile -stacktrace_id -> profile_id
🥳 |
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
- Android profiling traces ([#1897](https://github.com/getsentry/sentry-java/pull/1897)) If none of the above apply, you can opt out of this check by adding |
* Added a transaction profiler (noOp on java sdk) that starts/stops android profiling when a transaction starts or is finished * Added a new envelope item type "profile", generated using android trace file. Its payload is a json represented by ProfilingTraceData * SentryExecutorService now uses a ScheduledExecutorService to allow the schedule() method * Added "profilingTracesDirPath" and "profilingTracesIntervalMillis" to SentryAndroidOptions * Added "profilingEnabled", "maxTraceFileSize" and "transactionProfiler" to SentryOptions * Added io.sentry.traces.profiling.enable to manifest options * Profiling is disabled by default * Profiling traces directory's content is deleted in the background when the options are initialized
* Added a transaction profiler (noOp on java sdk) that starts/stops android profiling when a transaction starts or is finished * Added a new envelope item type "profile", generated using android trace file. Its payload is a json represented by ProfilingTraceData * SentryExecutorService now uses a ScheduledExecutorService to allow the schedule() method * Added "profilingTracesDirPath" and "profilingTracesIntervalMillis" to SentryAndroidOptions * Added "profilingEnabled", "maxTraceFileSize" and "transactionProfiler" to SentryOptions * Added io.sentry.traces.profiling.enable to manifest options * Profiling is disabled by default * Profiling traces directory's content is deleted in the background when the options are initialized
* Added a transaction profiler (noOp on java sdk) that starts/stops android profiling when a transaction starts or is finished * Added a new envelope item type "profile", generated using android trace file. Its payload is a json represented by ProfilingTraceData * SentryExecutorService now uses a ScheduledExecutorService to allow the schedule() method * Added "profilingTracesDirPath" and "profilingTracesIntervalMillis" to SentryAndroidOptions * Added "profilingEnabled", "maxTraceFileSize" and "transactionProfiler" to SentryOptions * Added io.sentry.traces.profiling.enable to manifest options * Profiling is disabled by default * Profiling traces directory's content is deleted in the background when the options are initialized
📜 Description
adds Android profiling whenever a transaction starts
adds a new envelope generation method to send profiling data
Bind traces to transactions
Ignore profiling for other transactions when they run at the same time
💡 Motivation and Context
We are integrating the Specto features in the Sentry sdk. This pr adds support for profiling Android methods whenever a sentry transaction is started
📝 Checklist
🔮 Next steps
Add tests (will be added in another pr)