Skip to content

Commit 13b4729

Browse files
author
Luca Forstner
authored
test(e2e): Decode gzipped envelopes in E2E tests (#8926)
1 parent 1ca67d1 commit 13b4729

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

packages/e2e-tests/test-applications/nextjs-app-dir/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ next-env.d.ts
4141
.sentryclirc
4242

4343
.vscode
44+
45+
test-results

packages/e2e-tests/test-applications/nextjs-app-dir/event-proxy-server.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { AddressInfo } from 'net';
77
import * as os from 'os';
88
import * as path from 'path';
99
import * as util from 'util';
10+
import * as zlib from 'zlib';
1011

1112
const readFile = util.promisify(fs.readFile);
1213
const writeFile = util.promisify(fs.writeFile);
@@ -44,8 +45,12 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
4445
});
4546

4647
proxyRequest.addListener('end', () => {
47-
const proxyRequestBody = Buffer.concat(proxyRequestChunks).toString();
48-
const envelopeHeader: { dsn?: string } = JSON.parse(proxyRequestBody.split('\n')[0]);
48+
const proxyRequestBody =
49+
proxyRequest.headers['content-encoding'] === 'gzip'
50+
? zlib.gunzipSync(Buffer.concat(proxyRequestChunks)).toString()
51+
: Buffer.concat(proxyRequestChunks).toString();
52+
53+
let envelopeHeader = JSON.parse(proxyRequestBody.split('\n')[0]);
4954

5055
if (!envelopeHeader.dsn) {
5156
throw new Error('[event-proxy-server] No dsn on envelope header. Please set tunnel option.');
@@ -71,12 +76,11 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
7176

7277
sentryResponse.addListener('end', () => {
7378
eventCallbackListeners.forEach(listener => {
74-
const rawProxyRequestBody = Buffer.concat(proxyRequestChunks).toString();
7579
const rawSentryResponseBody = Buffer.concat(sentryResponseChunks).toString();
7680

7781
const data: SentryRequestCallbackData = {
78-
envelope: parseEnvelope(rawProxyRequestBody, new TextEncoder(), new TextDecoder()),
79-
rawProxyRequestBody,
82+
envelope: parseEnvelope(proxyRequestBody, new TextEncoder(), new TextDecoder()),
83+
rawProxyRequestBody: proxyRequestBody,
8084
rawSentryResponseBody,
8185
sentryResponseStatusCode: sentryResponse.statusCode,
8286
};

packages/e2e-tests/test-applications/nextjs-app-dir/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@types/node": "18.11.17",
2020
"@types/react": "18.0.26",
2121
"@types/react-dom": "18.0.9",
22-
"next": "13.2.4",
22+
"next": "13.4.19",
2323
"react": "18.2.0",
2424
"react-dom": "18.2.0",
2525
"typescript": "4.9.5",

packages/e2e-tests/test-applications/nextjs-app-dir/tests/edge-route.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { test, expect } from '@playwright/test';
22
import { waitForTransaction, waitForError } from '../event-proxy-server';
33

44
test('Should create a transaction for edge routes', async ({ request }) => {
5-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
6-
75
const edgerouteTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => {
86
return (
97
transactionEvent?.transaction === 'GET /api/edge-endpoint' && transactionEvent?.contexts?.trace?.status === 'ok'
@@ -21,8 +19,6 @@ test('Should create a transaction for edge routes', async ({ request }) => {
2119
});
2220

2321
test('Should create a transaction with error status for faulty edge routes', async ({ request }) => {
24-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
25-
2622
const edgerouteTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => {
2723
return (
2824
transactionEvent?.transaction === 'GET /api/error-edge-endpoint' &&
@@ -42,8 +38,6 @@ test('Should create a transaction with error status for faulty edge routes', asy
4238
});
4339

4440
test('Should record exceptions for faulty edge routes', async ({ request }) => {
45-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
46-
4741
const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => {
4842
return errorEvent?.exception?.values?.[0]?.value === 'Edge Route Error';
4943
});

packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { test, expect } from '@playwright/test';
22
import { waitForTransaction, waitForError } from '../event-proxy-server';
33

44
test('Should create a transaction for middleware', async ({ request }) => {
5-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
6-
75
const middlewareTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => {
86
return transactionEvent?.transaction === 'middleware' && transactionEvent?.contexts?.trace?.status === 'ok';
97
});
@@ -19,8 +17,6 @@ test('Should create a transaction for middleware', async ({ request }) => {
1917
});
2018

2119
test('Should create a transaction with error status for faulty middleware', async ({ request }) => {
22-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
23-
2420
const middlewareTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => {
2521
return (
2622
transactionEvent?.transaction === 'middleware' && transactionEvent?.contexts?.trace?.status === 'internal_error'
@@ -39,8 +35,6 @@ test('Should create a transaction with error status for faulty middleware', asyn
3935
});
4036

4137
test('Records exceptions happening in middleware', async ({ request }) => {
42-
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
43-
4438
const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => {
4539
return errorEvent?.exception?.values?.[0]?.value === 'Middleware Error';
4640
});

packages/e2e-tests/test-applications/sveltekit/event-proxy-server.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { AddressInfo } from 'net';
77
import * as os from 'os';
88
import * as path from 'path';
99
import * as util from 'util';
10+
import * as zlib from 'zlib';
1011

1112
const readFile = util.promisify(fs.readFile);
1213
const writeFile = util.promisify(fs.writeFile);
@@ -44,8 +45,12 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
4445
});
4546

4647
proxyRequest.addListener('end', () => {
47-
const proxyRequestBody = Buffer.concat(proxyRequestChunks).toString();
48-
const envelopeHeader: { dsn?: string } = JSON.parse(proxyRequestBody.split('\n')[0]);
48+
const proxyRequestBody =
49+
proxyRequest.headers['content-encoding'] === 'gzip'
50+
? zlib.gunzipSync(Buffer.concat(proxyRequestChunks)).toString()
51+
: Buffer.concat(proxyRequestChunks).toString();
52+
53+
let envelopeHeader = JSON.parse(proxyRequestBody.split('\n')[0]);
4954

5055
if (!envelopeHeader.dsn) {
5156
throw new Error('[event-proxy-server] No dsn on envelope header. Please set tunnel option.');
@@ -71,12 +76,11 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
7176

7277
sentryResponse.addListener('end', () => {
7378
eventCallbackListeners.forEach(listener => {
74-
const rawProxyRequestBody = Buffer.concat(proxyRequestChunks).toString();
7579
const rawSentryResponseBody = Buffer.concat(sentryResponseChunks).toString();
7680

7781
const data: SentryRequestCallbackData = {
78-
envelope: parseEnvelope(rawProxyRequestBody, new TextEncoder(), new TextDecoder()),
79-
rawProxyRequestBody,
82+
envelope: parseEnvelope(proxyRequestBody, new TextEncoder(), new TextDecoder()),
83+
rawProxyRequestBody: proxyRequestBody,
8084
rawSentryResponseBody,
8185
sentryResponseStatusCode: sentryResponse.statusCode,
8286
};

0 commit comments

Comments
 (0)