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

Startup Profiling 2 - Add options and sampling logic #3121

Conversation

stefanosiano
Copy link
Member

@stefanosiano stefanosiano commented Dec 29, 2023

📜 Description

followup of #3101
added SentryStartupProfilingOptions class with Json ser/deser
added startupProfilingConfigFile deletion and creation on init
added sampling decision on SDK init with isForNextStartup flag set to true
added SentryOptions.getCacheDirPathWithoutDsn for startupProfiling config file

Here is the decision tree.
The only missing part is actually starting the profiler and bind it to the first transaction, which will come in the next PR.
Note: the auto instrumentation flag is available on SentryAndroidOptions, so it will be evaluated (in the next PR) before starting the startup profiler
photo_2023-12-15 14 57 18

💡 Motivation and Context

For the startup profiling feature, we need to add an option to enable it and we also need to respect the sampling decisions of the user.
Then, we need to save this info to disk, as the startup profiler will not have access to the SentryOptions object, as it will start before the SDK is initialized.

💚 How did you test it?

Unit tests

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

added SentryOptions.enableStartupProfiling
added startupProfilingConfigFile deletion and creation on init
added sampling decision on SDK init with isForNextStartup flag set to true
added SentryOptions.getCacheDirPathWithoutDsn for startupProfiling config file
…to feat/startup-profiling2-add-options

# Conflicts:
#	sentry/src/main/java/io/sentry/SentryOptions.java
#	sentry/src/test/java/io/sentry/SentryOptionsTest.kt
#	sentry/src/test/java/io/sentry/SentryTest.kt
@stefanosiano stefanosiano marked this pull request as ready for review December 29, 2023 10:14
Copy link
Contributor

github-actions bot commented Dec 29, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 4aa19d2

Copy link
Contributor

github-actions bot commented Dec 29, 2023

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 379.72 ms 457.96 ms 78.24 ms
Size 1.70 MiB 2.27 MiB 584.06 KiB

Baseline results on branch: feat/early-profiling1-decouple-profiler-transaction

Startup times

Revision Plain With Sentry Diff
e42754c 382.06 ms 465.49 ms 83.43 ms
604628a 389.84 ms 456.78 ms 66.94 ms
1da0e4d 375.46 ms 448.53 ms 73.07 ms

App size

Revision Plain With Sentry Diff
e42754c 1.72 MiB 2.27 MiB 557.10 KiB
604628a 1.72 MiB 2.27 MiB 558.57 KiB
1da0e4d 1.72 MiB 2.27 MiB 558.36 KiB

Previous results on branch: feat/startup-profiling2-add-options

Startup times

Revision Plain With Sentry Diff
f19450a 394.36 ms 473.10 ms 78.74 ms
47df090 386.30 ms 467.52 ms 81.22 ms

App size

Revision Plain With Sentry Diff
f19450a 1.70 MiB 2.27 MiB 583.38 KiB
47df090 1.72 MiB 2.27 MiB 561.22 KiB


final class SentryStartupProfilingOptions implements JsonUnknown, JsonSerializable {

boolean profileSampled;
Copy link
Member

Choose a reason for hiding this comment

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

should these be final?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, as these are read and deserialized from json (L100)

sampleStartupProfiling(options);
final @NotNull SentryStartupProfilingOptions startupProfilingOptions =
new SentryStartupProfilingOptions(options, startupSamplingDecision);
try (Writer fileWriter = new SentryFileWriter(startupProfilingConfigFile)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try (Writer fileWriter = new SentryFileWriter(startupProfilingConfigFile)) {
try (Writer fileWriter = new FileWriter(startupProfilingConfigFile)) {

SentryFileWriter is specific for performance instrumentation, I guess we don't want to create spans for our own file operations :)

Copy link
Member

Choose a reason for hiding this comment

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

Also, let's use FileOutputStream maybe, to align with all other places where we write to a file?

CHANGELOG.md Outdated
@@ -6,6 +6,7 @@

- Handle `monitor`/`check_in` in client reports and rate limiter ([#3096](https://github.com/getsentry/sentry-java/pull/3096))
- Startup profiling 1 - Decouple Profiler from Transaction ([#3101](https://github.com/getsentry/sentry-java/pull/3101))
- Startup profiling 2 - Add options and sampling logic ([#3121](https://github.com/getsentry/sentry-java/pull/3121))
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in the other PR, maybe let's squash these changelogs into one?

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.

A few points, but LGTM otherwise

used FileOutputStream instead for FileWriter
* first activity transaction now inherits startup sampling decision, if available
* if a startup profiler was instantiated, it will be reused in AndroidOptionsInitializer, instead of creating a new one
* added ITransactionProfiler.isRunning
* startup profiler and sampling decision is stored in AppStartMetrics
* startup profile is bound to the startup transaction
* added io.sentry.profiling.enable-startup manifest option
* moved profilingTracesHz from SentryAndroidOptions to SentryOptions
* added startup profiling launch in SentryPerformanceProvider
* added isStartupTransaction to TransactionOptions
@stefanosiano
Copy link
Member Author

@romtsn may you have a last look here and here, as well, before merging? 😄

@romtsn
Copy link
Member

romtsn commented Jan 15, 2024

@romtsn may you have a last look here and here, as well, before merging? 😄

yeah looks great, thanks for the thorough changelog!

@stefanosiano stefanosiano merged commit 02f6aa7 into feat/early-profiling1-decouple-profiler-transaction Jan 15, 2024
15 checks passed
@stefanosiano stefanosiano deleted the feat/startup-profiling2-add-options branch January 15, 2024 12:07
stefanosiano added a commit that referenced this pull request Jan 15, 2024
* Startup Profiling 1 - Decouple Profiler from Transaction (#3101)
* removed the need of a transaction to start a profile in AndroidTransactionProfiler, allowing to bind one later
* added a constructor to AndroidTransactionProfiler without options
* added options as param to AndroidTransactionProfiler.onTransactionFinish

* Startup Profiling 2 - Add options and sampling logic (#3121)
* added TransactionContext.isForNextStartup
* added SentryOptions.enableStartupProfiling
* added SentryStartupProfilingOptions class with Json ser/deser
* added startupProfilingConfigFile deletion and creation on init
* added sampling decision on SDK init with isForNextStartup flag set to true
* added SentryOptions.getCacheDirPathWithoutDsn for startupProfiling config file

* Startup Profiling 3 - Add ContentProvider and start profile (#3128)
* first activity transaction now inherits startup sampling decision, if available
* if a startup profiler was instantiated, it will be reused in AndroidOptionsInitializer, instead of creating a new one
* added ITransactionProfiler.isRunning
* startup profiler and sampling decision is stored in AppStartMetrics
* startup profile is bound to the startup transaction
* added io.sentry.profiling.enable-startup manifest option
* moved profilingTracesHz from SentryAndroidOptions to SentryOptions
* added startup profiling launch in SentryPerformanceProvider
* added isStartupTransaction to TransactionOptions
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.

2 participants