Skip to content

Commit 90c2385

Browse files
authored
fix(node-core): Apply correct SDK metadata (#17014)
While adding the SDK to the release-registry I noticed that we never apply the correct metadata to node-core. 64d056a failing tests show the node-core SDK getting incorrect `sentry.javascript.node` metadata (from `NodeClient`) 88a975a applies correct metadata to both SDKs I was debating changing the underlying `NodeClient` to not automatically set `sentry.javascript.node` but wasn't sure of the implications so decided not to.
1 parent 10d5454 commit 90c2385

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

packages/node-core/src/sdk/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Integration, Options } from '@sentry/core';
22
import {
3+
applySdkMetadata,
34
consoleIntegration,
45
consoleSandbox,
56
functionToStringIntegration,
@@ -120,6 +121,8 @@ function _init(
120121
);
121122
}
122123

124+
applySdkMetadata(options, 'node-core');
125+
123126
const client = new NodeClient(options);
124127
// The client is on the current scope, from where it generally is inherited
125128
getCurrentScope().setClient(client);

packages/node-core/test/sdk/init.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Integration } from '@sentry/core';
2-
import { logger } from '@sentry/core';
2+
import { logger, SDK_VERSION } from '@sentry/core';
33
import * as SentryOpentelemetry from '@sentry/opentelemetry';
44
import { type Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55
import { getClient } from '../../src/';
@@ -31,6 +31,24 @@ describe('init()', () => {
3131
vi.clearAllMocks();
3232
});
3333

34+
describe('metadata', () => {
35+
it('has the correct metadata', () => {
36+
init({ dsn: PUBLIC_DSN });
37+
38+
const client = getClient<NodeClient>();
39+
40+
expect(client?.getSdkMetadata()).toEqual(
41+
expect.objectContaining({
42+
sdk: {
43+
name: 'sentry.javascript.node-core',
44+
version: SDK_VERSION,
45+
packages: [{ name: 'npm:@sentry/node-core', version: SDK_VERSION }],
46+
},
47+
}),
48+
);
49+
});
50+
});
51+
3452
describe('integrations', () => {
3553
it("doesn't install default integrations if told not to", () => {
3654
init({ dsn: PUBLIC_DSN, defaultIntegrations: false });

packages/node/src/sdk/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Integration, Options } from '@sentry/core';
2-
import { hasSpansEnabled } from '@sentry/core';
2+
import { applySdkMetadata, hasSpansEnabled } from '@sentry/core';
33
import type { NodeClient } from '@sentry/node-core';
44
import {
55
getDefaultIntegrations as getNodeCoreDefaultIntegrations,
@@ -50,6 +50,8 @@ function _init(
5050
options: NodeOptions | undefined = {},
5151
getDefaultIntegrationsImpl: (options: Options) => Integration[],
5252
): NodeClient | undefined {
53+
applySdkMetadata(options, 'node');
54+
5355
const client = initNodeCore({
5456
...options,
5557
// Only use Node SDK defaults if none provided

packages/node/test/sdk/init.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Integration } from '@sentry/core';
2-
import { logger } from '@sentry/core';
2+
import { logger, SDK_VERSION } from '@sentry/core';
33
import * as SentryOpentelemetry from '@sentry/opentelemetry';
44
import { type Mock, type MockInstance, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55
import { getClient, NodeClient, validateOpenTelemetrySetup } from '../../src/';
@@ -38,6 +38,24 @@ describe('init()', () => {
3838
vi.clearAllMocks();
3939
});
4040

41+
describe('metadata', () => {
42+
it('has the correct metadata', () => {
43+
init({ dsn: PUBLIC_DSN });
44+
45+
const client = getClient<NodeClient>();
46+
47+
expect(client?.getSdkMetadata()).toEqual(
48+
expect.objectContaining({
49+
sdk: {
50+
name: 'sentry.javascript.node',
51+
version: SDK_VERSION,
52+
packages: [{ name: 'npm:@sentry/node', version: SDK_VERSION }],
53+
},
54+
}),
55+
);
56+
});
57+
});
58+
4159
describe('integrations', () => {
4260
it("doesn't install default integrations if told not to", () => {
4361
init({ dsn: PUBLIC_DSN, defaultIntegrations: false });

0 commit comments

Comments
 (0)