-
-
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.
fix(opentelemetry): Always use active span in
Propagator.inject
(#1…
…3381) This PR removes the check for `hasTracingEnabled` in `getInjectionData` and simply always takes the non-recording span if there is one. Which is always the case in server applications when handling a request. For non-request-handling situations, we fall back anyway to the propagation context.
- Loading branch information
Showing
4 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
dev-packages/node-integration-tests/suites/tracing/meta-tags-twp-errors/no-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,20 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
transport: loggingTransport, | ||
beforeSend(event) { | ||
event.contexts = { | ||
...event.contexts, | ||
traceData: { | ||
...Sentry.getTraceData(), | ||
metaTags: Sentry.getTraceMetaTags(), | ||
}, | ||
}; | ||
return event; | ||
}, | ||
}); | ||
|
||
Sentry.captureException(new Error('test error')); |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
const { loggingTransport, startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
transport: loggingTransport, | ||
beforeSend(event) { | ||
event.contexts = { | ||
...event.contexts, | ||
traceData: { | ||
...Sentry.getTraceData(), | ||
metaTags: Sentry.getTraceMetaTags(), | ||
}, | ||
}; | ||
return event; | ||
}, | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
|
||
const app = express(); | ||
|
||
app.get('/test', () => { | ||
throw new Error('test error'); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('errors in TwP mode have same trace in trace context and getTraceData()', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('in incoming request', async () => { | ||
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.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`); | ||
expect(traceData.metaTags).toContain(`sentr y-trace_id=${trace_id}`); | ||
expect(traceData.metaTags).not.toContain('sentry-sampled='); | ||
}, | ||
}) | ||
.start() | ||
.makeRequest('get', '/test'); | ||
}); | ||
|
||
test('outside of a request handler', done => { | ||
createRunner(__dirname, 'no-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.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); | ||
}); | ||
}); |
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