-
-
Notifications
You must be signed in to change notification settings - Fork 313
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 transaction sampling properties to SentryOptions #961
feat: Add transaction sampling properties to SentryOptions #961
Conversation
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 think there are still some discrepancies to the other SDKs in the API, but maybe these are wanted. Anyway, I added comments for all of them. If I'm wrong, just let me know. The code in general looks good. Tests are still missing, but I guess you are going to add them soon 😀
@@ -148,6 +156,21 @@ NS_SWIFT_NAME(Options) | |||
*/ | |||
@property (nonatomic, assign) BOOL sendDefaultPii; | |||
|
|||
/** | |||
* Indicates the percentage of the tracing data that is collected. |
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.
m
: Can we mention that the default value is 1.0. I actually prefer making this nonnull, as the default can be 1.0.
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.
The default shouldn't be 1.0 though. It's 0.
Default is null
so we can know if the user has defined a value explicilty. This discussion happened already in other SDKs and this value is nullable in Java:
Seems this is different in .NET which is non-nullable:
https://github.com/getsentry/sentry-dotnet/blob/06712edbe7100eb900676ea5a9b4473584d1c717/src/Sentry/SentryOptions.cs#L396-L403
Again this idea of setting such setting nullable is that it allow knowing if the user has configured it via the init
callback explicitly, or if not, we can bind the value from a configuration file or some integration.
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.
@bruno-garcia, objc doesn't have nullable primitives. Another discussion is required to solve this.
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.
Take the .NET approach then, we had discussions there.
IIRC: We use the tracerSamplingCallback first if it exists, if that returns null (it must be able to return nullable there btw!) or if it doesn't exist (the callback is null on the options) it falls back to the random sampling.
/cc @marandaneto @Tyrrrz
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.
Well, I can try to use the callback first if it's not null, but the same problem applies here, I can't have a callback that returns nullable double, so if the user decides to use a callback it will have to decide the sampling in the callback.
We have an alternative option to use NSNumber instead of double, which is nullable. But then in Swift will be NSNumber as well, which in some cases doesn't have an automatically bridge to/from double.
I don't like the idea of using this objc classes in Swift, some new developers are not used to these classes.
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 like the option @marandaneto proposed unless you @brustolin think this is weird for Swift users.
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.
After a lot of consideration, I realized that sampleRate is already NSNumber, so the SDK user already must deal with this kind of field.
Let's throw another one and make use of the null capability.
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.
wfm
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.
unresolving so I link copy-paste the comment link, but ignore my comment
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.
so we can know if the user has defined a value explicilty
@bruno-garcia if they are still accessible, can you link to the discussions you mentioned that cover this point? I couldn't find any discussion of this in the Java PR you linked. I see no reason the SDK should behave differently whether a customer explicitly sets the sample rate to 0, vs never having set it at all, which would leave it at the default, which is also 0. At least, I see nowhere in the SDK that cares about the difference, or that we ever report whether or not it's explicitly set to the backend.
The fact that -[nil doubleValue]
resolves to 0
is an implementation detail we should not rely on. It also obscures the intention of the design in our code. nil
should be reserved for something that's unknowable at an API interface, like if we need to retrieve it from a network call or file, but those tasks fail, in which case we'd have to pick a default fallback value anyways, which would be 0 here.
Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
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.
Next up we need to use these sample rates.
Some ideas for tests:
https://github.com/getsentry/sentry-dotnet/blob/cee8cc337cec426373c44521c4421e93d4b5c108/test/Sentry.Tests/HubTests.cs#L189-L432
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
…try/sentry-cocoa into feat/transaction-sampling
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.
LGTM
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.
Just two things to resolve. Apart from that, we are good.
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.
other than the open comments, LGTM
🥳 🥳 🥳 🥳 🥳 |
* feat: performance monitoring * build: Setup CI for performance monitoring branch * feat: Performance API: Transaction (#908) Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Clang Robot <clang-robot@sentry.io> Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> * test: Add captureTransaction to sample apps (#922) * docs: Improve code comments on transactions (#921) Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> * feat: Add missing properties to SpanContext and Transaction (#919) Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> * feat: Adding SentrySpan to performance monitoring. (#932) Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Clang Robot <clang-robot@sentry.io> * ref: Remove SentryTransaction from public API. (#950) Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> * feat: Add transaction sampling properties to SentryOptions (#961) * Transaction sampling * Update CHANGELOG.md * Format code * Apply suggestions from code review Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> * Testing and fixes * Using NSNumber for sampler return * Update CHANGELOG.md Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> * Comment Update * Using NSNumber for tracesSampleRate Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> * feat: Transaction in Sample App (#971) * Some UI Sample * Format code * Apply suggestions from code review Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> * removing button to download image * Adding status and fixing operation value * Fixed Tests Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> * merge fix * feat: Add sampling rules to SentryHub startTransaction. (#977) * Changing sampled from bool to enum, using TracesSampler * removing name from span * SamplingTests * changelog and code format * Lint Fix * Fix tests * Update Samples/iOS-Swift/iOS-Swift/TraceTestViewController.swift Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> * Random generator for sampling * missing comment * remove sampler from SentryHub+TestInit.h * Apply suggestions from code review Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Bruno Garcia <bruno@brunogarcia.com> Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> * meta: Add missing breaking change to Changelog * performance changelog Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io> Co-authored-by: Dhiogo Brustolin <dhiogorb@gmail.com> Co-authored-by: Clang Robot <clang-robot@sentry.io> Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
📜 Description
Added tracesSampleRate and tracesSampler to SentryOptions
💡 Motivation and Context
Options required to determine sampling of transactions.
💚 How did you test it?
No new behavior added.
📝 Checklist
🔮 Next steps
Apply transaction sampling rules on SentryHub startTransaction.