@@ -47,15 +47,15 @@ struct ExceptionData {
47
47
}
48
48
#[ derive( Debug , serde:: Deserialize ) ]
49
49
struct RequestData {
50
- method : String ,
50
+ method : Option < String > ,
51
51
url : String ,
52
52
}
53
53
54
54
#[ derive( Debug , serde:: Deserialize , serde:: Serialize , Clone ) ]
55
55
struct ExceptionValue {
56
56
r#type : String ,
57
57
value : Option < String > ,
58
- stacktrace : Stacktrace ,
58
+ stacktrace : Option < Stacktrace > ,
59
59
}
60
60
61
61
#[ derive( Debug , serde:: Deserialize , serde:: Serialize , Clone ) ]
@@ -80,15 +80,8 @@ struct Frame {
80
80
#[ serde( untagged) ]
81
81
#[ serde( rename_all( deserialize = "snake_case" ) ) ]
82
82
enum Metadata {
83
- Error {
84
- filename : String ,
85
- function : String ,
86
- r#type : String ,
87
- value : String ,
88
- } ,
89
- OnlyTitle {
90
- title : String ,
91
- } ,
83
+ Error { r#type : String , value : String } ,
84
+ OnlyTitle { title : String } ,
92
85
}
93
86
94
87
#[ derive( Debug , serde:: Serialize ) ]
@@ -166,90 +159,97 @@ fn should_be_skipped(event: &RawSentryEvent) -> bool {
166
159
fn process_file ( path : & PathBuf ) -> Option < SentryEvent > {
167
160
let file = File :: open ( path) . expect ( "Can not open file" ) ;
168
161
let raw_event: Result < RawSentryEvent , _ > = serde_json:: from_reader ( file) ;
169
- if let Ok ( raw_event) = raw_event {
170
- if should_be_skipped ( & raw_event) {
171
- return None ;
172
- }
173
-
174
- let get_transaction = |tags : & [ Tag ] | -> Option < String > {
175
- for tag in tags {
176
- if tag. key == "transaction" {
177
- return Some ( tag. value . clone ( ) ) ;
178
- }
162
+ match raw_event {
163
+ Ok ( raw_event) => {
164
+ if should_be_skipped ( & raw_event) {
165
+ return None ;
179
166
}
180
- None
181
- } ;
182
- let transaction = get_transaction ( & raw_event. tags ) ;
183
-
184
- let get_endpoint = |entries : & [ Entry ] | -> ( Option < String > , Option < String > ) {
185
- for entry in entries {
186
- match entry {
187
- Entry :: Request {
188
- data : RequestData { method, url } ,
189
- } => {
190
- let path = Url :: parse ( url) . expect ( "Invalid URL" ) . path ( ) . to_owned ( ) ;
191
- return ( Some ( method. clone ( ) ) , Some ( path) ) ;
167
+
168
+ let get_transaction = |tags : & [ Tag ] | -> Option < String > {
169
+ for tag in tags {
170
+ if tag. key == "transaction" {
171
+ return Some ( tag. value . clone ( ) ) ;
192
172
}
193
- Entry :: Message | Entry :: Breadcrumbs | Entry :: Exception { .. } => continue ,
194
173
}
195
- }
196
- // It may be a Gunicorn-level error that is logged differently
197
- if let Some ( ( _, path) ) = raw_event. message . split_once ( "Error handling request " ) {
174
+ None
175
+ } ;
176
+ let transaction = get_transaction ( & raw_event. tags ) ;
177
+
178
+ let get_endpoint = |entries : & [ Entry ] | -> ( Option < String > , Option < String > ) {
198
179
for entry in entries {
199
180
match entry {
200
- // The only place where we can get the HTTP method is local variables in one of the
201
- // stackframes
202
- Entry :: Exception {
203
- data : ExceptionData { values } ,
181
+ Entry :: Request {
182
+ data : RequestData { method, url } ,
204
183
} => {
205
- for ExceptionValue {
206
- stacktrace : Stacktrace { frames } ,
207
- ..
208
- } in values
209
- {
210
- for Frame { vars, .. } in frames {
211
- if let Some ( value) = vars[ "environ" ] [ "REQUEST_METHOD" ] . as_str ( )
212
- {
213
- let method = & value[ 1 ..value. len ( ) - 1 ] ;
214
- return ( Some ( method. to_owned ( ) ) , Some ( path. to_owned ( ) ) ) ;
184
+ if let Some ( method) = method {
185
+ let path = Url :: parse ( url) . expect ( "Invalid URL" ) . path ( ) . to_owned ( ) ;
186
+ return ( Some ( method. clone ( ) ) , Some ( path) ) ;
187
+ }
188
+ }
189
+ Entry :: Message | Entry :: Breadcrumbs | Entry :: Exception { .. } => continue ,
190
+ }
191
+ }
192
+ // It may be a Gunicorn-level error that is logged differently
193
+ if let Some ( ( _, path) ) = raw_event. message . split_once ( "Error handling request " ) {
194
+ for entry in entries {
195
+ match entry {
196
+ // The only place where we can get the HTTP method is local variables in one of the
197
+ // stackframes
198
+ Entry :: Exception {
199
+ data : ExceptionData { values } ,
200
+ } => {
201
+ for ExceptionValue { stacktrace, .. } in values {
202
+ if let Some ( Stacktrace { frames } ) = stacktrace {
203
+ for Frame { vars, .. } in frames {
204
+ if let Some ( value) =
205
+ vars[ "environ" ] [ "REQUEST_METHOD" ] . as_str ( )
206
+ {
207
+ let method = & value[ 1 ..value. len ( ) - 1 ] ;
208
+ return (
209
+ Some ( method. to_owned ( ) ) ,
210
+ Some ( path. to_owned ( ) ) ,
211
+ ) ;
212
+ }
213
+ }
215
214
}
216
215
}
217
216
}
217
+ Entry :: Message | Entry :: Breadcrumbs | Entry :: Request { .. } => continue ,
218
218
}
219
+ }
220
+ } ;
221
+ ( None , None )
222
+ } ;
223
+ let ( method, path) = get_endpoint ( & raw_event. entries ) ;
224
+
225
+ let exceptions = {
226
+ let mut out = Vec :: new ( ) ;
227
+ for entry in & raw_event. entries {
228
+ match entry {
229
+ Entry :: Exception {
230
+ data : ExceptionData { values } ,
231
+ } => out. push ( values. clone ( ) ) ,
219
232
Entry :: Message | Entry :: Breadcrumbs | Entry :: Request { .. } => continue ,
220
233
}
221
234
}
235
+ out
222
236
} ;
223
- ( None , None )
224
- } ;
225
- let ( method, path) = get_endpoint ( & raw_event. entries ) ;
226
-
227
- let exceptions = {
228
- let mut out = Vec :: new ( ) ;
229
- for entry in & raw_event. entries {
230
- match entry {
231
- Entry :: Exception {
232
- data : ExceptionData { values } ,
233
- } => out. push ( values. clone ( ) ) ,
234
- Entry :: Message | Entry :: Breadcrumbs | Entry :: Request { .. } => continue ,
235
- }
236
- }
237
- out
238
- } ;
239
-
240
- Some ( SentryEvent {
241
- event_id : raw_event. event_id ,
242
- group_id : raw_event. group_id ,
243
- title : raw_event. title ,
244
- message : raw_event. message ,
245
- culprit : raw_event. culprit ,
246
- transaction,
247
- method,
248
- path,
249
- exceptions,
250
- metadata : raw_event. metadata ,
251
- } )
252
- } else {
253
- panic ! ( "Invalid file: {:?}" , path) ;
237
+
238
+ Some ( SentryEvent {
239
+ event_id : raw_event. event_id ,
240
+ group_id : raw_event. group_id ,
241
+ title : raw_event. title ,
242
+ message : raw_event. message ,
243
+ culprit : raw_event. culprit ,
244
+ transaction,
245
+ method,
246
+ path,
247
+ exceptions,
248
+ metadata : raw_event. metadata ,
249
+ } )
250
+ }
251
+ Err ( error) => {
252
+ panic ! ( "Invalid file: {:?} ({})" , path, error) ;
253
+ }
254
254
}
255
255
}
0 commit comments