Skip to content
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

Merged
merged 15 commits into from Mar 14, 2022

Conversation

stefanosiano
Copy link
Member

@stefanosiano stefanosiano commented Feb 3, 2022

📜 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

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

Add tests (will be added in another pr)

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
AndroidTraceTransactionListener now takes Hub in the constructor (for testability)
…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
moved profilingTracesDirPath and profilingTracesIntervalMillis to SentryAndroidOptions
updated ProfilingTraceData to be the payload of the profiling envelope item
Copy link
Member

@romtsn romtsn left a 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/src/main/java/io/sentry/SentryOptions.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/ITransactionListener.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/SentryEnvelopeItem.java Outdated Show resolved Hide resolved
private final transient @NotNull File traceFile;

// Device metadata
private final int android_api_level;
Copy link
Member

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

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanosiano
Copy link
Member Author

For the serialization, should i rebase this branch to the 6.x.x branch and adapt to the ser/deser used there?

@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2022

Codecov Report

Merging #1897 (7830a25) into feat/profiling/android (4afe30c) will decrease coverage by 0.75%.
The diff coverage is 36.36%.

Impacted file tree graph

@@                     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     
Impacted Files Coverage Δ
sentry/src/main/java/io/sentry/HubAdapter.java 4.91% <0.00%> (-0.09%) ⬇️
sentry/src/main/java/io/sentry/NoOpHub.java 46.34% <ø> (ø)
...ntry/src/main/java/io/sentry/NoOpSentryClient.java 60.00% <ø> (ø)
...main/java/io/sentry/NoOpSentryExecutorService.java 40.00% <0.00%> (-10.00%) ⬇️
...ry/src/main/java/io/sentry/ProfilingTraceData.java 0.00% <0.00%> (ø)
...n/java/io/sentry/transport/ReusableCountLatch.java 88.23% <ø> (ø)
sentry/src/main/java/io/sentry/util/FileUtils.java 0.00% <0.00%> (ø)
sentry/src/main/java/io/sentry/SentryClient.java 84.63% <22.22%> (-1.35%) ⬇️
sentry/src/main/java/io/sentry/Hub.java 74.25% <50.00%> (-0.48%) ⬇️
...c/main/java/io/sentry/NoOpTransactionProfiler.java 50.00% <50.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4afe30c...7830a25. Read the comment docs.

@stefanosiano stefanosiano marked this pull request as ready for review March 7, 2022 11:24
@marandaneto
Copy link
Contributor

For the serialization, should i rebase this branch to the 6.x.x branch and adapt to the ser/deser used there?

I'd rather merge to the feature branch you already have.
Work on tests, etc... so we guarantee that nothing else from the SDK is broken.

@bruno-garcia
Copy link
Member

For the serialization, should i rebase this branch to the 6.x.x branch and adapt to the ser/deser used there?

I'd rather merge to the feature branch you already have. Work on tests, etc... so we guarantee that nothing else from the SDK is broken.

+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).

return null;
}

// The payload of the profiling item is a json that includes the trace file encoded with base64
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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
@stefanosiano
Copy link
Member Author

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
@stefanosiano stefanosiano merged commit 6a53471 into feat/profiling/android Mar 14, 2022
@stefanosiano stefanosiano deleted the feat/profiling/transaction_traces branch March 14, 2022 17:03
@bruno-garcia
Copy link
Member

🥳

@github-actions
Copy link
Contributor

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

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 #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 7d08aca

stefanosiano added a commit that referenced this pull request Mar 31, 2022
* 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
stefanosiano added a commit that referenced this pull request Apr 1, 2022
* 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
stefanosiano added a commit that referenced this pull request Apr 1, 2022
* 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
@bruno-garcia bruno-garcia mentioned this pull request Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants