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

feat: Add sampling configuration for profiling #2004

Merged
merged 25 commits into from Jul 27, 2022

Conversation

indragiek
Copy link
Member

📜 Description

Adds two new configuration options, profilesSampleRate and profilesSampler to mirror tracesSampleRate and tracesSampler, except for profiling data.

There are no breaking changes -- enableProfiling is now deprecated, but will continue to work for existing clients that use it (this is equivalent to setting profilesSampleRate to 1.0)

💡 Motivation and Context

Currently our only control for how profiles get sampled is the transaction sampling - we always collect a profile for every sampled transaction. However, since profiles are quite a bit larger than transactions, we likely will want to undersample them relative to transactions for high data volumes. Effectively, these parameters control *for what percentage of sampled transactions do we collect a profile"

There is more info on the design of this parameter here, which we will adopt across other SDKs that support profiling as well: https://www.notion.so/sentry/Profiles-Sample-Rate-9ef72666b5af487d94cf314cc81e88c6

💚 How did you test it?

New unit tests.

📝 Checklist

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

🔮 Next steps

@github-actions
Copy link

github-actions bot commented Jul 25, 2022

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

Generated by 🚫 dangerJS against 0ddcebd

@indragiek
Copy link
Member Author

CI flakes appear to be unrelated to these changes. I'm working on a separate change to fix the flakiness of the "Generate Profiling Test Data" action, it seems to fail very regularly.

Comment on lines -271 to -277
options.tracesSampler = { _ in return 0.49 }
options.tracesSampleRate = 0.49
}
}

func testStartTransactionSamplingUsingSampleRate() {
testSampler(expected: .yes) { options in
options.tracesSampler = { _ in return 0.5 }
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests are unrelated to my changes but I fixed these to set the tracesSampleRate as the name of the test suggests, instead of the sampler function.

Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

Code looks good to me.
I think you just need to take a look in the fail actions in CI other than UI tests.

@indragiek
Copy link
Member Author

All CI is passing except the profiling jobs which we know are flaking (@armcknight is working on improving those).

@indragiek indragiek merged commit 643eab8 into master Jul 27, 2022
@indragiek indragiek deleted the indragiek/profiles-sample-rate branch July 27, 2022 17:00
kevinrenskers added a commit that referenced this pull request Aug 1, 2022
* master:
  ci: benchmarking and profile generation improvements (#2022)
  release: 7.23.0
  fix: Bad merge on CHANGELOG.md (#2020)
  fix: Log empty samples instead of collecting stacks for idle threads (#2013)
  fix: Handle failure to read thread priority gracefully (#2015)
  fix: Remove logging that could occur while a thread is suspended (#2014)
  fix: Use constant for max thread name size instead of magic number (#2012)
  Disable flaky tesDefaultMaxEnvelopesConcurrent (#2018)
  Fix build failure in unit tests (#2019)
  Fix address sanitizer compilation error (#1996)
  fix: Sauce labs iPhone 13 pro iOS version
  feat: Add transaction to baggage and trace headers (#1992)
  ci: fix ui thread starvation in benchmarks (#2009)
  fix: Add more descriptive deprecation message for enableProfiling (#2011)
  feat: Add sampling configuration for profiling (#2004)
  fix log message option name (#2006)
  meta: add armcknight as a codeowner (#2008)
  release: 7.22.0
  fix: Disable broken LaunchUITests to unblock release (#2003)

# Conflicts:
#	Samples/iOS-Swift/iOS-Swift/ViewControllers/PerformanceViewController.swift
Comment on lines +399 to +400
testProfilesSampler(expected: .yes) { options in
options.profilesSampler = { _ in return 0.51 }
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand how some of these tests work. With a 0.51 sample rate, this should fail 49% of the time. Is something else getting mocked to make this always work? Same for a few others with a rate that's not 0.0 or 1.0.

Copy link
Member

Choose a reason for hiding this comment

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

The tests don't use a random value. The random value is fixed see

let hub = fixture.getSut()
Dynamic(hub).tracesSampler.random = TestRandom(value: 1.0)
Dynamic(hub).profilesSampler.random = TestRandom(value: 0.5)

Copy link
Member

Choose a reason for hiding this comment

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

OK, after reading SentryProfilesSampler's implementation I see how this works now, thanks.

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