diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3ff2a2..cbd640a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sentry-tracing/src/converters.rs b/sentry-tracing/src/converters.rs index 6b3f991b..57162aed 100644 --- a/sentry-tracing/src/converters.rs +++ b/sentry-tracing/src/converters.rs @@ -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>>, + ctx: C, ) -> Breadcrumb where S: Subscriber + for<'a> LookupSpan<'a>, + C: Into>>, { let (message, visitor) = extract_event_data_with_context(event, ctx.into(), true); @@ -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>>, +) -> 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) -> BTreeMap { let mut tags = BTreeMap::new(); @@ -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>>, + ctx: C, ) -> Event<'static> where S: Subscriber + for<'a> LookupSpan<'a>, + C: Into>>, { // 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 @@ -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>>, +) -> 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>>, ) -> 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>>, { let (message, visitor) = extract_event_data_with_context(event, ctx.into(), true); diff --git a/sentry-tracing/src/layer/breadcrumb.rs b/sentry-tracing/src/layer/breadcrumb.rs index a4f2fd07..7eb71ad8 100644 --- a/sentry-tracing/src/layer/breadcrumb.rs +++ b/sentry-tracing/src/layer/breadcrumb.rs @@ -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. /// @@ -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), )); diff --git a/sentry-tracing/src/layer/error.rs b/sentry-tracing/src/layer/error.rs index 488f9935..c9d6eebf 100644 --- a/sentry-tracing/src/layer/error.rs +++ b/sentry-tracing/src/layer/error.rs @@ -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. /// @@ -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); } } diff --git a/sentry-tracing/src/layer/log.rs b/sentry-tracing/src/layer/log.rs index 0a5e65b5..d3816427 100644 --- a/sentry-tracing/src/layer/log.rs +++ b/sentry-tracing/src/layer/log.rs @@ -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. /// @@ -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), )); diff --git a/sentry-tracing/src/lib.rs b/sentry-tracing/src/lib.rs index 012c0f87..66dcd82f 100644 --- a/sentry-tracing/src/lib.rs +++ b/sentry-tracing/src/lib.rs @@ -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.";