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 transaction sampling properties to SentryOptions #961

Merged
merged 12 commits into from
Mar 2, 2021

Conversation

brustolin
Copy link
Contributor

@brustolin brustolin commented Feb 25, 2021

📜 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

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

🔮 Next steps

Apply transaction sampling rules on SentryHub startTransaction.

@philipphofmann philipphofmann changed the title feat: Add transaction sampling options to SentrySDK. feat: Add transaction sampling properties to SentryOptions Feb 25, 2021
Copy link
Member

@philipphofmann philipphofmann left a 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 😀

Sources/Sentry/SentryTransactionSamplingContext.m Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryOptions.h Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryOptions.h Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryTransactionSamplingContext.h Outdated Show resolved Hide resolved
@@ -148,6 +156,21 @@ NS_SWIFT_NAME(Options)
*/
@property (nonatomic, assign) BOOL sendDefaultPii;

/**
* Indicates the percentage of the tracing data that is collected.
Copy link
Member

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.

Copy link
Member

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:

https://github.com/getsentry/sentry-java/blob/4620134a84de5e8a10a2811392f31941a10059cc/sentry/src/main/java/io/sentry/SentryOptions.java#L146

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.

Copy link
Contributor Author

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.

Copy link
Member

@bruno-garcia bruno-garcia Feb 26, 2021

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

wfm

Copy link
Contributor

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

Copy link
Member

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.

Sources/Sentry/Public/SentryTransactionSamplingContext.h Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryTransactionSamplingContext.h Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryTransactionSamplingContext.h Outdated Show resolved Hide resolved
Sources/Sentry/SentryOptions.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryOptions.m Show resolved Hide resolved
Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

brustolin and others added 3 commits February 26, 2021 08:04
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@philipphofmann philipphofmann left a 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.

Sources/Sentry/SentryOptions.m Outdated Show resolved Hide resolved
Copy link
Contributor

@marandaneto marandaneto left a 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

@brustolin brustolin merged commit 088280c into feat/performance-monitoring Mar 2, 2021
@brustolin brustolin deleted the feat/transaction-sampling branch March 2, 2021 21:57
@bruno-garcia
Copy link
Member

🥳 🥳 🥳 🥳 🥳

bruno-garcia added a commit that referenced this pull request Mar 11, 2021
* 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>
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

6 participants