Sentry Rust SDK: sentry-tracing
Capture tracing spans and events as Sentry traces and structured logs.
For most applications, we recommend installing only these two layers:
- [
SpanLayer] capturestracingspans as Sentry transactions and spans. - [
LogLayer] capturestracingevents as Sentry structured logs. Requires thelogsfeature.
We also provide the following layers, but recommend the span and log layers above for most applications:
- [
ErrorLayer] capturestracingevents as Sentry error events, with support for tags and exception information. - [
BreadcrumbLayer] addstracingevents as breadcrumbs on subsequent Sentry error events.
For migration from the legacy combined layer, see [SentryLayer].
Getting started
Enable the tracing and logs features on sentry to use its tracing integration re-export.
Set a traces sample rate to capture transactions, then install the span and log layers with
explicit level filters:
use ;
use LevelFilter;
use *;
let _guard = init;
registry
.with
.with
.init;
The layers do not filter by level internally. The filters above capture INFO, WARN, and
ERROR telemetry, excluding DEBUG and TRACE. Adjust each layer's filter independently to
control volume. Global subscriber filters also apply and can suppress telemetry before the
Sentry layers receive it.
Spans
SpanLayer creates a Sentry transaction when no Sentry span is active, or a child span
otherwise. For example,
tracing::instrument creates
spans for instrumented functions; arguments become span data unless skipped.
With the log layer installed, the info! event below produces a log associated with the same
trace as the instrumented functions:
async
async
By default, the Sentry span name matches the tracing span name, and its operation is
<target>::<span name>.
Special span fields
sentry.nameoverrides the Sentry span name, including when recorded after creation.sentry.opoverrides the Sentry span operation, including when recorded after creation.sentry.tracecontinues the trace from asentry-traceheader. It must be set when a root Sentry span is created, meaning no Sentry span is active in the current scope. Applying it to a child Sentry span or recording it after creation has no effect.
async
Logs
LogLayer sends events accepted by its filter as structured logs. Event fields become log
attributes.
info!;
Resources
License: MIT