-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Pass parentSampleRate
to tracesSampler
#15024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 38 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
ebcf7bf
Remove unused function
a83a511
Merge remote-tracking branch 'origin/develop' into lforst-sample-rand
1646f0b
Write and use sample rand on propagation context
7fbba52
Implement propagating sampling decision properly
0b12615
Inject sample rand
1eac9af
Merge remote-tracking branch 'origin/develop' into lforst-sample-rand
38fe823
format
4fb937f
put onto initial dsc
6c27931
Add tests for `tracesSampleRate` behavior
8d6984f
mv
9b394c3
todo comment
1d4a641
unit tests
2d35988
node integration tests
957bc09
browser integration tests
e1c531f
Fix test
1fbbf82
Merge remote-tracking branch 'origin/develop' into lforst-sample-rand
a1d5dd3
test fix
83ac885
feat: Pass `parentSampleRate` to `tracesSampler`
045b41f
always apply root span sample rate to dsc
52ea3d2
e l a b o r a t e
631ed1b
Dont reinvent util we already have
37b6ca2
beep boop actually do what I am supposed to beep boop
5e3f706
don't leak attribute into actual data
8c83fb9
Merge branch 'lforst-sample-rand' into lforst-parent-sampling-decision
c4282b8
.
4a2a7ae
.
5b81700
.
9b2afff
tests
2c0910a
Merge remote-tracking branch 'origin/develop' into lforst-parent-samp…
6c6febf
something's off
4092e09
pain
72c3a64
Merge remote-tracking branch 'origin/develop' into lforst-parent-samp…
d835de7
otel side of things
c96c706
help
fdf0fa7
.
e9471eb
bless
2b491f2
beep boop
a96e9c6
lint
063984b
fix and test 0% sample rate
8607cc8
apply before emit
51526ec
Merge branch 'develop' into lforst-parent-sampling-decision
08b6561
fix merge mistake
bceb9f3
Refactor again
e2ffc52
lint
feb43ee
update tests
2a127b2
.
70c3fd9
fix crap
0ca98e3
update tests
812e750
more tests
2882ca4
e2e tests
f5a8220
.
fbee088
Merge remote-tracking branch 'origin/develop' into lforst-parent-samp…
f683884
.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ts/suites/sample-rand-propagation/test.ts → ...s/tracing/sample-rand-propagation/test.ts
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
...ode-integration-tests/suites/tracing/sample-rate-propagation/no-tracing-enabled/server.js
This file contains hidden or 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,39 @@ | ||
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 cors = require('cors'); | ||
const { | ||
startExpressServerAndSendPortToRunner, | ||
getPortAppIsRunningOn, | ||
} = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/check', (req, res) => { | ||
const appPort = getPortAppIsRunningOn(app); | ||
// eslint-disable-next-line no-undef | ||
fetch(`http://localhost:${appPort}/bounce`) | ||
.then(r => r.json()) | ||
.then(bounceRes => { | ||
res.json({ propagatedData: bounceRes }); | ||
}); | ||
}); | ||
|
||
app.get('/bounce', (req, res) => { | ||
res.json({ | ||
baggage: req.headers['baggage'], | ||
}); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
25 changes: 25 additions & 0 deletions
25
.../node-integration-tests/suites/tracing/sample-rate-propagation/no-tracing-enabled/test.ts
This file contains hidden or 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,25 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
||
describe('parentSampleRate propagation with no tracing enabled', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should propagate an incoming sample rate', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-1', | ||
baggage: 'sentry-sample_rate=0.1337', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.1337/); | ||
}); | ||
|
||
test('should not propagate a sample rate for root traces', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check'); | ||
expect((response as any).propagatedData.baggage).not.toMatch(/sentry-sample_rate/); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
.../node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampleRate/server.js
This file contains hidden or 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,40 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
transport: loggingTransport, | ||
tracesSampleRate: 0.69, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { | ||
startExpressServerAndSendPortToRunner, | ||
getPortAppIsRunningOn, | ||
} = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/check', (req, res) => { | ||
const appPort = getPortAppIsRunningOn(app); | ||
// eslint-disable-next-line no-undef | ||
fetch(`http://localhost:${appPort}/bounce`) | ||
.then(r => r.json()) | ||
.then(bounceRes => { | ||
res.json({ propagatedData: bounceRes }); | ||
}); | ||
}); | ||
|
||
app.get('/bounce', (req, res) => { | ||
res.json({ | ||
baggage: req.headers['baggage'], | ||
}); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
61 changes: 61 additions & 0 deletions
61
...es/node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampleRate/test.ts
This file contains hidden or 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,61 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
||
describe('parentSampleRate propagation with tracesSampleRate', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should propagate incoming sample rate when inheriting a positive sampling decision', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-1', | ||
baggage: 'sentry-sample_rate=0.1337', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.1337/); | ||
}); | ||
|
||
test('should propagate incoming sample rate when inheriting a negative sampling decision', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-0', | ||
baggage: 'sentry-sample_rate=0.1337', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.1337/); | ||
}); | ||
|
||
test('should propagate configured sample rate when receiving a trace without sampling decision and sample rate', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac', | ||
baggage: '', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/); | ||
}); | ||
|
||
test('should propagate configured sample rate when receiving a trace without sampling decision, but with sample rate', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac', | ||
baggage: 'sentry-sample_rate=0.1337', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/); | ||
}); | ||
|
||
test('should propagate configured sample rate when there is no incoming trace', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check'); | ||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
...ges/node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampler/server.js
This file contains hidden or 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,46 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
transport: loggingTransport, | ||
tracesSampler: ({ parentSampleRate }) => { | ||
if (parentSampleRate) { | ||
return parentSampleRate; | ||
} | ||
|
||
return 0.69; | ||
}, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { | ||
startExpressServerAndSendPortToRunner, | ||
getPortAppIsRunningOn, | ||
} = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/check', (req, res) => { | ||
const appPort = getPortAppIsRunningOn(app); | ||
// eslint-disable-next-line no-undef | ||
fetch(`http://localhost:${appPort}/bounce`) | ||
.then(r => r.json()) | ||
.then(bounceRes => { | ||
res.json({ propagatedData: bounceRes }); | ||
}); | ||
}); | ||
|
||
app.get('/bounce', (req, res) => { | ||
res.json({ | ||
baggage: req.headers['baggage'], | ||
}); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
37 changes: 37 additions & 0 deletions
37
...kages/node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampler/test.ts
This file contains hidden or 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,37 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
||
describe('parentSampleRate propagation with tracesSampler', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming trace', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check'); | ||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/); | ||
}); | ||
|
||
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming sample rate', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-1', | ||
baggage: '', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/); | ||
}); | ||
|
||
test('should propagate sample_rate equivalent to incoming sample_rate (because tracesSampler is configured that way)', async () => { | ||
const runner = createRunner(__dirname, 'server.js').start(); | ||
const response = await runner.makeRequest('get', '/check', { | ||
headers: { | ||
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-1', | ||
baggage: 'sentry-sample_rate=0.1337', | ||
}, | ||
}); | ||
|
||
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.1337/); | ||
}); | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm no strong feelings, but can we move this somewhere else than here? E.g. into sentrySpan (where we already delete the name attribute) and/or the span exporter (where we already clear some data that we do not want to send)? These feel like more correct places for this than the envelope, which should rather just send what it gets, IMHO.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this here because there is no other really generic flow that runs for standalone spans. This is basically one-of logic. We already delete it in sentrySpan, but sentrySpan doesn't run for standalones, neither does the span exporter in browser. Do you have any other concrete ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also just delete the line. We also seem to be sending other garbage attributes through standalones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I see 🤔 you decide, it feels a bit "weird" to do this in envelope serialization step, but also OK to me!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. For the lack of better placement I'll leave it. Removing it wouldn't be great since we'd just end up forgetting to do so. It's super easy to refactor once we flesh out standalone spans.