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

fix: delay sampling of tracing spans to finish #712

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

thomaseizinger
Copy link
Contributor

This PR is an attempt to completely resolve #617.

Currently, fields from spans are only recorded when the span gets sampled. This currently happens very early, right when the Transaction gets created. As a result, any event that gets recorded afterwards (i.e. as a breadcrumb) does not have access to the current span fields.

By delaying the discarding of Transaction to finish, we get to retain all the contextual data and still honor the configured sampling.

I ran a performance test of our software with this local branch applied and could not measure any impact of this.

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.21%. Comparing base (605d36d) to head (9d0f853).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #712      +/-   ##
==========================================
+ Coverage   72.79%   73.21%   +0.42%     
==========================================
  Files          66       66              
  Lines        7804     7923     +119     
==========================================
+ Hits         5681     5801     +120     
+ Misses       2123     2122       -1     

@Swatinem Swatinem merged commit caa746d into getsentry:master Nov 29, 2024
14 checks passed
github-merge-queue bot pushed a commit to firezone/firezone that referenced this pull request Dec 2, 2024
This is another attempt at fixing #7386. Previous PR was #7379. The
difference is, this time it works! In the following screenshot,
`handle_input` is a currently active span.


![image](https://github.com/user-attachments/assets/0845d566-8ca7-4ba2-8786-9c5819cdfd48)

I had to make some patches to Sentry, most notably:

- getsentry/sentry-rust#708
- getsentry/sentry-rust#712

The way we configure Sentry is quite tricky:

First and foremost, we need to understand that the `tracing` adapter for
Sentry has a `span_filter` configuration. When a span gets filtered out
there, the rest of `sentry-tracing` never sees the data in that span.
Thus, in order to capture variables from spans, we need to have a fairly
generous span filter. In this PR, we change this span filter to include
all spans except those on TRACE level.

Secondly, by default, the Sentry SDK doesn't send any spans to the
backend, i.e. the sampling rate is 0. Previously, we set the sampling
rate to 1.0 because the `span_filter` was already filtering out all
non-telemetry spans. A telemetry span is a concept that we invented. It
is a span that gets sampled at _creation_ time with a probability of 1%.
This is useful because creating a lot of spans is also expensive, so we
don't want to do it e.g. on a per-packet basis. With just these
configuration options, we now have a problem: We don't want to submit
all spans to Sentry but we need the `span_filter` to allow all spans
otherwise we can't capture the contextual fields from the span in
breadcrumbs. Luckily, the Sentry SDK has another configuration option:
`traces_sampler`.

The `traces_sampler` gets to compute a sampling rate for each individual
span. This allows us to discard all spans from being sent to Sentry
unless they are `telemetry` spans.

Resolves: #7386.
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.

Propagate tracing span attributes in sentry events
2 participants