Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Deprecations

- Deprecated [`sentry_tracing::layer()`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/fn.layer.html) and [`SentryLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SentryLayer.html), along with their associated filtering and mapping types and helpers, in favor of independently selectable [`SpanLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SpanLayer.html), [`LogLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.LogLayer.html), [`ErrorLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.ErrorLayer.html), and [`BreadcrumbLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.BreadcrumbLayer.html). A [migration guide](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SentryLayer.html) is available ([#1342](https://github.com/getsentry/sentry-rust/pull/1342)).
- Deprecated [`sentry_tracing::layer()`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/fn.layer.html) and [`SentryLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SentryLayer.html), along with their associated filtering and mapping types and helpers, in favor of independently selectable [`SpanLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SpanLayer.html), [`LogLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.LogLayer.html), [`ErrorLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.ErrorLayer.html), and [`BreadcrumbLayer`](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.BreadcrumbLayer.html). A [migration guide](https://docs.rs/sentry-tracing/0.49.4/sentry_tracing/struct.SentryLayer.html) is available ([#1342](https://github.com/getsentry/sentry-rust/pull/1342), [#1348](https://github.com/getsentry/sentry-rust/pull/1348)).
- As this is a larger change, we would love to hear your feedback about the new API if you have trouble migrating. Please [open a GitHub issue](https://github.com/getsentry/sentry-rust/issues/new?template=02-improvement.yml), and we will help identify a solution.

## 0.49.3
Expand Down
72 changes: 62 additions & 10 deletions sentry-tracing/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,13 @@ impl Visit for FieldVisitor {
}
}

/// Creates a [`Breadcrumb`] from a given [`tracing_core::Event`].
#[expect(clippy::impl_trait_in_params, reason = "existed before lint enabled")]
pub fn breadcrumb_from_event<'context, S>(
pub(crate) fn breadcrumb_from_event_impl<'context, S, C>(
event: &tracing_core::Event,
ctx: impl Into<Option<&'context Context<'context, S>>>,
ctx: C,
) -> Breadcrumb
where
S: Subscriber + for<'a> LookupSpan<'a>,
C: Into<Option<&'context Context<'context, S>>>,
{
let (message, visitor) = extract_event_data_with_context(event, ctx.into(), true);

Expand All @@ -219,6 +218,25 @@ where
}
}

// TODO: When removing this function, rename `breadcrumb_from_event_impl` to `breadcrumb_from_event`.
/// Creates a [`Breadcrumb`] from a given [`tracing_core::Event`].
#[deprecated(
note = "Only useful for custom `SentryLayer::event_mapper` callbacks; that API is deprecated"
)]
#[expect(
clippy::impl_trait_in_params,
reason = "preserving the public helper signature"
)]
pub fn breadcrumb_from_event<'context, S>(
event: &tracing_core::Event,
ctx: impl Into<Option<&'context Context<'context, S>>>,
) -> Breadcrumb
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
breadcrumb_from_event_impl(event, ctx)
}

/// Convert `tracing` fields to the corresponding Sentry tags, removing them from `fields`.
fn extract_and_remove_tags(fields: &mut BTreeMap<String, Value>) -> BTreeMap<String, String> {
let mut tags = BTreeMap::new();
Expand Down Expand Up @@ -278,14 +296,13 @@ fn contexts_from_event(
context
}

/// Creates an [`Event`] (possibly carrying exceptions) from a given [`tracing_core::Event`].
#[expect(clippy::impl_trait_in_params, reason = "existed before lint enabled")]
pub fn event_from_event<'context, S>(
pub(crate) fn event_from_event_impl<'context, S, C>(
event: &tracing_core::Event,
ctx: impl Into<Option<&'context Context<'context, S>>>,
ctx: C,
) -> Event<'static>
where
S: Subscriber + for<'a> LookupSpan<'a>,
C: Into<Option<&'context Context<'context, S>>>,
{
// Exception records in Sentry need a valid type, value and full stack trace to support
// proper grouping and issue metadata generation. tracing_core::Record does not contain sufficient
Expand Down Expand Up @@ -349,19 +366,54 @@ where
}
}

/// Creates a [`Log`] from a given [`tracing_core::Event`]
// TODO: When removing this function, rename `event_from_event_impl` to `event_from_event`.
/// Creates an [`Event`] (possibly carrying exceptions) from a given [`tracing_core::Event`].
#[deprecated(
note = "Only useful for custom `SentryLayer::event_mapper` callbacks; that API is deprecated"
)]
#[expect(
clippy::impl_trait_in_params,
reason = "preserving the public helper signature"
)]
pub fn event_from_event<'context, S>(
event: &tracing_core::Event,
ctx: impl Into<Option<&'context Context<'context, S>>>,
) -> Event<'static>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
event_from_event_impl(event, ctx)
}

// TODO: When removing this function, rename `log_from_event_impl` to `log_from_event`.
/// Creates a [`Log`] from a given [`tracing_core::Event`].
///
/// If a context is provided, include available parent-span data in the returned log's attributes.
/// See [`crate::LogLayer::enable_span_attributes`] for span-capture and filtering requirements.
#[cfg(feature = "logs")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "logs")))]
#[expect(clippy::impl_trait_in_params, reason = "existed before lint enabled")]
#[deprecated(
note = "Only useful for custom `SentryLayer::event_mapper` callbacks; that API is deprecated"
)]
#[expect(
clippy::impl_trait_in_params,
reason = "preserving the public helper signature"
)]
pub fn log_from_event<'context, S>(
event: &tracing_core::Event,
ctx: impl Into<Option<&'context Context<'context, S>>>,
) -> Log
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
log_from_event_impl(event, ctx)
}

#[cfg(feature = "logs")]
pub(crate) fn log_from_event_impl<'context, S, C>(event: &tracing_core::Event, ctx: C) -> Log
where
S: Subscriber + for<'a> LookupSpan<'a>,
C: Into<Option<&'context Context<'context, S>>>,
{
let (message, visitor) = extract_event_data_with_context(event, ctx.into(), true);

Expand Down
4 changes: 2 additions & 2 deletions sentry-tracing/src/layer/breadcrumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_core::{Event, Subscriber};
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;

use crate::converters::breadcrumb_from_event;
use crate::converters::breadcrumb_from_event_impl;

/// Adds tracing events as Sentry breadcrumbs.
///
Expand Down Expand Up @@ -114,7 +114,7 @@ impl BreadcrumbLayer {
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
self.capture(breadcrumb_from_event(
self.capture(breadcrumb_from_event_impl(
event,
self.with_span_attributes.then_some(&ctx),
));
Expand Down
4 changes: 2 additions & 2 deletions sentry-tracing/src/layer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_core::{Event, Subscriber};
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;

use crate::converters::event_from_event;
use crate::converters::event_from_event_impl;

/// Captures tracing events as Sentry error events.
///
Expand Down Expand Up @@ -110,7 +110,7 @@ impl ErrorLayer {
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let sentry_event = event_from_event(event, self.with_span_attributes.then_some(&ctx));
let sentry_event = event_from_event_impl(event, self.with_span_attributes.then_some(&ctx));
self.capture(sentry_event);
}
}
Expand Down
4 changes: 2 additions & 2 deletions sentry-tracing/src/layer/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_core::{Event, Subscriber};
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;

use crate::converters::log_from_event;
use crate::converters::log_from_event_impl;

/// Captures tracing events as Sentry logs.
///
Expand Down Expand Up @@ -107,7 +107,7 @@ impl LogLayer {
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
self.capture(log_from_event(
self.capture(log_from_event_impl(
event,
self.with_span_attributes.then_some(&ctx),
));
Expand Down
6 changes: 5 additions & 1 deletion sentry-tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
mod converters;
mod layer;

pub use converters::*;
#[cfg(feature = "logs")]
#[expect(deprecated, reason = "re-exporting deprecated legacy mapper helpers")]
pub use converters::log_from_event;
#[expect(deprecated, reason = "re-exporting deprecated legacy mapper helpers")]
pub use converters::{breadcrumb_from_event, event_from_event};
pub use layer::*;

const TAGS_PREFIX: &str = "tags.";
Expand Down
Loading