pub struct SentryLayer<S> { /* private fields */ }Prefer SpanLayer::new() and LogLayer::new(); see SentryLayer docs for migration
Expand description
Legacy combined tracing layer.
For most applications, use SpanLayer and LogLayer with explicit filters instead.
Add ErrorLayer if tracing events should also be captured as Sentry error events, and
BreadcrumbLayer if errors need breadcrumb context.
Mixing this legacy layer with any individual Sentry layer is unsupported.
Combining it with SpanLayer can panic when a span is created. When migrating,
replace the legacy layer rather than adding individual layers alongside it.
ยงMigrating the default configuration
The individual layers do not filter by level internally. The following configuration
reproduces the default level selection of SentryLayer with the logs feature enabled:
ERROR,WARN, andINFOspans become Sentry transactions and spans.ERROR,WARN, andINFOevents become structured logs.ERRORevents also become Sentry error events.WARNandINFOevents also become breadcrumbs on the current scope, sent with subsequent captured errors.
use sentry::integrations::tracing::{BreadcrumbLayer, ErrorLayer, LogLayer, SpanLayer};
use tracing::Level;
use tracing_subscriber::filter::{filter_fn, LevelFilter};
use tracing_subscriber::prelude::*;
tracing_subscriber::registry()
.with(SpanLayer::new().with_filter(LevelFilter::INFO))
.with(
BreadcrumbLayer::new().with_filter(filter_fn(|metadata| {
matches!(*metadata.level(), Level::WARN | Level::INFO)
})),
)
.with(ErrorLayer::new().with_filter(LevelFilter::ERROR))
.with(LogLayer::new().with_filter(LevelFilter::INFO))
.init();Without the logs feature, omit the log layer. Client configuration, including trace sampling,
is unchanged.
If the legacy layer used enable_span_attributes, enable
span attributes on each individual event layer that needs them. See the option docs for
breadcrumbs,
errors, and
logs for filtering requirements.
ยงMigrating custom configuration
- Replace
span_filterwith a filter on the span layer. - Split
event_filterinto filters on the individual event layers. An event can be accepted by multiple layers, replacing combinedEventFilterflags. - Individual layers do not provide mapper callbacks. Some
SentryLayer::event_mapperusages may be addressed by other existing APIs, such as filter callbacks on the layers orbefore_send*callbacks provided by the Sentry SDK. However, we recognize it may not be possible to migrate all existing usages. If you are unable to migrate to the new API due to this change, we would love to hear from you. Please open a GitHub issue explaining your use case, and we will work with you to find a solution.
If a custom configuration sends the same event to both the breadcrumb and error layers,
install the breadcrumb layer before the error layer to include that breadcrumb in the error.
The default configuration above excludes ERROR events from breadcrumbs, so the order does
not affect their inclusion.
Implementationsยง
Sourceยงimpl<S> SentryLayer<S>
impl<S> SentryLayer<S>
Sourcepub fn event_filter<F>(self, filter: F) -> Self
pub fn event_filter<F>(self, filter: F) -> Self
Sourcepub fn event_mapper<F>(self, mapper: F) -> Self
pub fn event_mapper<F>(self, mapper: F) -> Self
Sets a custom event mapper function.
The mapper is responsible for creating either breadcrumbs or events from
Events.
Sourcepub fn span_filter<F>(self, filter: F) -> Self
pub fn span_filter<F>(self, filter: F) -> Self
Sets a custom span filter function.
The filter classifies whether sentry should handle tracing::Spans based
on their Metadata.
Sourcepub fn enable_span_attributes(self) -> Self
pub fn enable_span_attributes(self) -> Self
Include attributes of parent spans in breadcrumbs, error events, and logs.
Only spans accepted by this layerโs span filter provide attributes. Including attributes does not require the transaction to be sampled.
When migrating, enable span attributes on each individual event layer that needs them; see the migration guide.
Trait Implementationsยง
Sourceยงimpl<S> Default for SentryLayer<S>where
S: Subscriber + for<'a> LookupSpan<'a>,
impl<S> Default for SentryLayer<S>where
S: Subscriber + for<'a> LookupSpan<'a>,
Sourceยงimpl<S> Layer<S> for SentryLayer<S>where
S: Subscriber + for<'a> LookupSpan<'a>,
impl<S> Layer<S> for SentryLayer<S>where
S: Subscriber + for<'a> LookupSpan<'a>,
Sourceยงfn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>)
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>)
Sourceยงfn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>)
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>)
Attributes and Id.Sourceยงfn on_enter(&self, id: &Id, ctx: Context<'_, S>)
fn on_enter(&self, id: &Id, ctx: Context<'_, S>)
Sourceยงfn on_exit(&self, id: &Id, ctx: Context<'_, S>)
fn on_exit(&self, id: &Id, ctx: Context<'_, S>)
Sourceยงfn on_close(&self, id: Id, ctx: Context<'_, S>)
fn on_close(&self, id: Id, ctx: Context<'_, S>)
Sourceยงfn on_record(&self, id: &Id, values: &Record<'_>, ctx: Context<'_, S>)
fn on_record(&self, id: &Id, values: &Record<'_>, ctx: Context<'_, S>)
Id recorded the given
values.Sourceยงfn on_register_dispatch(&self, subscriber: &Dispatch)
fn on_register_dispatch(&self, subscriber: &Dispatch)
Subscriber. Read moreSourceยงfn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest
Subscriber::register_callsite. Read moreSourceยงfn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool
true if this layer is interested in a span or event with the
given metadata in the current Context, similarly to
Subscriber::enabled. Read moreSourceยงfn on_follows_from(&self, _span: &Id, _follows: &Id, _ctx: Context<'_, S>)
fn on_follows_from(&self, _span: &Id, _follows: &Id, _ctx: Context<'_, S>)
span recorded that it
follows from the span with the ID follows.Sourceยงfn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<'_, S>)
fn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<'_, S>)
Sourceยงfn and_then<L>(self, layer: L) -> Layered<L, Self, S>
fn and_then<L>(self, layer: L) -> Layered<L, Self, S>
Layer, returning a Layered
struct implementing Layer. Read moreSourceยงfn with_subscriber(self, inner: S) -> Layered<Self, S>where
Self: Sized,
fn with_subscriber(self, inner: S) -> Layered<Self, S>where
Self: Sized,
Layer with the given Subscriber, returning a
Layered struct that implements Subscriber. Read more