You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most event capture will use the sampling rate for the client, however there are some events we consider high priority we want to always send. This would require a user defined function that allows use to set something on the event that we could check for by-passing the sampling rate.
Solution Brainstorm
Add a user defined function to ClientOptions that receives an event and checks if it qualifies for ignoring the configured sampling rate.
Have prepare_event check for user defined sampling override and check if sampling rate should be ignored.
Rather than adding a function that returns a boolean to fully ignore the sample rate, I would suggest we instead add support for an error_sampler function, like we have in the Python SDK, which returns a floating-point value instead of a boolean. That version allows sampling different events at different sample rates, in addition to supporting your use case.
However, as adding fields to the ClientOptions is a breaking change, we will need to carefully consider if/when we should make this change.
Rather than adding a function that returns a boolean to fully ignore the sample rate, I would suggest we instead add support for an error_sampler function, like we have in the Python SDK, which returns a floating-point value instead of a boolean. That version allows sampling different events at different sample rates, in addition to supporting your use case.
This may be ok, in the sense if no user defined sampling rate override function is provided it falls back to the default behavior.
@darrell-roberts the problem is that the ClientOptions struct is a pub struct with all pub fields. Even though most users will likely construct ClientOptions by setting a few fields manually then having ..Default::default fill in the rest, it is still possible to exhaustively construct and/or to exhaustively match against the ClientOptions struct. As adding a field will break code which exhaustively constructs or matches the struct, it is a breaking change.
At some point, I would like to refractor ClientOptions so that we can add functionality in a non-breaking manner, but this itself will be a disruptive breaking change, as it would require fundamentally changing the API. So that will only happen after careful consideration.
This may be ok, in the sense if no user defined sampling rate override function is provided it falls back to the default behavior.
@darrell-roberts the problem is that the ClientOptions struct is a pub struct with all pub fields. Even though most users will likely construct ClientOptions by setting a few fields manually then having ..Default::default fill in the rest, it is still possible to exhaustively construct and/or to exhaustively match against the ClientOptions struct. As adding a field will break code which exhaustively constructs or matches the struct, it is a breaking change.
At some point, I would like to refractor ClientOptions so that we can add functionality in a non-breaking manner, but this itself will be a disruptive breaking change, as it would require fundamentally changing the API. So that will only happen after careful consideration.
@darrell-roberts the issue can remain and on the backlog. I have applied a label to indicate that this would require a breaking change. Unless we see huge demand for this feature, we likely will not make a major release only to add this feature, but we can include it with the next major release, whenever that occurs. I do not have a specific timeline for the next major release, but likely within a few months.
I would ask that we close the PR for now, just to keep things tidy. We can revive the branch whenever we are ready to make the change.
Also, as a workaround until we release this change, you might be able to implement custom sampling logic in before_send.
Doing this would require you to set a sample_rate of 1.0 (the default), and then to implement your custom sampling logic in before_send. This setup could look something like the following pseudocode:
Hi @darrell-roberts, following the release of SDK version 0.49.0, we can now add new client configuration options without necessitating a breaking change, since the relevant struct was made #[non_exhaustive].
If you are interested, you can update your PR (some APIs have changed), and then reopen it.
Hi @darrell-roberts, following the release of SDK version 0.49.0, we can now add new client configuration options without necessitating a breaking change, since the relevant struct was made #[non_exhaustive].
If you are interested, you can update your PR (some APIs have changed), and then reopen it.
Hi @darrell-roberts, sorry for the back and forth on this issue.
I realize that I previously suggested reopening your original PR once ClientOptions became #[non_exhaustive]. However, after discussing this feature proposal internally with the broader SDK team, we decided not to add dynamic per-event error sampling to the Rust SDK at this time.
The use case is valid, but the other SDKs we checked do not support this capability; the Python SDK is currently the only exception. A dynamic error sampler is also not defined in the Sentry SDK specification. Since this use case can already be implemented with a custom before_send callback, we do not want to introduce and maintain a Rust-specific API for it at this time.
As I mentioned previously, the supported workaround is to set sample_rate to 1.0 (the default) and implement the custom sampling logic in before_send:
This is a product and maintenance decision rather than a judgment on the use case or the implementation. We appreciate you bringing the use case to our attention and taking the time to implement a solution. We would reconsider this decision if our cross-SDK direction changes or if there is significant community demand for the feature.
Activity
linear-code commentedon May 17, 2026
RUST-215
darrell-roberts commentedon May 17, 2026
Created draft PR: #1128
szokeasaurusrex commentedon May 18, 2026
Hi @darrell-roberts, thanks for the issue and the draft PR!
Rather than adding a function that returns a boolean to fully ignore the sample rate, I would suggest we instead add support for an
error_samplerfunction, like we have in the Python SDK, which returns a floating-point value instead of a boolean. That version allows sampling different events at different sample rates, in addition to supporting your use case.However, as adding fields to the
ClientOptionsis a breaking change, we will need to carefully consider if/when we should make this change.darrell-roberts commentedon May 18, 2026
Hi @szokeasaurusrex
Thanks. The approach in the python SDK is a better approach. I've updated the draft PR with the suggestion.
This may be ok, in the sense if no user defined sampling rate override function is provided it falls back to the default behavior.
szokeasaurusrex commentedon May 18, 2026
@darrell-roberts the problem is that the
ClientOptionsstruct is apubstruct with allpubfields. Even though most users will likely constructClientOptionsby setting a few fields manually then having..Default::defaultfill in the rest, it is still possible to exhaustively construct and/or to exhaustively match against theClientOptionsstruct. As adding a field will break code which exhaustively constructs or matches the struct, it is a breaking change.At some point, I would like to refractor
ClientOptionsso that we can add functionality in a non-breaking manner, but this itself will be a disruptive breaking change, as it would require fundamentally changing the API. So that will only happen after careful consideration.darrell-roberts commentedon May 19, 2026
What do you suggest I do with this issue / PR?
szokeasaurusrex commentedon May 19, 2026
@darrell-roberts the issue can remain and on the backlog. I have applied a label to indicate that this would require a breaking change. Unless we see huge demand for this feature, we likely will not make a major release only to add this feature, but we can include it with the next major release, whenever that occurs. I do not have a specific timeline for the next major release, but likely within a few months.
I would ask that we close the PR for now, just to keep things tidy. We can revive the branch whenever we are ready to make the change.
szokeasaurusrex commentedon May 19, 2026
Also, as a workaround until we release this change, you might be able to implement custom sampling logic in
before_send.Doing this would require you to set a
sample_rateof1.0(the default), and then to implement your custom sampling logic inbefore_send. This setup could look something like the following pseudocode:feat(core): Add event sampling strategy
feat(core): Add event sampling strategy
feat(core): Add event sampling strategy
feat!(core): Add event sampling strategy (#1228)
szokeasaurusrex commentedon Jul 29, 2026
Hi @darrell-roberts, following the release of SDK version 0.49.0, we can now add new client configuration options without necessitating a breaking change, since the relevant struct was made
#[non_exhaustive].If you are interested, you can update your PR (some APIs have changed), and then reopen it.
darrell-roberts commentedon Aug 11, 2026
Hi @szokeasaurusrex, Thanks. I've put up PR #1284.
szokeasaurusrex commentedon Aug 11, 2026
Hi @darrell-roberts, sorry for the back and forth on this issue.
I realize that I previously suggested reopening your original PR once
ClientOptionsbecame#[non_exhaustive]. However, after discussing this feature proposal internally with the broader SDK team, we decided not to add dynamic per-event error sampling to the Rust SDK at this time.The use case is valid, but the other SDKs we checked do not support this capability; the Python SDK is currently the only exception. A dynamic error sampler is also not defined in the Sentry SDK specification. Since this use case can already be implemented with a custom
before_sendcallback, we do not want to introduce and maintain a Rust-specific API for it at this time.As I mentioned previously, the supported workaround is to set
sample_rateto1.0(the default) and implement the custom sampling logic inbefore_send:This is a product and maintenance decision rather than a judgment on the use case or the implementation. We appreciate you bringing the use case to our attention and taking the time to implement a solution. We would reconsider this decision if our cross-SDK direction changes or if there is significant community demand for the feature.