@@ -54,14 +54,6 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
5454 const eventType = event . type || 'event' ;
5555 const useEnvelope = eventType === 'transaction' || api . forceEnvelope ( ) ;
5656
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-
6557 const req : SentryRequest = {
6658 body : JSON . stringify ( sdkInfo ? enhanceEventWithSdkInfo ( event , api . metadata . sdk ) : event ) ,
6759 type : eventType ,
@@ -75,18 +67,23 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
7567 // deserialization. Instead, we only implement a minimal subset of the spec to
7668 // serialize events inline here.
7769 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+
7878 const envelopeHeaders = JSON . stringify ( {
7979 event_id : event . event_id ,
8080 sent_at : new Date ( ) . toISOString ( ) ,
8181 ...( sdkInfo && { sdk : sdkInfo } ) ,
8282 ...( api . forceEnvelope ( ) && { dsn : api . getDsn ( ) . toString ( ) } ) ,
8383 } ) ;
84- const itemHeaders = JSON . stringify ( {
85- type : eventType ,
8684
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 ,
9087
9188 // The content-type is assumed to be 'application/json' and not part of
9289 // 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 {
10198 // size and to reduce request body size.
10299 //
103100 // 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+
105110 // The trailing newline is optional. We intentionally don't send it to avoid
106111 // sending unnecessary bytes.
107112 //
0 commit comments