@@ -61,12 +61,9 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
6161 url : useEnvelope ? api . getEnvelopeEndpointWithUrlEncodedAuth ( ) : api . getStoreEndpointWithUrlEncodedAuth ( ) ,
6262 } ;
6363
64- // https://develop.sentry.dev/sdk/envelopes/
65-
66- // Since we don't need to manipulate envelopes nor store them, there is no
67- // exported concept of an Envelope with operations including serialization and
68- // deserialization. Instead, we only implement a minimal subset of the spec to
69- // serialize events inline here.
64+ // Since we don't need to manipulate envelopes nor store them, there is no exported concept of an Envelope with
65+ // operations including serialization and deserialization. Instead, we only implement a minimal subset of the spec to
66+ // serialize events inline here. See https://develop.sentry.dev/sdk/envelopes/.
7067 if ( useEnvelope ) {
7168 // Extract header information from event
7269 const { transactionSampling, tracestate, ...metadata } = event . debug_meta || { } ;
@@ -101,19 +98,17 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
10198 const itemHeaderEntries : { [ key : string ] : unknown } = {
10299 type : eventType ,
103100
104- // The content-type is assumed to be 'application/json' and not part of
105- // the current spec for transaction items, so we don't bloat the request
106- // body with it.
107- //
108- // content_type: 'application/json',
101+ // Note: as mentioned above, `content_type` and `length` were left out on purpose.
109102 //
110- // The length is optional. It must be the number of bytes in req.Body
111- // encoded as UTF-8. Since the server can figure this out and would
112- // otherwise refuse events that report the length incorrectly, we decided
113- // not to send the length to avoid problems related to reporting the wrong
114- // size and to reduce request body size.
103+ // `content_type`:
104+ // Assumed to be 'application/json' and not part of the current spec for transaction items. No point in bloating the
105+ // request body with it. (Would be `content_type: 'application/json'`.)
115106 //
116- // length: new TextEncoder().encode(req.body).length,
107+ // `length`:
108+ // Optional and equal to the number of bytes in `req.Body` encoded as UTF-8. Since the server can figure this out
109+ // and will refuse events that report the length incorrectly, we decided not to send the length to reduce request
110+ // body size and to avoid problems related to reporting the wrong size.(Would be
111+ // `length: new TextEncoder().encode(req.body).length`.)
117112 } ;
118113
119114 if ( eventType === 'transaction' ) {
@@ -123,10 +118,8 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
123118
124119 const itemHeaders = JSON . stringify ( itemHeaderEntries ) ;
125120
126- // The trailing newline is optional. We intentionally don't send it to avoid
127- // sending unnecessary bytes.
128- //
129- // const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}\n`;
121+ // The trailing newline is optional; leave it off to avoid sending unnecessary bytes. (Would be
122+ // `const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}\n`;`.)
130123 const envelope = `${ envelopeHeaders } \n${ itemHeaders } \n${ req . body } ` ;
131124 req . body = envelope ;
132125 }
0 commit comments