-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Expose functional integrations to replace classes #10356
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a148de0
feat(node): Expose functional integrations to replace classes
mydea 225afc9
fix stuff & exports
mydea 7200e86
rename undici to `nativeNodeFetchIntegration` & add migration docs
mydea 6827886
http & node-fetch fixes
mydea 336834d
add missing re-exports
mydea 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
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
21 changes: 21 additions & 0 deletions
21
dev-packages/node-integration-tests/suites/tracing-new/httpIntegration/spans/scenario.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,21 @@ | ||
import '@sentry/tracing'; | ||
|
||
import * as http from 'http'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [Sentry.httpIntegration({})], | ||
debug: true, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'test_transaction' }, async () => { | ||
http.get('http://match-this-url.com/api/v0'); | ||
http.get('http://match-this-url.com/api/v1'); | ||
|
||
// Give it a tick to resolve... | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
}); |
40 changes: 40 additions & 0 deletions
40
dev-packages/node-integration-tests/suites/tracing-new/httpIntegration/spans/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,40 @@ | ||
import nock from 'nock'; | ||
|
||
import { TestEnv, assertSentryTransaction } from '../../../../utils'; | ||
|
||
test('should capture spans for outgoing http requests', async () => { | ||
const match1 = nock('http://match-this-url.com').get('/api/v0').reply(200); | ||
const match2 = nock('http://match-this-url.com').get('/api/v1').reply(200); | ||
|
||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(match1.isDone()).toBe(true); | ||
expect(match2.isDone()).toBe(true); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'test_transaction', | ||
spans: [ | ||
{ | ||
description: 'GET http://match-this-url.com/api/v0', | ||
op: 'http.client', | ||
origin: 'auto.http.node.http', | ||
status: 'ok', | ||
tags: { | ||
'http.status_code': '200', | ||
}, | ||
}, | ||
{ | ||
description: 'GET http://match-this-url.com/api/v1', | ||
op: 'http.client', | ||
origin: 'auto.http.node.http', | ||
status: 'ok', | ||
tags: { | ||
'http.status_code': '200', | ||
}, | ||
}, | ||
], | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
...kages/node-integration-tests/suites/tracing-new/httpIntegration/spansDisabled/scenario.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,20 @@ | ||
import '@sentry/tracing'; | ||
|
||
import * as http from 'http'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [Sentry.httpIntegration({ tracing: false })], | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan({ name: 'test_transaction' }, async () => { | ||
http.get('http://match-this-url.com/api/v0'); | ||
http.get('http://match-this-url.com/api/v1'); | ||
|
||
// Give it a tick to resolve... | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
}); |
21 changes: 21 additions & 0 deletions
21
dev-packages/node-integration-tests/suites/tracing-new/httpIntegration/spansDisabled/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,21 @@ | ||
import nock from 'nock'; | ||
|
||
import { TestEnv, assertSentryTransaction } from '../../../../utils'; | ||
|
||
test('should not capture spans for outgoing http requests if tracing is disabled', async () => { | ||
const match1 = nock('http://match-this-url.com').get('/api/v0').reply(200); | ||
const match2 = nock('http://match-this-url.com').get('/api/v1').reply(200); | ||
|
||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(match1.isDone()).toBe(true); | ||
expect(match2.isDone()).toBe(true); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'test_transaction', | ||
spans: [], | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
...-integration-tests/suites/tracing-new/httpIntegration/tracePropagationTargets/scenario.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,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import '@sentry/tracing'; | ||
|
||
import * as http from 'http'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
tracePropagationTargets: [/\/v0/, 'v1'], | ||
integrations: [Sentry.httpIntegration({})], | ||
}); | ||
|
||
Sentry.startSpan({ name: 'test_transaction' }, () => { | ||
http.get('http://match-this-url.com/api/v0'); | ||
http.get('http://match-this-url.com/api/v1'); | ||
http.get('http://dont-match-this-url.com/api/v2'); | ||
http.get('http://dont-match-this-url.com/api/v3'); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...node-integration-tests/suites/tracing-new/httpIntegration/tracePropagationTargets/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,42 @@ | ||
import nock from 'nock'; | ||
|
||
import { TestEnv, runScenario } from '../../../../utils'; | ||
|
||
test('httpIntegration should instrument correct requests when tracePropagationTargets option is provided & tracing is enabled', async () => { | ||
const match1 = nock('http://match-this-url.com') | ||
.get('/api/v0') | ||
.matchHeader('baggage', val => typeof val === 'string') | ||
.matchHeader('sentry-trace', val => typeof val === 'string') | ||
.reply(200); | ||
|
||
const match2 = nock('http://match-this-url.com') | ||
.get('/api/v1') | ||
.matchHeader('baggage', val => typeof val === 'string') | ||
.matchHeader('sentry-trace', val => typeof val === 'string') | ||
.reply(200); | ||
|
||
const match3 = nock('http://dont-match-this-url.com') | ||
.get('/api/v2') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const match4 = nock('http://dont-match-this-url.com') | ||
.get('/api/v3') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const env = await TestEnv.init(__dirname); | ||
await runScenario(env.url); | ||
|
||
env.server.close(); | ||
nock.cleanAll(); | ||
|
||
await new Promise(resolve => env.server.close(resolve)); | ||
|
||
expect(match1.isDone()).toBe(true); | ||
expect(match2.isDone()).toBe(true); | ||
expect(match3.isDone()).toBe(true); | ||
expect(match4.isDone()).toBe(true); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...tion-tests/suites/tracing-new/httpIntegration/tracePropagationTargetsDisabled/scenario.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,19 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import '@sentry/tracing'; | ||
|
||
import * as http from 'http'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracePropagationTargets: [/\/v0/, 'v1'], | ||
integrations: [Sentry.httpIntegration({})], | ||
}); | ||
|
||
Sentry.startSpan({ name: 'test_transaction' }, () => { | ||
http.get('http://match-this-url.com/api/v0'); | ||
http.get('http://match-this-url.com/api/v1'); | ||
http.get('http://dont-match-this-url.com/api/v2'); | ||
http.get('http://dont-match-this-url.com/api/v3'); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...egration-tests/suites/tracing-new/httpIntegration/tracePropagationTargetsDisabled/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,42 @@ | ||
import nock from 'nock'; | ||
|
||
import { TestEnv, runScenario } from '../../../../utils'; | ||
|
||
test('httpIntegration should not instrument when tracing is enabled', async () => { | ||
const match1 = nock('http://match-this-url.com') | ||
.get('/api/v0') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const match2 = nock('http://match-this-url.com') | ||
.get('/api/v1') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const match3 = nock('http://dont-match-this-url.com') | ||
.get('/api/v2') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const match4 = nock('http://dont-match-this-url.com') | ||
.get('/api/v3') | ||
.matchHeader('baggage', val => val === undefined) | ||
.matchHeader('sentry-trace', val => val === undefined) | ||
.reply(200); | ||
|
||
const env = await TestEnv.init(__dirname); | ||
await runScenario(env.url); | ||
|
||
env.server.close(); | ||
nock.cleanAll(); | ||
|
||
await new Promise(resolve => env.server.close(resolve)); | ||
|
||
expect(match1.isDone()).toBe(true); | ||
expect(match2.isDone()).toBe(true); | ||
expect(match3.isDone()).toBe(true); | ||
expect(match4.isDone()).toBe(true); | ||
}); |
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.
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.
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 think we need to do a better job to call out that these integration chanes also apply to all/most
@sentry/node
-based packages (serverless, fullstack framework SDKs). Doesn't strictly have to happen now but I'd say we should add them. Probably simplest to list them individually (also, they slightly differ per integration :( )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.
yeah, I thought about this too but this makes the table veeery unwieldly 😓 not sure, maybe we just point it out above? E.g. node also applies to next, remix, sveltekit, ..., browser also applies to react, ...?