|
1 | | -import { |
2 | | - Event, |
3 | | - SdkInfo, |
4 | | - SentryRequest, |
5 | | - SentryRequestType, |
6 | | - Session, |
7 | | - SessionAggregates, |
8 | | - SessionEnvelope, |
9 | | - SessionItem, |
10 | | -} from '@sentry/types'; |
| 1 | +import { Event, SdkInfo, SentryRequest, Session, SessionAggregates, SessionEnvelope, SessionItem } from '@sentry/types'; |
11 | 2 | import { createEnvelope, dsnToString, normalize, serializeEnvelope } from '@sentry/utils'; |
12 | 3 |
|
13 | 4 | import { APIDetails, getEnvelopeEndpointWithUrlEncodedAuth, getStoreEndpointWithUrlEncodedAuth } from './api'; |
@@ -138,39 +129,21 @@ export function eventToSentryRequest(event: Event, api: APIDetails): SentryReque |
138 | 129 | // deserialization. Instead, we only implement a minimal subset of the spec to |
139 | 130 | // serialize events inline here. |
140 | 131 | if (useEnvelope) { |
141 | | - const envelopeHeaders = JSON.stringify({ |
142 | | - event_id: event.event_id, |
| 132 | + const envelopeHeaders = { |
| 133 | + event_id: event.event_id as string, |
143 | 134 | sent_at: new Date().toISOString(), |
144 | 135 | ...(sdkInfo && { sdk: sdkInfo }), |
145 | 136 | ...(!!api.tunnel && { dsn: dsnToString(api.dsn) }), |
146 | | - }); |
147 | | - const itemHeaders = JSON.stringify({ |
148 | | - type: eventType, |
149 | | - |
150 | | - // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and |
151 | | - // explicitly-set sampling decisions). Are we good with that? |
152 | | - sample_rates: [{ id: samplingMethod, rate: sampleRate }], |
153 | | - |
154 | | - // The content-type is assumed to be 'application/json' and not part of |
155 | | - // the current spec for transaction items, so we don't bloat the request |
156 | | - // body with it. |
157 | | - // |
158 | | - // content_type: 'application/json', |
159 | | - // |
160 | | - // The length is optional. It must be the number of bytes in req.Body |
161 | | - // encoded as UTF-8. Since the server can figure this out and would |
162 | | - // otherwise refuse events that report the length incorrectly, we decided |
163 | | - // not to send the length to avoid problems related to reporting the wrong |
164 | | - // size and to reduce request body size. |
165 | | - // |
166 | | - // length: new TextEncoder().encode(req.body).length, |
167 | | - }); |
168 | | - // The trailing newline is optional. We intentionally don't send it to avoid |
169 | | - // sending unnecessary bytes. |
170 | | - // |
171 | | - // const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}\n`; |
172 | | - const envelope = `${envelopeHeaders}\n${itemHeaders}\n${req.body}`; |
173 | | - req.body = envelope; |
| 137 | + }; |
| 138 | + const eventItem: EventItem = [ |
| 139 | + { |
| 140 | + type: eventType, |
| 141 | + sample_rates: [{ id: samplingMethod, rate: sampleRate }], |
| 142 | + }, |
| 143 | + req.body, |
| 144 | + ]; |
| 145 | + const envelope = createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]); |
| 146 | + req.body = serializeEnvelope(envelope); |
174 | 147 | } |
175 | 148 |
|
176 | 149 | return req; |
|
0 commit comments