Skip to content

Commit eb8eebf

Browse files
committed
[WIP] feat: Send transactions in envelopes
The new Envelope endpoint and format is what we want to use for transactions going forward. TODO: include rationale.
1 parent ea41928 commit eb8eebf

File tree

1 file changed

+21
-2
lines changed
  • packages/node/src/transports

1 file changed

+21
-2
lines changed

packages/node/src/transports/base.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,26 @@ export abstract class BaseTransport implements Transport {
8484
}
8585
return this._buffer.add(
8686
new Promise<Response>((resolve, reject) => {
87-
const req = httpModule.request(this._getRequestOptions(), (res: http.IncomingMessage) => {
87+
const options = this._getRequestOptions();
88+
let payload = JSON.stringify(event);
89+
90+
if (event.type === 'transaction') {
91+
options.path = (options.path || '').replace('/store', '/envelope');
92+
(options.headers || {})['content-type'] = 'application/x-sentry-envelope';
93+
94+
const enveloperHeaders = JSON.stringify({
95+
event_id: event.event_id,
96+
sent_at: null,
97+
});
98+
const itemHeaders = JSON.stringify({
99+
content_type: 'application/json',
100+
type: event.type,
101+
});
102+
const envelope = `${enveloperHeaders}\n${itemHeaders}\n${payload}\n`;
103+
payload = envelope;
104+
}
105+
106+
const req = httpModule.request(options, (res: http.IncomingMessage) => {
88107
const statusCode = res.statusCode || 500;
89108
const status = Status.fromHttpCode(statusCode);
90109

@@ -118,7 +137,7 @@ export abstract class BaseTransport implements Transport {
118137
});
119138
});
120139
req.on('error', reject);
121-
req.end(JSON.stringify(event));
140+
req.end(payload);
122141
}),
123142
);
124143
}

0 commit comments

Comments
 (0)