-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba7aa1c
commit e87d5d1
Showing
11 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/node-fastify-5/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/node-fastify-5/.npmrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
31 changes: 31 additions & 0 deletions
31
dev-packages/e2e-tests/test-applications/node-fastify-5/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "node-fastify-5", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "ts-node src/app.ts", | ||
"test": "playwright test", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"typecheck": "tsc", | ||
"test:build": "pnpm install && pnpm run typecheck", | ||
"test:assert": "pnpm test" | ||
}, | ||
"dependencies": { | ||
"@sentry/node": "latest || *", | ||
"@sentry/types": "latest || *", | ||
"@sentry/core": "latest || *", | ||
"@sentry/utils": "latest || *", | ||
"@sentry/opentelemetry": "latest || *", | ||
"@types/node": "22.7.5", | ||
"fastify": "5.0.0", | ||
"typescript": "5.6.3", | ||
"ts-node": "10.9.2" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/node-fastify-5/playwright.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
const config = getPlaywrightConfig({ | ||
startCommand: `pnpm start`, | ||
}); | ||
|
||
export default config; |
153 changes: 153 additions & 0 deletions
153
dev-packages/e2e-tests/test-applications/node-fastify-5/src/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import type * as S from '@sentry/node'; | ||
const Sentry = require('@sentry/node') as typeof S; | ||
|
||
// We wrap console.warn to find out if a warning is incorrectly logged | ||
console.warn = new Proxy(console.warn, { | ||
apply: function (target, thisArg, argumentsList) { | ||
const msg = argumentsList[0]; | ||
if (typeof msg === 'string' && msg.startsWith('[Sentry]')) { | ||
console.error(`Sentry warning was triggered: ${msg}`); | ||
process.exit(1); | ||
} | ||
|
||
return target.apply(thisArg, argumentsList); | ||
}, | ||
}); | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.E2E_TEST_DSN, | ||
integrations: [], | ||
tracesSampleRate: 1, | ||
tunnel: 'http://localhost:3031/', // proxy server | ||
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'], | ||
}); | ||
|
||
import type * as H from 'http'; | ||
import type * as F from 'fastify'; | ||
|
||
// Make sure fastify is imported after Sentry is initialized | ||
const { fastify } = require('fastify') as typeof F; | ||
const http = require('http') as typeof H; | ||
|
||
const app = fastify(); | ||
const port = 3030; | ||
const port2 = 3040; | ||
|
||
Sentry.setupFastifyErrorHandler(app); | ||
|
||
app.get('/test-success', function (_req, res) { | ||
res.send({ version: 'v1' }); | ||
}); | ||
|
||
app.get<{ Params: { param: string } }>('/test-param/:param', function (req, res) { | ||
res.send({ paramWas: req.params.param }); | ||
}); | ||
|
||
app.get<{ Params: { id: string } }>('/test-inbound-headers/:id', function (req, res) { | ||
const headers = req.headers; | ||
|
||
res.send({ headers, id: req.params.id }); | ||
}); | ||
|
||
app.get<{ Params: { id: string } }>('/test-outgoing-http/:id', async function (req, res) { | ||
const id = req.params.id; | ||
const data = await makeHttpRequest(`http://localhost:3030/test-inbound-headers/${id}`); | ||
|
||
res.send(data); | ||
}); | ||
|
||
app.get<{ Params: { id: string } }>('/test-outgoing-fetch/:id', async function (req, res) { | ||
const id = req.params.id; | ||
const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`); | ||
const data = await response.json(); | ||
|
||
res.send(data); | ||
}); | ||
|
||
app.get('/test-transaction', async function (req, res) { | ||
Sentry.startSpan({ name: 'test-span' }, () => { | ||
Sentry.startSpan({ name: 'child-span' }, () => {}); | ||
}); | ||
|
||
res.send({}); | ||
}); | ||
|
||
app.get('/test-error', async function (req, res) { | ||
const exceptionId = Sentry.captureException(new Error('This is an error')); | ||
|
||
await Sentry.flush(2000); | ||
|
||
res.send({ exceptionId }); | ||
}); | ||
|
||
app.get<{ Params: { id: string } }>('/test-exception/:id', async function (req, res) { | ||
throw new Error(`This is an exception with id ${req.params.id}`); | ||
}); | ||
|
||
app.get('/test-outgoing-fetch-external-allowed', async function (req, res) { | ||
const fetchResponse = await fetch(`http://localhost:${port2}/external-allowed`); | ||
const data = await fetchResponse.json(); | ||
|
||
res.send(data); | ||
}); | ||
|
||
app.get('/test-outgoing-fetch-external-disallowed', async function (req, res) { | ||
const fetchResponse = await fetch(`http://localhost:${port2}/external-disallowed`); | ||
const data = await fetchResponse.json(); | ||
|
||
res.send(data); | ||
}); | ||
|
||
app.get('/test-outgoing-http-external-allowed', async function (req, res) { | ||
const data = await makeHttpRequest(`http://localhost:${port2}/external-allowed`); | ||
res.send(data); | ||
}); | ||
|
||
app.get('/test-outgoing-http-external-disallowed', async function (req, res) { | ||
const data = await makeHttpRequest(`http://localhost:${port2}/external-disallowed`); | ||
res.send(data); | ||
}); | ||
|
||
app.listen({ port: port }); | ||
|
||
// A second app so we can test header propagation between external URLs | ||
const app2 = fastify(); | ||
app2.get('/external-allowed', function (req, res) { | ||
const headers = req.headers; | ||
|
||
res.send({ headers, route: '/external-allowed' }); | ||
}); | ||
|
||
app2.get('/external-disallowed', function (req, res) { | ||
const headers = req.headers; | ||
|
||
res.send({ headers, route: '/external-disallowed' }); | ||
}); | ||
|
||
app2.listen({ port: port2 }); | ||
|
||
function makeHttpRequest(url: string) { | ||
return new Promise(resolve => { | ||
const data: any[] = []; | ||
|
||
http | ||
.request(url, httpRes => { | ||
httpRes.on('data', chunk => { | ||
data.push(chunk); | ||
}); | ||
httpRes.on('error', error => { | ||
resolve({ error: error.message, url }); | ||
}); | ||
httpRes.on('end', () => { | ||
try { | ||
const json = JSON.parse(Buffer.concat(data).toString()); | ||
resolve(json); | ||
} catch { | ||
resolve({ data: Buffer.concat(data).toString(), url }); | ||
} | ||
}); | ||
}) | ||
.end(); | ||
}); | ||
} |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-fastify-5/start-event-proxy.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
||
startEventProxyServer({ | ||
port: 3031, | ||
proxyServerName: 'node-fastify-5', | ||
}); |
29 changes: 29 additions & 0 deletions
29
dev-packages/e2e-tests/test-applications/node-fastify-5/tests/errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError } from '@sentry-internal/test-utils'; | ||
|
||
test('Sends correct error event', async ({ baseURL }) => { | ||
const errorEventPromise = waitForError('node-fastify-5', event => { | ||
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123'; | ||
}); | ||
|
||
await fetch(`${baseURL}/test-exception/123`); | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123'); | ||
|
||
expect(errorEvent.request).toEqual({ | ||
method: 'GET', | ||
cookies: {}, | ||
headers: expect.any(Object), | ||
url: 'http://localhost:3030/test-exception/123', | ||
}); | ||
|
||
expect(errorEvent.transaction).toEqual('GET /test-exception/:id'); | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: expect.any(String), | ||
span_id: expect.any(String), | ||
}); | ||
}); |
Oops, something went wrong.