Skip to content

feat: Add option to exclude certain HTTP statuses from tracing#5034

Open
jamescrosswell wants to merge 13 commits intomainfrom
trace-ignore-status-codes
Open

feat: Add option to exclude certain HTTP statuses from tracing#5034
jamescrosswell wants to merge 13 commits intomainfrom
trace-ignore-status-codes

Conversation

@jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Mar 17, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Breaking Changes 🛠

  • The _Metrics_ APIs are now stable: removed Experimental from SentrySdk, SentryOptions and IHub by Flash0ver in #5023

Features ✨

  • Report a new _Diagnostic_ (SENTRY1001) when a Metrics-API is invoked with an unsupported numeric type by Flash0ver in #4840
  • feat: Add option to exclude certain HTTP statuses from tracing by jamescrosswell in #5034

Fixes 🐛

  • fix: include Data set via ITransactionTracer in SentryTransaction by Flash0ver in #4148
  • fix: CaptureFeedback now applies event processors by jamescrosswell in #4942

Dependencies ⬆️

Deps

  • chore(deps): update Java SDK to v8.36.0 by github-actions in #5036
  • chore(deps): update epitaph to 0.1.1 by github-actions in #5036
  • chore(deps): update Native SDK to v0.13.3 by github-actions in #5045
  • chore(deps): update Cocoa SDK to v9.7.0 by github-actions in #5015
  • chore(deps): update Java SDK to v8.35.0 by github-actions in #5017
  • chore(deps): replaced the heavy protobuf-javalite 3.25.8 dependency with a light-weight epitaph 0.1.0 alternative on Android (getsentry/sentry-java#5157) by github-actions in #5017
  • chore(deps): update CLI to v3.3.3 by github-actions in #5002
  • chore(deps): update Cocoa SDK to v9.6.0 by github-actions in #4958

Other

  • ref: Use .NET 6.0 ArgumentNullException throw helpers by copilot-swe-agent in #4985

🤖 This preview updates automatically when you update the PR.

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.02%. Comparing base (58c1a81) to head (9393cdc).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...or.WebAssembly/WebAssemblyHostBuilderExtensions.cs 0.00% 1 Missing ⚠️
src/Sentry/BindableSentryOptions.cs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5034   +/-   ##
=======================================
  Coverage   74.02%   74.02%           
=======================================
  Files         499      500    +1     
  Lines       18049    18063   +14     
  Branches     3512     3515    +3     
=======================================
+ Hits        13361    13372   +11     
- Misses       3831     3837    +6     
+ Partials      857      854    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell changed the base branch from main to fix/transaction/tracer-setdata-not-sent March 18, 2026 00:23
@jamescrosswell jamescrosswell changed the base branch from fix/transaction/tracer-setdata-not-sent to main March 18, 2026 00:23
@jamescrosswell jamescrosswell marked this pull request as ready for review March 22, 2026 21:55
&& statusCodeObj is int statusCode
&& _options.TraceIgnoreStatusCodes.ContainsStatusCode(statusCode))
{
return null;
Copy link
Member

Choose a reason for hiding this comment

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

question: Sampling Decision

From the dev docs:

If the value of this attribute matches one of the status codes in traceIgnoreStatusCodes, the SDK MUST set the transaction's sampling decision to not sampled.

Should this have other effects as well,
like setting the "sample_rate" on the DynamicSamplingContext as well,
or am I misunderstanding something there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At this stage, the Dynamic Sampling Context is no longer relevant... the transaction tracer has already been finished and a snapshot of the transaction has been created in the form of a SentryTransaction (a more or less immutable DTO - certainly it's not used for tracing any longer). Any outbound requests that were made using the DSC have already been completed so there's no way to retrospectively change the sample rate that was communicated for those.

public string? CacheDirectoryPath { get; set; }
public bool? CaptureFailedRequests { get; set; }
public List<string>? FailedRequestTargets { get; set; }
public List<int>? TraceIgnoreStatusCodes { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

issue: potential inconsistency

I wanted to check whether we are consistent with the other IList<HttpStatusCodeRange>-based Option, which is FailedRequestStatusCodes.

But FailedRequestStatusCodes does not exist on the BindableSentryOptions.

Now I'm wondering, whether BindableSentryOptions.FailedRequestStatusCodes does not exist because

  • we forgot it
  • we didn't add it because of scalar status codes vs Status-Code-Ranges

If the reasoning is the latter, then I guess we should not add this BindableSentryOptions as well, for consistency.

If, instead of only allowing scalar bindable options,
we also want to be able to depict Ranges via BindableSentryOptions, perhaps we could enable parsing from

{
  "Sentry": {
    "TraceIgnoreStatusCodes": [[301, 303], [305, 399], [401, 404]],
    "TraceIgnoreStatusCodes": [ {"start": 301, "end": 303}, {"start": 305, "end": 399}, {"start": 401, "end":404}]
  }
}

or something like that.

If we'd like to do that, for both this TraceIgnoreStatusCodes, and the already existing SentryOptions.FailedRequestStatusCodes, perhaps we want to hold off on this Bindable-Option for now, and introduce Bindable-HttpStatusCodeRange-Collections in a separate issue/PR.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But FailedRequestStatusCodes does not exist on the BindableSentryOptions.

Ideally as many of the options as possible would also be configurable via bindings (e.g. apssettings.json).

I think I didn't solve for FailedRequestStatusCodes specifically because the broader AOT problem was huge in scope. The shortest path to completion was simply to omit any non trivial properties (primitives) from the bindable options and require SDK users configure these instead via code.

I'm not really sure how many people will use the configuration bindings for these two properties, so a relatively simple solution to start with is probably not a bad thing. This PR adds the ability to configure lists of explicit codes to ignore via bindings... if people want to do more complex things like ranges, that would have to be done in code.

We could create a custom binding that was more sophisticated... it's certainly technically possible but would date longer to build and test. We have a backlog of over 300 issues so I'd recommend we just go with this simpler solution for the time being (or omit the ability to configure trace ignore status codes via bindings entirely).

We could also, for consistency, add an issue to the backlog to enable some similar bindable options for FailedRequestStatusCodes... with a medium priority initially (unless we get feedback from the community that this would be useful).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added #5061 as a follow up task to address the inconsistency:

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@jamescrosswell jamescrosswell marked this pull request as draft March 24, 2026 07:55
@jamescrosswell jamescrosswell marked this pull request as ready for review March 25, 2026 01:09
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.

Add option to exclude certain HTTP statuses from tracing in SDK

3 participants