Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(http): refactor node:http client instrumentation for portability#20393
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d45b2415e4312ecef400f6ec58d569c96fcFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,202 +1,101 @@ | ||
| import { createTestServer } from '@sentry-internal/test-utils'; | ||
| import { describe, expect } from 'vitest'; | ||
| import { conditionalTest } from '../../../../utils'; | ||
| import { createEsmAndCjsTests } from '../../../../utils/runner'; | ||
| describe('outgoing http requests with tracing & spans disabled', () => { | ||
| createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| conditionalTest({ min: 22 })('node >=22', () => { | ||
| test('outgoing http requests are correctly instrumented with tracing & spans disabled', async () => { | ||
| expect.assertions(11); | ||
| test('outgoing http requests are correctly instrumented with tracing & spans disabled', async () => { | ||
| expect.assertions(11); | ||
| const [SERVER_URL, closeTestServer] = await createTestServer() | ||
| .get('/api/v0', headers => { | ||
| expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{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-f\d]{32})-([a-f\d]{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(); | ||
| const [SERVER_URL, closeTestServer] = await createTestServer() | ||
| .get('/api/v0', headers => { | ||
| expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{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-f\d]{32})-([a-f\d]{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(); | ||
| await createRunner() | ||
| .withEnv({ SERVER_URL }) | ||
| .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', | ||
| }, | ||
| await createRunner() | ||
| .withEnv({ SERVER_URL }) | ||
| .expect({ | ||
| event: { | ||
| exception: { | ||
| values: [ | ||
| { | ||
| 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', | ||
| type: 'Error', | ||
| value: 'foo', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| closeTestServer(); | ||
| }); | ||
| }); | ||
| // On older node versions, outgoing requests do not get trace-headers injected, sadly | ||
| // This is because the necessary diagnostics channel hook is not available yet | ||
| conditionalTest({ max: 21 })('node <22', () => { | ||
JPeer264 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| test('outgoing http requests generate breadcrumbs correctly with tracing & spans disabled', async () => { | ||
| expect.assertions(9); | ||
| const [SERVER_URL, closeTestServer] = await createTestServer() | ||
| .get('/api/v0', headers => { | ||
| // This is not instrumented, sadly | ||
| expect(headers['baggage']).toBeUndefined(); | ||
| expect(headers['sentry-trace']).toBeUndefined(); | ||
| }) | ||
| .get('/api/v1', headers => { | ||
| // This is not instrumented, sadly | ||
| expect(headers['baggage']).toBeUndefined(); | ||
| expect(headers['sentry-trace']).toBeUndefined(); | ||
| }) | ||
| .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(); | ||
| await createRunner() | ||
| .withEnv({ SERVER_URL }) | ||
| .expect({ | ||
| event: { | ||
| exception: { | ||
| values: [ | ||
| { | ||
| type: 'Error', | ||
| value: 'foo', | ||
| }, | ||
| ], | ||
| breadcrumbs: [ | ||
| { | ||
| message: 'manual breadcrumb', | ||
| timestamp: expect.any(Number), | ||
| }, | ||
| 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/v0`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v0', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v1`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v1', | ||
| }, | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v1`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v1', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v2`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v2', | ||
| }, | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v2`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v2', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v3`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v3', | ||
| }, | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| }, | ||
| { | ||
| category: 'http', | ||
| data: { | ||
| 'http.method': 'GET', | ||
| url: `${SERVER_URL}/api/v3`, | ||
| status_code: 200, | ||
| ADDED_PATH: '/api/v3', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| timestamp: expect.any(Number), | ||
| type: 'http', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| closeTestServer(); | ||
| }); | ||
| closeTestServer(); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.