@@ -76,11 +76,14 @@ pub fn transfer_id(
76
76
let contexts = event. contexts . get_or_insert_with ( Contexts :: new) ;
77
77
contexts. add ( ProfileContext {
78
78
profile_id : Annotated :: new ( profile_id) ,
79
+ ..ProfileContext :: default ( )
79
80
} ) ;
80
81
}
81
82
None => {
82
83
if let Some ( contexts) = event. contexts . value_mut ( ) {
83
- contexts. remove :: < ProfileContext > ( ) ;
84
+ if let Some ( profile_context) = contexts. get_mut :: < ProfileContext > ( ) {
85
+ profile_context. profile_id = Annotated :: empty ( ) ;
86
+ }
84
87
}
85
88
}
86
89
}
@@ -239,6 +242,7 @@ mod tests {
239
242
profile_id: EventId(
240
243
012d836b-15bb-49d7-bbf9-9e64295d995b,
241
244
),
245
+ profiler_id: ~,
242
246
}
243
247
"### ) ;
244
248
}
@@ -293,4 +297,88 @@ mod tests {
293
297
let envelope_response = processor. process ( message) . unwrap ( ) ;
294
298
assert ! ( envelope_response. envelope. is_none( ) ) ;
295
299
}
300
+
301
+ #[ tokio:: test]
302
+ async fn test_profile_id_removed_profiler_id_kept ( ) {
303
+ // Setup
304
+ let processor = create_test_processor ( Default :: default ( ) ) ;
305
+ let event_id = EventId :: new ( ) ;
306
+ let dsn = "https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42"
307
+ . parse ( )
308
+ . unwrap ( ) ;
309
+ let request_meta = RequestMeta :: new ( dsn) ;
310
+ let mut envelope = Envelope :: from_request ( Some ( event_id) , request_meta) ;
311
+
312
+ // Add a valid transaction item.
313
+ envelope. add_item ( {
314
+ let mut item = Item :: new ( ItemType :: Transaction ) ;
315
+
316
+ item. set_payload (
317
+ ContentType :: Json ,
318
+ r#"{
319
+ "type": "transaction",
320
+ "transaction": "/foo/",
321
+ "timestamp": 946684810.0,
322
+ "start_timestamp": 946684800.0,
323
+ "contexts": {
324
+ "trace": {
325
+ "trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
326
+ "span_id": "fa90fdead5f74053",
327
+ "op": "http.server",
328
+ "type": "trace"
329
+ },
330
+ "profile": {
331
+ "profile_id": "4c79f60c11214eb38604f4ae0781bfb2",
332
+ "profiler_id": "4c79f60c11214eb38604f4ae0781bfb2",
333
+ "type": "profile"
334
+ }
335
+ },
336
+ "transaction_info": {
337
+ "source": "url"
338
+ }
339
+ }"# ,
340
+ ) ;
341
+ item
342
+ } ) ;
343
+
344
+ let mut project_state = ProjectState :: allowed ( ) ;
345
+ project_state. config . features . 0 . insert ( Feature :: Profiling ) ;
346
+
347
+ let mut envelopes = ProcessingGroup :: split_envelope ( * envelope) ;
348
+ assert_eq ! ( envelopes. len( ) , 1 ) ;
349
+
350
+ let ( group, envelope) = envelopes. pop ( ) . unwrap ( ) ;
351
+ let envelope = ManagedEnvelope :: standalone ( envelope, Addr :: dummy ( ) , Addr :: dummy ( ) , group) ;
352
+
353
+ let message = ProcessEnvelope {
354
+ envelope,
355
+ project_state : Arc :: new ( project_state) ,
356
+ sampling_project_state : None ,
357
+ reservoir_counters : ReservoirCounters :: default ( ) ,
358
+ } ;
359
+
360
+ let envelope_response = processor. process ( message) . unwrap ( ) ;
361
+ let ctx = envelope_response. envelope . unwrap ( ) ;
362
+ let new_envelope = ctx. envelope ( ) ;
363
+
364
+ // Get the re-serialized context.
365
+ let item = new_envelope
366
+ . get_item_by ( |item| item. ty ( ) == & ItemType :: Transaction )
367
+ . unwrap ( ) ;
368
+ let transaction = Annotated :: < Event > :: from_json_bytes ( & item. payload ( ) ) . unwrap ( ) ;
369
+ let context = transaction
370
+ . value ( )
371
+ . unwrap ( )
372
+ . context :: < ProfileContext > ( )
373
+ . unwrap ( ) ;
374
+
375
+ assert_debug_snapshot ! ( context, @r###"
376
+ ProfileContext {
377
+ profile_id: ~,
378
+ profiler_id: EventId(
379
+ 4c79f60c-1121-4eb3-8604-f4ae0781bfb2,
380
+ ),
381
+ }
382
+ "### ) ;
383
+ }
296
384
}
0 commit comments