Skip to content
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

feat(node): fetch breadcrumbs without tracing #14018

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const DEPENDENTS: Dependent[] = [
ignoreExports: [
// not supported in bun:
'NodeClient',
// Doesn't have these events
'fetchBreadcrumbsIntegration',
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracePropagationTargets: [/\/v0/, 'v1'],
integrations: [Sentry.nativeNodeFetchIntegration({ breadcrumbs: false })],
transport: loggingTransport,
tracesSampleRate: 0.0,
});

async function run(): Promise<void> {
Sentry.addBreadcrumb({ message: 'manual breadcrumb' });

// Since fetch is lazy loaded, we need to wait a bit until it's fully instrumented
await new Promise(resolve => setTimeout(resolve, 100));
await fetch(`${process.env.SERVER_URL}/api/v0`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v1`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v2`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v3`).then(res => res.text());

Sentry.captureException(new Error('foo'));
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracePropagationTargets: [/\/v0/, 'v1'],
integrations: [],
transport: loggingTransport,
tracesSampleRate: 0.0,
fetchBreadcrumbs: false,
});

async function run(): Promise<void> {
Sentry.addBreadcrumb({ message: 'manual breadcrumb' });

// Since fetch is lazy loaded, we need to wait a bit until it's fully instrumented
await new Promise(resolve => setTimeout(resolve, 100));
await fetch(`${process.env.SERVER_URL}/api/v0`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v1`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v2`).then(res => res.text());
await fetch(`${process.env.SERVER_URL}/api/v3`).then(res => res.text());

Sentry.captureException(new Error('foo'));
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,62 @@ conditionalTest({ min: 18 })('outgoing fetch', () => {
.start(closeTestServer);
});
});

test('outgoing fetch requests should not create breadcrumbs when disabled', done => {
createTestServer(done)
.start()
.then(([SERVER_URL, closeTestServer]) => {
createRunner(__dirname, 'scenario-disabled.ts')
.withEnv({ SERVER_URL })
.ensureNoErrorOutput()
.expect({
event: {
breadcrumbs: [
{
message: 'manual breadcrumb',
timestamp: expect.any(Number),
},
],
exception: {
values: [
{
type: 'Error',
value: 'foo',
},
],
},
},
})
.start(closeTestServer);
});
});

test('outgoing fetch requests should not create breadcrumbs when legacy disabled', done => {
createTestServer(done)
.start()
.then(([SERVER_URL, closeTestServer]) => {
createRunner(__dirname, 'scenario-disabled-legacy.ts')
.withEnv({ SERVER_URL })
.ensureNoErrorOutput()
.expect({
event: {
breadcrumbs: [
{
message: 'manual breadcrumb',
timestamp: expect.any(Number),
},
],
exception: {
values: [
{
type: 'Error',
value: 'foo',
},
],
},
},
})
.start(closeTestServer);
});
});
});
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export {
mysql2Integration,
mysqlIntegration,
nativeNodeFetchIntegration,
fetchBreadcrumbsIntegration,
nestIntegration,
NodeClient,
nodeContextIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export {
consoleIntegration,
httpIntegration,
nativeNodeFetchIntegration,
fetchBreadcrumbsIntegration,
onUncaughtExceptionIntegration,
onUnhandledRejectionIntegration,
modulesIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export {
consoleIntegration,
httpIntegration,
nativeNodeFetchIntegration,
fetchBreadcrumbsIntegration,
onUncaughtExceptionIntegration,
onUnhandledRejectionIntegration,
modulesIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { spotlightIntegration } from './integrations/spotlight';
export { genericPoolIntegration } from './integrations/tracing/genericPool';
export { dataloaderIntegration } from './integrations/tracing/dataloader';
export { amqplibIntegration } from './integrations/tracing/amqplib';
export { fetchBreadcrumbsIntegration } from './integrations/fetch-breadcrumbs';

export { SentryContextManager } from './otel/contextManager';
export { generateInstrumentOnce } from './otel/instrument';
Expand Down
Loading
Loading