@@ -4,7 +4,7 @@ use std::fmt::{self, Display};
44use serde:: { Serialize , Serializer } ;
55
66use crate :: processor:: ProcessValue ;
7- use crate :: protocol:: { SpanId , Timestamp , TraceId } ;
7+ use crate :: protocol:: { Attribute , SpanId , Timestamp , TraceId } ;
88
99#[ derive( Clone , Debug , Default , PartialEq , Empty , FromValue , IntoValue , ProcessValue ) ]
1010#[ metastructure( process_func = "process_ourlog" , value_type = "OurLog" ) ]
@@ -31,7 +31,7 @@ pub struct OurLog {
3131
3232 /// Arbitrary attributes on a log.
3333 #[ metastructure( pii = "true" , trim = false ) ]
34- pub attributes : Annotated < Object < OurLogAttribute > > ,
34+ pub attributes : Annotated < Object < Attribute > > ,
3535
3636 /// Additional arbitrary fields for forwards compatibility.
3737 #[ metastructure( additional_properties, retain = true , pii = "maybe" ) ]
@@ -44,127 +44,6 @@ impl OurLog {
4444 }
4545}
4646
47- #[ derive( Clone , PartialEq , Empty , FromValue , IntoValue , ProcessValue ) ]
48- pub struct OurLogAttribute {
49- #[ metastructure( flatten) ]
50- pub value : OurLogAttributeValue ,
51-
52- /// Additional arbitrary fields for forwards compatibility.
53- #[ metastructure( additional_properties) ]
54- pub other : Object < Value > ,
55- }
56-
57- impl OurLogAttribute {
58- pub fn new ( attribute_type : OurLogAttributeType , value : Value ) -> Self {
59- Self {
60- value : OurLogAttributeValue {
61- ty : Annotated :: new ( attribute_type) ,
62- value : Annotated :: new ( value) ,
63- } ,
64- other : Object :: new ( ) ,
65- }
66- }
67- }
68-
69- impl fmt:: Debug for OurLogAttribute {
70- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
71- f. debug_struct ( "OurLogAttribute" )
72- . field ( "value" , & self . value . value )
73- . field ( "type" , & self . value . ty )
74- . field ( "other" , & self . other )
75- . finish ( )
76- }
77- }
78-
79- #[ derive( Debug , Clone , PartialEq , Empty , FromValue , IntoValue , ProcessValue ) ]
80- pub struct OurLogAttributeValue {
81- #[ metastructure( field = "type" , required = true , trim = false ) ]
82- pub ty : Annotated < OurLogAttributeType > ,
83- #[ metastructure( required = true , pii = "true" ) ]
84- pub value : Annotated < Value > ,
85- }
86-
87- #[ derive( Debug , Clone , PartialEq , Eq ) ]
88- pub enum OurLogAttributeType {
89- Boolean ,
90- Integer ,
91- Double ,
92- String ,
93- Unknown ( String ) ,
94- }
95-
96- impl ProcessValue for OurLogAttributeType { }
97-
98- impl OurLogAttributeType {
99- pub fn as_str ( & self ) -> & str {
100- match self {
101- Self :: Boolean => "boolean" ,
102- Self :: Integer => "integer" ,
103- Self :: Double => "double" ,
104- Self :: String => "string" ,
105- Self :: Unknown ( value) => value,
106- }
107- }
108-
109- pub fn unknown_string ( ) -> String {
110- "unknown" . to_string ( )
111- }
112- }
113-
114- impl fmt:: Display for OurLogAttributeType {
115- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
116- write ! ( f, "{}" , self . as_str( ) )
117- }
118- }
119-
120- impl From < String > for OurLogAttributeType {
121- fn from ( value : String ) -> Self {
122- match value. as_str ( ) {
123- "boolean" => Self :: Boolean ,
124- "integer" => Self :: Integer ,
125- "double" => Self :: Double ,
126- "string" => Self :: String ,
127- _ => Self :: Unknown ( value) ,
128- }
129- }
130- }
131-
132- impl Empty for OurLogAttributeType {
133- #[ inline]
134- fn is_empty ( & self ) -> bool {
135- false
136- }
137- }
138-
139- impl FromValue for OurLogAttributeType {
140- fn from_value ( value : Annotated < Value > ) -> Annotated < Self > {
141- match String :: from_value ( value) {
142- Annotated ( Some ( value) , meta) => Annotated ( Some ( value. into ( ) ) , meta) ,
143- Annotated ( None , meta) => Annotated ( None , meta) ,
144- }
145- }
146- }
147-
148- impl IntoValue for OurLogAttributeType {
149- fn into_value ( self ) -> Value
150- where
151- Self : Sized ,
152- {
153- Value :: String ( match self {
154- Self :: Unknown ( s) => s,
155- s => s. to_string ( ) ,
156- } )
157- }
158-
159- fn serialize_payload < S > ( & self , s : S , _behavior : SkipSerialization ) -> Result < S :: Ok , S :: Error >
160- where
161- Self : Sized ,
162- S : serde:: Serializer ,
163- {
164- serde:: ser:: Serialize :: serialize ( self . as_str ( ) , s)
165- }
166- }
167-
16847#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
16948pub enum OurLogLevel {
17049 Trace ,
@@ -289,7 +168,7 @@ mod tests {
289168 }"# ;
290169
291170 let data = Annotated :: < OurLog > :: from_json ( json) . unwrap ( ) ;
292- insta:: assert_debug_snapshot!( data, @r#"
171+ insta:: assert_debug_snapshot!( data, @r### "
293172 OurLog {
294173 timestamp: Timestamp(
295174 2018-12-13T16:51:00Z,
@@ -301,49 +180,49 @@ mod tests {
301180 level: Info,
302181 body: "Example log record",
303182 attributes: {
304- "boolean.attribute": OurLogAttribute {
183+ "boolean.attribute": Attribute {
305184 value: Bool(
306185 true,
307186 ),
308187 type: Boolean,
309188 other: {},
310189 },
311- "double.attribute": OurLogAttribute {
190+ "double.attribute": Attribute {
312191 value: F64(
313192 1.23,
314193 ),
315194 type: Double,
316195 other: {},
317196 },
318- "sentry.observed_timestamp_nanos": OurLogAttribute {
197+ "sentry.observed_timestamp_nanos": Attribute {
319198 value: String(
320199 "1544712660300000000",
321200 ),
322201 type: Integer,
323202 other: {},
324203 },
325- "sentry.severity_number": OurLogAttribute {
204+ "sentry.severity_number": Attribute {
326205 value: String(
327206 "10",
328207 ),
329208 type: Integer,
330209 other: {},
331210 },
332- "sentry.severity_text": OurLogAttribute {
211+ "sentry.severity_text": Attribute {
333212 value: String(
334213 "info",
335214 ),
336215 type: String,
337216 other: {},
338217 },
339- "sentry.trace_flags": OurLogAttribute {
218+ "sentry.trace_flags": Attribute {
340219 value: String(
341220 "10",
342221 ),
343222 type: Integer,
344223 other: {},
345224 },
346- "string.attribute": OurLogAttribute {
225+ "string.attribute": Attribute {
347226 value: String(
348227 "some string",
349228 ),
@@ -353,7 +232,7 @@ mod tests {
353232 },
354233 other: {},
355234 }
356- "# ) ;
235+ "### ) ;
357236
358237 insta:: assert_json_snapshot!( SerializableAnnotated ( & data) , @r###"
359238 {
0 commit comments