Skip to content

Commit

Permalink
Revert Sidecar to accept all envelopes
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT committed Nov 25, 2023
1 parent 4284201 commit 58a2cb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-rockets-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/sidecar': patch
---

Accept all envelopes
33 changes: 1 addition & 32 deletions packages/sidecar/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,7 @@ function handleStreamRequest(req: IncomingMessage, res: ServerResponse, buffer:
if (chunk !== null) body += chunk;
});
req.on('end', () => {
if (req.headers['content-type'] == 'application/x-sentry-envelope') {
if (containsKnownEnvelopeType(body)) {
buffer.put([`${req.headers['content-type']}`, body]);
}
} else {
// It's not an Sentry envelope, so we just put it in the buffer
buffer.put([`${req.headers['content-type']}`, body]);
}
buffer.put([`${req.headers['content-type']}`, body]);
res.writeHead(204, {
'Cache-Control': 'no-cache',
...getCorsHeader(),
Expand All @@ -181,30 +174,6 @@ function handleStreamRequest(req: IncomingMessage, res: ServerResponse, buffer:
}
}

function containsKnownEnvelopeType(body: string): boolean {
const [...rawEntries] = body.split(/\n/gm);

const items = [];
for (let i = 0; i < rawEntries.length; i++) {
if (!rawEntries[i]) {
continue;
}
// not ideal we json parse envelope entries here but it's the easiest way to get the type
items.push(JSON.parse(rawEntries[i]));
}

const allowedTypes = ['event', 'transaction'];
const types = items.map(item => item.type);

for (let i = 0; i < types.length; i++) {
if (allowedTypes.includes(types[i])) {
return true;
}
}

return false;
}

function startServer(buffer: MessageBuffer<Payload>, port: number): Server {
const server = createServer((req, res) => {
handleStreamRequest(req, res, buffer);
Expand Down

0 comments on commit 58a2cb3

Please sign in to comment.