-
-
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.
test(node): Add integration test to demonstrate sample rate propagati…
…on of incoming trace (#14788)
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...es/node-integration-tests/suites/tracing/envelope-header/sampleRate-propagation/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,32 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
// disable attaching headers to /test/* endpoints | ||
tracePropagationTargets: [/^(?!.*test).*$/], | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const bodyParser = require('body-parser'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.text()); | ||
app.use(bodyParser.raw()); | ||
|
||
app.get('/test', (req, res) => { | ||
res.send({ headers: req.headers }); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
30 changes: 30 additions & 0 deletions
30
...ages/node-integration-tests/suites/tracing/envelope-header/sampleRate-propagation/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,30 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
||
describe('tracesSampleRate propagation', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
const traceId = '12345678123456781234567812345678'; | ||
|
||
test('uses sample rate from incoming baggage header in trace envelope item', done => { | ||
createRunner(__dirname, 'server.js') | ||
.expectHeader({ | ||
transaction: { | ||
trace: { | ||
sample_rate: '0.05', | ||
sampled: 'true', | ||
trace_id: traceId, | ||
transaction: 'myTransaction', | ||
}, | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test', { | ||
headers: { | ||
'sentry-trace': `${traceId}-1234567812345678-1`, | ||
baggage: `sentry-sample_rate=0.05,sentry-trace_id=${traceId},sentry-sampled=true,sentry-transaction=myTransaction`, | ||
}, | ||
}); | ||
}); | ||
}); |