@@ -321,24 +321,20 @@ relay_common::impl_str_de!(ContentType, "a content type string");
321321/// The type of an event attachment.
322322///
323323/// These item types must align with the Sentry processing pipeline.
324- #[ derive( Clone , Copy , Debug , Eq , PartialEq , Deserialize , Serialize ) ]
324+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
325325pub enum AttachmentType {
326326 /// A regular attachment without special meaning.
327- #[ serde( rename = "event.attachment" ) ]
328327 Attachment ,
329328
330329 /// A minidump crash report (binary data).
331- #[ serde( rename = "event.minidump" ) ]
332330 Minidump ,
333331
334332 /// An apple crash report (text data).
335- #[ serde( rename = "event.applecrashreport" ) ]
336333 AppleCrashReport ,
337334
338335 /// A msgpack-encoded event payload submitted as part of multipart uploads.
339336 ///
340337 /// This attachment is processed by Relay immediately and never forwarded or persisted.
341- #[ serde( rename = "event.payload" ) ]
342338 EventPayload ,
343339
344340 /// A msgpack-encoded list of payloads.
@@ -347,7 +343,6 @@ pub enum AttachmentType {
347343 /// will be merged and truncated to the maxmimum number of allowed attachments.
348344 ///
349345 /// This attachment is processed by Relay immediately and never forwarded or persisted.
350- #[ serde( rename = "event.breadcrumbs" ) ]
351346 Breadcrumbs ,
352347
353348 /// This is a binary attachment present in Unreal 4 events containing event context information.
@@ -356,7 +351,6 @@ pub enum AttachmentType {
356351 /// [`symbolic_unreal::Unreal4Context`].
357352 ///
358353 /// [`symbolic_unreal::Unreal4Context`]: https://docs.rs/symbolic/*/symbolic/unreal/struct.Unreal4Context.html
359- #[ serde( rename = "unreal.context" ) ]
360354 UnrealContext ,
361355
362356 /// This is a binary attachment present in Unreal 4 events containing event Logs.
@@ -365,8 +359,11 @@ pub enum AttachmentType {
365359 /// [`symbolic_unreal::Unreal4LogEntry`].
366360 ///
367361 /// [`symbolic_unreal::Unreal4LogEntry`]: https://docs.rs/symbolic/*/symbolic/unreal/struct.Unreal4LogEntry.html
368- #[ serde( rename = "unreal.logs" ) ]
369362 UnrealLogs ,
363+
364+ /// Unknown attachment type, forwarded for compatibility.
365+ /// Attachments with this type will be dropped if `accept_unknown_items` is set to false.
366+ Unknown ( String ) ,
370367}
371368
372369impl Default for AttachmentType {
@@ -375,6 +372,43 @@ impl Default for AttachmentType {
375372 }
376373}
377374
375+ impl fmt:: Display for AttachmentType {
376+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
377+ match self {
378+ AttachmentType :: Attachment => write ! ( f, "event.attachment" ) ,
379+ AttachmentType :: Minidump => write ! ( f, "event.minidump" ) ,
380+ AttachmentType :: AppleCrashReport => write ! ( f, "event.applecrashreport" ) ,
381+ AttachmentType :: EventPayload => write ! ( f, "event.payload" ) ,
382+ AttachmentType :: Breadcrumbs => write ! ( f, "event.breadcrumbs" ) ,
383+ AttachmentType :: UnrealContext => write ! ( f, "unreal.context" ) ,
384+ AttachmentType :: UnrealLogs => write ! ( f, "unreal.logs" ) ,
385+ AttachmentType :: Unknown ( s) => s. fmt ( f) ,
386+ }
387+ }
388+ }
389+
390+ impl std:: str:: FromStr for AttachmentType {
391+ type Err = std:: convert:: Infallible ;
392+
393+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
394+ Ok ( match s {
395+ "event.attachment" => AttachmentType :: Attachment ,
396+ "event.minidump" => AttachmentType :: Minidump ,
397+ "event.applecrashreport" => AttachmentType :: AppleCrashReport ,
398+ "event.payload" => AttachmentType :: EventPayload ,
399+ "event.breadcrumbs" => AttachmentType :: Breadcrumbs ,
400+ "unreal.context" => AttachmentType :: UnrealContext ,
401+ "unreal.logs" => AttachmentType :: UnrealLogs ,
402+ other => AttachmentType :: Unknown ( other. to_owned ( ) ) ,
403+ } )
404+ }
405+ }
406+
407+ relay_common:: impl_str_serde!(
408+ AttachmentType ,
409+ "an attachment type (see sentry develop docs)"
410+ ) ;
411+
378412fn is_false ( val : & bool ) -> bool {
379413 !* val
380414}
@@ -491,9 +525,9 @@ impl Item {
491525 }
492526
493527 /// Returns the attachment type if this item is an attachment.
494- pub fn attachment_type ( & self ) -> Option < AttachmentType > {
528+ pub fn attachment_type ( & self ) -> Option < & AttachmentType > {
495529 // TODO: consider to replace this with an ItemType?
496- self . headers . attachment_type
530+ self . headers . attachment_type . as_ref ( )
497531 }
498532
499533 /// Sets the attachment type of this item.
@@ -607,15 +641,21 @@ impl Item {
607641
608642 // Attachments are only event items if they are crash reports or if they carry partial
609643 // event payloads. Plain attachments never create event payloads.
610- ItemType :: Attachment => match self . attachment_type ( ) . unwrap_or_default ( ) {
611- AttachmentType :: AppleCrashReport
612- | AttachmentType :: Minidump
613- | AttachmentType :: EventPayload
614- | AttachmentType :: Breadcrumbs => true ,
615- AttachmentType :: Attachment
616- | AttachmentType :: UnrealContext
617- | AttachmentType :: UnrealLogs => false ,
618- } ,
644+ ItemType :: Attachment => {
645+ match self . attachment_type ( ) . unwrap_or ( & AttachmentType :: default ( ) ) {
646+ AttachmentType :: AppleCrashReport
647+ | AttachmentType :: Minidump
648+ | AttachmentType :: EventPayload
649+ | AttachmentType :: Breadcrumbs => true ,
650+ AttachmentType :: Attachment
651+ | AttachmentType :: UnrealContext
652+ | AttachmentType :: UnrealLogs => false ,
653+ // When an outdated Relay instance forwards an unknown attachment type for compatibility,
654+ // we assume that the attachment does not create a new event. This will make it hard
655+ // to introduce new attachment types which _do_ create a new event.
656+ AttachmentType :: Unknown ( _) => false ,
657+ }
658+ }
619659
620660 // Form data items may contain partial event payloads, but those are only ever valid if
621661 // they occur together with an explicit event item, such as a minidump or apple crash
0 commit comments