-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(core): Remove sampled
flag from dynamic sampling context in Tracing without Performance mode
#13753
fix(core): Remove sampled
flag from dynamic sampling context in Tracing without Performance mode
#13753
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ Sentry.init({ | |
dsn: 'https://[email protected]/1337', | ||
transport: loggingTransport, | ||
beforeSend(event) { | ||
event.contexts = { | ||
...event.contexts, | ||
traceData: { | ||
...Sentry.getTraceData(), | ||
metaTags: Sentry.getTraceMetaTags(), | ||
}, | ||
}; | ||
if (!event.contexts.traceData) { | ||
event.contexts = { | ||
...event.contexts, | ||
traceData: { | ||
...Sentry.getTraceData(), | ||
metaTags: Sentry.getTraceMetaTags(), | ||
}, | ||
}; | ||
} | ||
return event; | ||
}, | ||
}); | ||
|
@@ -21,8 +23,20 @@ const express = require('express'); | |
|
||
const app = express(); | ||
|
||
app.get('/test', () => { | ||
throw new Error('test error'); | ||
app.get('/test', (_req, res) => { | ||
Sentry.captureException(new Error('test error')); | ||
res.status(200).send(); | ||
}); | ||
|
||
app.get('/test-scope', (_req, res) => { | ||
Sentry.withScope(scope => { | ||
scope.setContext('traceData', { | ||
...Sentry.getTraceData(), | ||
metaTags: Sentry.getTraceMetaTags(), | ||
}); | ||
Sentry.captureException(new Error('test error 2')); | ||
}); | ||
res.status(200).send(); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ describe('errors in TwP mode have same trace in trace context and getTraceData() | |
cleanupChildProcesses(); | ||
}); | ||
|
||
test('in incoming request', async () => { | ||
test('in incoming request', done => { | ||
createRunner(__dirname, 'server.js') | ||
.expect({ | ||
event: event => { | ||
|
@@ -17,17 +17,44 @@ describe('errors in TwP mode have same trace in trace context and getTraceData() | |
const traceData = contexts?.traceData || {}; | ||
|
||
expect(traceData['sentry-trace']).toEqual(`${trace_id}-${span_id}`); | ||
|
||
expect(traceData.baggage).toContain(`sentry-trace_id=${trace_id}`); | ||
expect(traceData.baggage).not.toContain('sentry-sampled='); | ||
|
||
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`); | ||
expect(traceData.metaTags).toContain(`sentr y-trace_id=${trace_id}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how did that pass before? 😅 oops There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it "passed" because the test function was async but it should have been sync and passed |
||
expect(traceData.metaTags).toContain(`sentry-trace_id=${trace_id}`); | ||
expect(traceData.metaTags).not.toContain('sentry-sampled='); | ||
}, | ||
}) | ||
.start() | ||
.start(done) | ||
.makeRequest('get', '/test'); | ||
}); | ||
|
||
test('in incoming request with Custom Scope', done => { | ||
createRunner(__dirname, 'server.js') | ||
.expect({ | ||
event: event => { | ||
const { contexts } = event; | ||
const { trace_id, span_id } = contexts?.trace || {}; | ||
expect(trace_id).toMatch(/^[a-f0-9]{32}$/); | ||
expect(span_id).toMatch(/^[a-f0-9]{16}$/); | ||
|
||
const traceData = contexts?.traceData || {}; | ||
|
||
expect(traceData['sentry-trace']).toEqual(`${trace_id}-${span_id}`); | ||
|
||
expect(traceData.baggage).toContain(`sentry-trace_id=${trace_id}`); | ||
expect(traceData.baggage).not.toContain('sentry-sampled='); | ||
|
||
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`); | ||
expect(traceData.metaTags).toContain(`sentry-trace_id=${trace_id}`); | ||
expect(traceData.metaTags).not.toContain('sentry-sampled='); | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test-scope'); | ||
}); | ||
|
||
test('outside of a request handler', done => { | ||
createRunner(__dirname, 'no-server.js') | ||
.expect({ | ||
|
@@ -41,6 +68,7 @@ describe('errors in TwP mode have same trace in trace context and getTraceData() | |
|
||
expect(traceData['sentry-trace']).toEqual(`${trace_id}-${span_id}`); | ||
expect(traceData.baggage).toContain(`sentry-trace_id=${trace_id}`); | ||
expect(traceData.baggage).not.toContain('sentry-sampled='); | ||
|
||
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`); | ||
expect(traceData.metaTags).toContain(`sentry-trace_id=${trace_id}`); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ describe('getTraceMetaTags', () => { | |
expect(sentryBaggageContent).toContain('sentry-environment=production'); | ||
expect(sentryBaggageContent).toContain('sentry-public_key=public'); | ||
expect(sentryBaggageContent).toContain(`sentry-trace_id=${traceId}`); | ||
expect(sentryBaggageContent).not.toContain('sentry-sampled='); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion failed before the change in this PR |
||
}); | ||
}); |
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.
why is this change necessary?
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.
Actually, two of the tests have become so similar that I'll just remove the beforeSend hook and one of the tests.