@@ -54,14 +54,6 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
54
54
const eventType = event . type || 'event' ;
55
55
const useEnvelope = eventType === 'transaction' || api . forceEnvelope ( ) ;
56
56
57
- const { transactionSampling, ...metadata } = event . debug_meta || { } ;
58
- const { method : samplingMethod , rate : sampleRate } = transactionSampling || { } ;
59
- if ( Object . keys ( metadata ) . length === 0 ) {
60
- delete event . debug_meta ;
61
- } else {
62
- event . debug_meta = metadata ;
63
- }
64
-
65
57
const req : SentryRequest = {
66
58
body : JSON . stringify ( sdkInfo ? enhanceEventWithSdkInfo ( event , api . metadata . sdk ) : event ) ,
67
59
type : eventType ,
@@ -75,18 +67,23 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
75
67
// deserialization. Instead, we only implement a minimal subset of the spec to
76
68
// serialize events inline here.
77
69
if ( useEnvelope ) {
70
+ // Extract header information from event
71
+ const { transactionSampling, ...metadata } = event . debug_meta || { } ;
72
+ if ( Object . keys ( metadata ) . length === 0 ) {
73
+ delete event . debug_meta ;
74
+ } else {
75
+ event . debug_meta = metadata ;
76
+ }
77
+
78
78
const envelopeHeaders = JSON . stringify ( {
79
79
event_id : event . event_id ,
80
80
sent_at : new Date ( ) . toISOString ( ) ,
81
81
...( sdkInfo && { sdk : sdkInfo } ) ,
82
82
...( api . forceEnvelope ( ) && { dsn : api . getDsn ( ) . toString ( ) } ) ,
83
83
} ) ;
84
- const itemHeaders = JSON . stringify ( {
85
- type : eventType ,
86
84
87
- // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
88
- // explicitly-set sampling decisions). Are we good with that?
89
- sample_rates : [ { id : samplingMethod , rate : sampleRate } ] ,
85
+ const itemHeaderEntries : { [ key : string ] : unknown } = {
86
+ type : eventType ,
90
87
91
88
// The content-type is assumed to be 'application/json' and not part of
92
89
// the current spec for transaction items, so we don't bloat the request
@@ -101,7 +98,15 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
101
98
// size and to reduce request body size.
102
99
//
103
100
// length: new TextEncoder().encode(req.body).length,
104
- } ) ;
101
+ } ;
102
+
103
+ if ( eventType === 'transaction' ) {
104
+ // TODO: Right now, `sampleRate` will be undefined in the cases of inheritance and explicitly-set sampling decisions.
105
+ itemHeaderEntries . sample_rates = [ { id : transactionSampling ?. method , rate : transactionSampling ?. rate } ] ;
106
+ }
107
+
108
+ const itemHeaders = JSON . stringify ( itemHeaderEntries ) ;
109
+
105
110
// The trailing newline is optional. We intentionally don't send it to avoid
106
111
// sending unnecessary bytes.
107
112
//
0 commit comments