-
-
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(node): Ensure
httpIntegration
propagates traces
We used to rely on the existence of another `httpIntegration`
- Loading branch information
Showing
3 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...kages/node-integration-tests/suites/tracing/requests/http-no-tracing-no-spans/scenario.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,61 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracePropagationTargets: [/\/v0/, 'v1'], | ||
integrations: [Sentry.httpIntegration({ spans: false })], | ||
transport: loggingTransport, | ||
// Ensure this gets a correct hint | ||
beforeBreadcrumb(breadcrumb, hint) { | ||
breadcrumb.data = breadcrumb.data || {}; | ||
const req = hint?.request as { path?: string }; | ||
breadcrumb.data.ADDED_PATH = req?.path; | ||
return breadcrumb; | ||
}, | ||
}); | ||
|
||
import * as http from 'http'; | ||
|
||
async function run(): Promise<void> { | ||
Sentry.addBreadcrumb({ message: 'manual breadcrumb' }); | ||
|
||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v0`); | ||
await makeHttpGet(`${process.env.SERVER_URL}/api/v1`); | ||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v2`); | ||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v3`); | ||
|
||
Sentry.captureException(new Error('foo')); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(); | ||
|
||
function makeHttpRequest(url: string): Promise<void> { | ||
return new Promise<void>(resolve => { | ||
http | ||
.request(url, httpRes => { | ||
httpRes.on('data', () => { | ||
// we don't care about data | ||
}); | ||
httpRes.on('end', () => { | ||
resolve(); | ||
}); | ||
}) | ||
.end(); | ||
}); | ||
} | ||
|
||
function makeHttpGet(url: string): Promise<void> { | ||
return new Promise<void>(resolve => { | ||
http.get(url, httpRes => { | ||
httpRes.on('data', () => { | ||
// we don't care about data | ||
}); | ||
httpRes.on('end', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} |
95 changes: 95 additions & 0 deletions
95
dev-packages/node-integration-tests/suites/tracing/requests/http-no-tracing-no-spans/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,95 @@ | ||
import { createRunner } from '../../../../utils/runner'; | ||
import { createTestServer } from '../../../../utils/server'; | ||
|
||
test('outgoing http requests are correctly instrumented with tracing & spans disabled', done => { | ||
expect.assertions(11); | ||
|
||
createTestServer(done) | ||
.get('/api/v0', headers => { | ||
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/)); | ||
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000'); | ||
expect(headers['baggage']).toEqual(expect.any(String)); | ||
}) | ||
.get('/api/v1', headers => { | ||
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/)); | ||
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000'); | ||
expect(headers['baggage']).toEqual(expect.any(String)); | ||
}) | ||
.get('/api/v2', headers => { | ||
expect(headers['baggage']).toBeUndefined(); | ||
expect(headers['sentry-trace']).toBeUndefined(); | ||
}) | ||
.get('/api/v3', headers => { | ||
expect(headers['baggage']).toBeUndefined(); | ||
expect(headers['sentry-trace']).toBeUndefined(); | ||
}) | ||
.start() | ||
.then(([SERVER_URL, closeTestServer]) => { | ||
createRunner(__dirname, 'scenario.ts') | ||
.withEnv({ SERVER_URL }) | ||
.ensureNoErrorOutput() | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'foo', | ||
}, | ||
], | ||
}, | ||
breadcrumbs: [ | ||
{ | ||
message: 'manual breadcrumb', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'http', | ||
data: { | ||
'http.method': 'GET', | ||
url: `${SERVER_URL}/api/v0`, | ||
status_code: 200, | ||
ADDED_PATH: '/api/v0', | ||
}, | ||
timestamp: expect.any(Number), | ||
type: 'http', | ||
}, | ||
{ | ||
category: 'http', | ||
data: { | ||
'http.method': 'GET', | ||
url: `${SERVER_URL}/api/v1`, | ||
status_code: 200, | ||
ADDED_PATH: '/api/v1', | ||
}, | ||
timestamp: expect.any(Number), | ||
type: 'http', | ||
}, | ||
{ | ||
category: 'http', | ||
data: { | ||
'http.method': 'GET', | ||
url: `${SERVER_URL}/api/v2`, | ||
status_code: 200, | ||
ADDED_PATH: '/api/v2', | ||
}, | ||
timestamp: expect.any(Number), | ||
type: 'http', | ||
}, | ||
{ | ||
category: 'http', | ||
data: { | ||
'http.method': 'GET', | ||
url: `${SERVER_URL}/api/v3`, | ||
status_code: 200, | ||
ADDED_PATH: '/api/v3', | ||
}, | ||
timestamp: expect.any(Number), | ||
type: 'http', | ||
}, | ||
], | ||
}, | ||
}) | ||
.start(closeTestServer); | ||
}); | ||
}); |
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