Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(sentry-tracing): add span fields to breadcrumbs #708

Merged

Conversation

thomaseizinger
Copy link
Contributor

The fields of a span are equally helpful in an event as well as in the breadcrumbs leading up to it. In fact, in an application that makes heavy use of spans to add contextual information to messages, the log messages themselves without the span fields are often almost useless.

@thomaseizinger thomaseizinger changed the title feat(sentry-tracing): add span fields to breadcrbums feat(sentry-tracing): add span fields to breadcrumbs Nov 19, 2024
github-merge-queue bot pushed a commit to firezone/firezone that referenced this pull request Nov 19, 2024
This switches our `sentry-tracing` dependency to a fork that includes
getsentry/sentry-rust#708. Recording our span
fields with breadcrumbs is important to provide accurate context of the
message. Without the span fields, the messages give us a lot less
information.

Since the last release, the open issue on `flush` having a flipped
return value got fixed as well.
@thomaseizinger
Copy link
Contributor Author

Unfortuantely, this is only one half of the story. We also need to find a solution to #617 (comment) otherwise only spans that have been sampled are present.

@Swatinem
Copy link
Member

I think this needs a rebase

@thomaseizinger thomaseizinger force-pushed the feat/add-span-context-to-breadcrumbs branch from 5570b24 to 789cdc1 Compare November 29, 2024 08:22
@thomaseizinger
Copy link
Contributor Author

I think this needs a rebase

Done!

@thomaseizinger
Copy link
Contributor Author

thomaseizinger commented Nov 29, 2024

Unfortuantely, this is only one half of the story. We also need to find a solution to #617 (comment) otherwise only spans that have been sampled are present.

Any thoughts on this? I did some digging through the codebase and I think we could solve this by sampling spans later, i.e. keep them around initially and only sample and discard them when they are about to be submitted to Sentry. I don't know how much of a performance impact this has though.

The problem with the current approach is that the code added in this PR does not do anything unless one also samples all spans. That on the other hand though can create A LOT of spans in Sentry which may not be desired. Ideally, I think the two features of sampling spans to be sent to Sentry and capturing the fields within spans for breadcrumbs and events are orthogonal.

@thomaseizinger

This comment was marked as outdated.

@Swatinem
Copy link
Member

A test for tracing was recently added here: 00cb40f
You might be able to use the with_captured_envelopes_options function:

pub fn with_captured_envelopes_options<F: FnOnce(), O: Into<ClientOptions>>(

Otherwise I’m a bit out of the loop when it comes to how the SDK APIs and are supposed to work :-(

@Swatinem Swatinem enabled auto-merge (squash) November 29, 2024 08:43
@Swatinem Swatinem merged commit eb902e0 into getsentry:master Nov 29, 2024
14 checks passed
@thomaseizinger
Copy link
Contributor Author

A test for tracing was recently added here: 00cb40f

I managed to add one based on that! :)

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.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants