sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

Expose span fields through FieldVisitor

Open yuanluna opened this issue 2 years ago • 8 comments
trafficstars

Hi, in Sentry we define the FieldVisitor here in the extract_span_data, and used it here in the on_new_span for the sentry layer, the data of the tracing span is directly written into sentry Span, which does not expose these data at all. Can we make this customizable to be able to read certain data from span?

Thank you!

yuanluna avatar Feb 03 '23 05:02 yuanluna

@loewenheim Hi, thanks for responding quickly! Do you think it is possible to simply bump extract_span_data to public? or to quickly add some getters for the inner data of sentry_span? Thanks!

yuanluna avatar Feb 03 '23 18:02 yuanluna

For your use case, is it sufficient to get access to the data individually by key or do you need to be able to see the whole map at once?

loewenheim avatar Feb 06 '23 11:02 loewenheim

I have devised a solution, would this work for you? https://github.com/getsentry/sentry-rust/pull/548

loewenheim avatar Feb 06 '23 17:02 loewenheim

Hi @loewenheim thank you so much for such a quick change!! Yes I would love to access the data through key. A quick dumb question: what's the best way of getting this span in the event_mapping filter on sentry layer? Thank you!

yuanluna avatar Feb 06 '23 17:02 yuanluna

Hi @loewenheim following up my question above. I am trying to fetch the sentry span in eventMapper, where I can only get the SpanRef, I thought the sentry span should be inside extension, but it is not. Can you help to understand the correct way to do it? Thanks a lot!!

yuanluna avatar Feb 09 '23 00:02 yuanluna

I'll get back to you as soon as I can.

loewenheim avatar Feb 09 '23 09:02 loewenheim

I think I have to pass this on to one of my colleagues. @swatinem or @jan-auer, can you weigh in?

loewenheim avatar Feb 09 '23 14:02 loewenheim

So you are trying to access the current span from within the configured event_mapper? https://docs.rs/sentry/latest/sentry/integrations/tracing/struct.SentryLayer.html#method.event_mapper

I don’t think there is a straight forward way right now. You can maybe use a configure_scope call to get the current span/transaction:

if let Some(span) = sentry::configure_scope(|scope| scope.get_span()) {
  // ...
}

Swatinem avatar Feb 13 '23 12:02 Swatinem