From cc7b53c11d2b0d5867d0366ccb1d39ec4da2bf19 Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Tue, 7 Oct 2025 17:06:58 +0200 Subject: [PATCH 1/7] feat: Add custom attachment type --- sentry-types/src/protocol/attachment.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/sentry-types/src/protocol/attachment.rs b/sentry-types/src/protocol/attachment.rs index 8b2ce6d74..c694c1581 100644 --- a/sentry-types/src/protocol/attachment.rs +++ b/sentry-types/src/protocol/attachment.rs @@ -3,7 +3,7 @@ use std::fmt; use serde::Deserialize; /// The different types an attachment can have. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize)] pub enum AttachmentType { #[serde(rename = "event.attachment")] /// (default) A standard attachment without special meaning. @@ -23,6 +23,9 @@ pub enum AttachmentType { /// the last logs are extracted into event breadcrumbs. #[serde(rename = "unreal.logs")] UnrealLogs, + /// A custom attachment type with an arbitrary string value. + #[serde(untagged)] + Custom(String), } impl Default for AttachmentType { @@ -33,13 +36,14 @@ impl Default for AttachmentType { impl AttachmentType { /// Gets the string value Sentry expects for the attachment type. - pub fn as_str(self) -> &'static str { + pub fn as_str(&self) -> &str { match self { Self::Attachment => "event.attachment", Self::Minidump => "event.minidump", Self::AppleCrashReport => "event.applecrashreport", Self::UnrealContext => "unreal.context", Self::UnrealLogs => "unreal.logs", + Self::Custom(s) => s, } } } @@ -68,7 +72,7 @@ impl Attachment { r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}","content_type":"{ct}"}}"#, filename = self.filename, length = self.buffer.len(), - at = self.ty.unwrap_or_default().as_str(), + at = self.ty.clone().unwrap_or_default().as_str(), ct = self .content_type .as_ref() @@ -92,3 +96,18 @@ impl fmt::Debug for Attachment { .finish() } } + +#[cfg(test)] +mod tests { + use super::*; + use serde_json; + + #[test] + fn test_attachment_type_deserialize() { + let result: AttachmentType = serde_json::from_str(r#""event.minidump""#).unwrap(); + assert_eq!(result, AttachmentType::Minidump); + + let result: AttachmentType = serde_json::from_str(r#""my.custom.type""#).unwrap(); + assert_eq!(result, AttachmentType::Custom("my.custom.type".to_string())); + } +} From 1b42c152e874d4c78de8751eaa805084b82dbe3c Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Wed, 8 Oct 2025 08:07:56 +0200 Subject: [PATCH 2/7] Add changelog message --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3063a0b..17f174cda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - feat(log): support combined LogFilters and RecordMappings ([#914](https://github.com/getsentry/sentry-rust/pull/914)) by @lcian - Breaking change: `sentry::integrations::log::LogFilter` has been changed to a `bitflags` struct. - It's now possible to map a `log` record to multiple items in Sentry by combining multiple log filters in the filter, e.g. `log::Level::ERROR => LogFilter::Event | LogFilter::Log`. - - If using a custom `mapper` instead, it's possible to return a `Vec` to map a `log` record to multiple items in Sentry. + - If using a custom `mapper` instead, it's possible to return a `Vec` to map a `log` record to multiple items in Sentry. + - Add custom variant to `AttachmentType` that holds an arbitrary String. ([#916](https://github.com/getsentry/sentry-rust/pull/916)) ### Behavioral changes From 3ad7329eb7e5b2964507af4cc48ef2bc4554c277 Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Wed, 8 Oct 2025 08:09:37 +0200 Subject: [PATCH 3/7] Add changelog entry in correct section --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f174cda..9137444a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Breaking changes + +- Add custom variant to `AttachmentType` that holds an arbitrary String. ([#916](https://github.com/getsentry/sentry-rust/pull/916)) + ## 0.44.0 ### Breaking changes From 9122269fadef257cdd75968936fdde56f76d2f34 Mon Sep 17 00:00:00 2001 From: Tobias Wilfert <36408720+tobias-wilfert@users.noreply.github.com> Date: Wed, 8 Oct 2025 10:02:43 +0200 Subject: [PATCH 4/7] Apply suggestion from @Swatinem Co-authored-by: Arpad Borsos --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9137444a3..4b0cbe116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ - Breaking change: `sentry::integrations::log::LogFilter` has been changed to a `bitflags` struct. - It's now possible to map a `log` record to multiple items in Sentry by combining multiple log filters in the filter, e.g. `log::Level::ERROR => LogFilter::Event | LogFilter::Log`. - If using a custom `mapper` instead, it's possible to return a `Vec` to map a `log` record to multiple items in Sentry. - - Add custom variant to `AttachmentType` that holds an arbitrary String. ([#916](https://github.com/getsentry/sentry-rust/pull/916)) ### Behavioral changes From 092f407e2b0b02fc908551fa006eec18ee18d706 Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Wed, 8 Oct 2025 10:04:20 +0200 Subject: [PATCH 5/7] Undo formatting changes --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0cbe116..4d93483d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - feat(log): support combined LogFilters and RecordMappings ([#914](https://github.com/getsentry/sentry-rust/pull/914)) by @lcian - Breaking change: `sentry::integrations::log::LogFilter` has been changed to a `bitflags` struct. - It's now possible to map a `log` record to multiple items in Sentry by combining multiple log filters in the filter, e.g. `log::Level::ERROR => LogFilter::Event | LogFilter::Log`. - - If using a custom `mapper` instead, it's possible to return a `Vec` to map a `log` record to multiple items in Sentry. + - If using a custom `mapper` instead, it's possible to return a `Vec` to map a `log` record to multiple items in Sentry. ### Behavioral changes @@ -53,6 +53,7 @@ ### Features - ref(tracing): rework tracing to Sentry span name/op conversion ([#887](https://github.com/getsentry/sentry-rust/pull/887)) by @lcian + - Additional special fields have been added that allow overriding certain data on the Sentry span: - `sentry.op`: override the Sentry span op. - `sentry.name`: override the Sentry span name. @@ -194,10 +195,11 @@ ### Features Support for [Sentry structured logs](https://docs.sentry.io/product/explore/logs/) has been added to the SDK. + - To set up logs, enable the `logs` feature of the `sentry` crate and set `enable_logs` to `true` in your client options. - Then, use the `logger_trace!`, `logger_debug!`, `logger_info!`, `logger_warn!`, `logger_error!` and `logger_fatal!` macros to capture logs. - To filter or update logs before they are sent, you can use the `before_send_log` client option. -- Please note that breaking changes could occur until the API is finalized. +- Please note that breaking changes could occur until the API is finalized. - feat(logs): add log protocol types (#821) by @lcian - feat(logs): add ability to capture and send logs (#823) by @lcian & @Swatinem @@ -302,7 +304,7 @@ An OpenTelemetry integration has been released. Please refer to the changelog en - The metrics feature and the code related to it has been removed from the crate, as the Sentry backend stopped ingesting metrics a while ago. - Switch to MIT license (#724) by @cleptric - The license for the crates has been changed to MIT. - + ### Features - feat(actix): capture HTTP request body (#731) by @pacifistes From a6888fdc966141f07c75db4ae9592b229b3053fc Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Wed, 8 Oct 2025 10:17:01 +0200 Subject: [PATCH 6/7] Undo formatting changes --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d93483d0..e8323e51f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,6 @@ ### Features - ref(tracing): rework tracing to Sentry span name/op conversion ([#887](https://github.com/getsentry/sentry-rust/pull/887)) by @lcian - - Additional special fields have been added that allow overriding certain data on the Sentry span: - `sentry.op`: override the Sentry span op. - `sentry.name`: override the Sentry span name. @@ -195,11 +194,10 @@ ### Features Support for [Sentry structured logs](https://docs.sentry.io/product/explore/logs/) has been added to the SDK. - - To set up logs, enable the `logs` feature of the `sentry` crate and set `enable_logs` to `true` in your client options. - Then, use the `logger_trace!`, `logger_debug!`, `logger_info!`, `logger_warn!`, `logger_error!` and `logger_fatal!` macros to capture logs. - To filter or update logs before they are sent, you can use the `before_send_log` client option. -- Please note that breaking changes could occur until the API is finalized. +- Please note that breaking changes could occur until the API is finalized. - feat(logs): add log protocol types (#821) by @lcian - feat(logs): add ability to capture and send logs (#823) by @lcian & @Swatinem @@ -304,7 +302,7 @@ An OpenTelemetry integration has been released. Please refer to the changelog en - The metrics feature and the code related to it has been removed from the crate, as the Sentry backend stopped ingesting metrics a while ago. - Switch to MIT license (#724) by @cleptric - The license for the crates has been changed to MIT. - + ### Features - feat(actix): capture HTTP request body (#731) by @pacifistes From 42033ae3a79805d9f1c2306b0391a388a8bad22c Mon Sep 17 00:00:00 2001 From: tobias-wilfert Date: Wed, 8 Oct 2025 10:41:38 +0200 Subject: [PATCH 7/7] Avoid the clone --- sentry-types/src/protocol/attachment.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sentry-types/src/protocol/attachment.rs b/sentry-types/src/protocol/attachment.rs index c694c1581..e23a64784 100644 --- a/sentry-types/src/protocol/attachment.rs +++ b/sentry-types/src/protocol/attachment.rs @@ -72,7 +72,11 @@ impl Attachment { r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}","content_type":"{ct}"}}"#, filename = self.filename, length = self.buffer.len(), - at = self.ty.clone().unwrap_or_default().as_str(), + at = self + .ty + .as_ref() + .unwrap_or(&AttachmentType::default()) + .as_str(), ct = self .content_type .as_ref()