-
-
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
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing/meta-tags-twp-errors/server.js
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 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
transport: loggingTransport, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.get('/test', (_req, res) => { | ||
Sentry.captureException(new Error('This is a test error')); | ||
Sentry.getClient().on('beforeEnvelope', envelope => { | ||
const event = envelope[1][0][1]; | ||
if (event.exception.values[0].value === 'This is a test error') { | ||
res.send({ | ||
traceData: Sentry.getTraceData(), | ||
traceMetaTags: Sentry.getTraceMetaTags(), | ||
errorTraceContext: event.contexts.trace, | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
43 changes: 43 additions & 0 deletions
43
dev-packages/node-integration-tests/suites/tracing/meta-tags-twp-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,43 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('errors in Tracing without Performance mode', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('error has the same traceId as obtained via getTraceData()/getTraceMetaTags()', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
|
||
const response = await runner.makeRequest('get', '/test'); | ||
|
||
console.log('response: ', response); | ||
|
||
const { traceData, traceMetaTags, errorTraceContext } = response as { | ||
traceData: Record<string, string>; | ||
traceMetaTags: string; | ||
errorTraceContext: { | ||
trace_id: string; | ||
span_id: string; | ||
}; | ||
}; | ||
|
||
const traceId = errorTraceContext?.trace_id; | ||
const spanId = errorTraceContext?.span_id; | ||
|
||
expect(traceId).toMatch(/^[a-f0-9]{32}$/); | ||
expect(spanId).toMatch(/^[a-f0-9]{16}$/); | ||
|
||
expect(errorTraceContext).toEqual({ | ||
trace_id: traceId, | ||
span_id: spanId, | ||
}); | ||
|
||
expect(traceData).toEqual({ | ||
'sentry-trace': `${traceId}-${spanId}`, | ||
baggage: expect.stringContaining(`sentry-trace_id=${traceId}`), | ||
}); | ||
|
||
expect(traceMetaTags).toContain(`content="${traceId}-${spanId}"/>\n`); | ||
expect(traceMetaTags).toContain(`sentry-trace_id=${traceId}`); | ||
}); | ||
}); |