@@ -61,12 +61,9 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
61
61
url : useEnvelope ? api . getEnvelopeEndpointWithUrlEncodedAuth ( ) : api . getStoreEndpointWithUrlEncodedAuth ( ) ,
62
62
} ;
63
63
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/.
70
67
if ( useEnvelope ) {
71
68
// Extract header information from event
72
69
const { transactionSampling, tracestate, ...metadata } = event . debug_meta || { } ;
@@ -101,19 +98,17 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
101
98
const itemHeaderEntries : { [ key : string ] : unknown } = {
102
99
type : eventType ,
103
100
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.
109
102
//
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'`.)
115
106
//
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`.)
117
112
} ;
118
113
119
114
if ( eventType === 'transaction' ) {
@@ -123,10 +118,8 @@ export function eventToSentryRequest(event: Event, api: API): SentryRequest {
123
118
124
119
const itemHeaders = JSON . stringify ( itemHeaderEntries ) ;
125
120
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`;`.)
130
123
const envelope = `${ envelopeHeaders } \n${ itemHeaders } \n${ req . body } ` ;
131
124
req . body = envelope ;
132
125
}
0 commit comments