Skip to content

feat(sveltekit): Add Undici integration by default #7650

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 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/sveltekit/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { configureScope } from '@sentry/core';
import type { NodeOptions } from '@sentry/node';
import { init as initNodeSdk } from '@sentry/node';
import { init as initNodeSdk, Integrations } from '@sentry/node';
import { addOrUpdateIntegration } from '@sentry/utils';

import { applySdkMetadata } from '../common/metadata';

Expand All @@ -11,9 +12,15 @@ import { applySdkMetadata } from '../common/metadata';
export function init(options: NodeOptions): void {
applySdkMetadata(options, ['sveltekit', 'node']);

addServerIntegrations(options);

initNodeSdk(options);

configureScope(scope => {
scope.setTag('runtime', 'node');
});
}

function addServerIntegrations(options: NodeOptions): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: before adding this integration, don't we need to check for hasTracingEnabled?

At least that's how we do it on the client-side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to worry about bundle size + the integration should gracefully handle when tracing is not enabled, so I think the answer is no.

We have this logic in next.js because the http integration by default sets tracing to be false - you have to opt-in to it (which is what the nextjs SDK adds for you).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for clarifying!

options.integrations = addOrUpdateIntegration(new Integrations.Undici(), options.integrations || []);
}
15 changes: 15 additions & 0 deletions packages/sveltekit/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,20 @@ describe('Sentry server SDK', () => {
// @ts-ignore need access to protected _tags attribute
expect(currentScope._tags).toEqual({ runtime: 'node' });
});

it('adds the Undici integration', () => {
init({});

expect(nodeInit).toHaveBeenCalledTimes(1);
expect(nodeInit).toHaveBeenCalledWith(
expect.objectContaining({
integrations: expect.arrayContaining([
expect.objectContaining({
name: 'Undici',
}),
]),
}),
);
});
});
});