Skip to content

Commit e85814b

Browse files
committed
use getDefaultIntegrations to add/not add span streaming integration
1 parent 58411fa commit e85814b

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { nativeNodeFetchIntegration } from './integrations/nativeNodeFetchIntegr
3939
/**
4040
* Get default integrations for the Light Node-Core SDK.
4141
*/
42-
export function getDefaultIntegrations(): Integration[] {
42+
export function getDefaultIntegrations(options?: Options): Integration[] {
4343
return [
4444
// Common
4545
eventFiltersIntegration(),
@@ -61,6 +61,7 @@ export function getDefaultIntegrations(): Integration[] {
6161
childProcessIntegration(),
6262
processSessionIntegration(),
6363
modulesIntegration(),
64+
...(options?.traceLifecycle === 'stream' ? [spanStreamingIntegration()] : []),
6465
];
6566
}
6667

@@ -113,10 +114,6 @@ function _init(
113114
);
114115
}
115116

116-
if (options.traceLifecycle === 'stream' && !options.integrations.some(({ name }) => name === 'SpanStreaming')) {
117-
options.integrations.push(spanStreamingIntegration());
118-
}
119-
120117
applySdkMetadata(options, 'node-light', ['node-core']);
121118

122119
const client = new LightNodeClient(options);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { initializeEsmLoader } from './esmLoader';
4747
/**
4848
* Get default integrations for the Node-Core SDK.
4949
*/
50-
export function getDefaultIntegrations(): Integration[] {
50+
export function getDefaultIntegrations(options?: Options): Integration[] {
5151
return [
5252
// Common
5353
// TODO(v11): Replace with `eventFiltersIntegration` once we remove the deprecated `inboundFiltersIntegration`
@@ -72,6 +72,7 @@ export function getDefaultIntegrations(): Integration[] {
7272
childProcessIntegration(),
7373
processSessionIntegration(),
7474
modulesIntegration(),
75+
...(options?.traceLifecycle === 'stream' ? [spanStreamingIntegration()] : []),
7576
];
7677
}
7778

@@ -127,10 +128,6 @@ function _init(
127128
);
128129
}
129130

130-
if (options.traceLifecycle === 'stream' && !options.integrations.some(({ name }) => name === 'SpanStreaming')) {
131-
options.integrations.push(spanStreamingIntegration());
132-
}
133-
134131
applySdkMetadata(options, 'node-core');
135132

136133
const client = new NodeClient(options);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ describe('Light Mode | SDK', () => {
106106

107107
expect(integrationNames).toContain('NodeFetch');
108108
});
109+
110+
it('includes spanStreaming integration when traceLifecycle is "stream"', () => {
111+
const integrations = Sentry.getDefaultIntegrations({ traceLifecycle: 'stream' });
112+
const integrationNames = integrations.map(i => i.name);
113+
114+
expect(integrationNames).toContain('SpanStreaming');
115+
});
116+
117+
it("doesn't include spanStreaming integration when traceLifecycle is not 'stream'", () => {
118+
const integrations = Sentry.getDefaultIntegrations();
119+
const integrationNames = integrations.map(i => i.name);
120+
121+
expect(integrationNames).not.toContain('SpanStreaming');
122+
});
109123
});
110124

111125
describe('isInitialized', () => {

packages/node/src/sdk/index.ts

Lines changed: 2 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 { applySdkMetadata, hasSpansEnabled } from '@sentry/core';
2+
import { applySdkMetadata, hasSpansEnabled, spanStreamingIntegration } from '@sentry/core';
33
import type { NodeClient } from '@sentry/node-core';
44
import {
55
getDefaultIntegrations as getNodeCoreDefaultIntegrations,
@@ -33,6 +33,7 @@ export function getDefaultIntegrations(options: Options): Integration[] {
3333
// This means that generally request isolation will work (because that is done by httpIntegration)
3434
// But `transactionName` will not be set automatically
3535
...(hasSpansEnabled(options) ? getAutoPerformanceIntegrations() : []),
36+
...(options.traceLifecycle === 'stream' ? [spanStreamingIntegration()] : []),
3637
];
3738
}
3839

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ describe('init()', () => {
143143
}),
144144
);
145145
});
146+
147+
it('installs spanStreaming integration when traceLifecycle is "stream"', () => {
148+
init({ dsn: PUBLIC_DSN, traceLifecycle: 'stream' });
149+
const client = getClient();
150+
151+
expect(client?.getOptions()).toEqual(
152+
expect.objectContaining({
153+
integrations: expect.arrayContaining([expect.objectContaining({ name: 'SpanStreaming' })]),
154+
}),
155+
);
156+
});
157+
158+
it("doesn't install spanStreaming integration when traceLifecycle is not 'stream'", () => {
159+
init({ dsn: PUBLIC_DSN });
160+
161+
const client = getClient();
162+
expect(client?.getOptions()).toEqual(
163+
expect.objectContaining({
164+
integrations: expect.not.arrayContaining([expect.objectContaining({ name: 'SpanStreaming' })]),
165+
}),
166+
);
167+
});
146168
});
147169

148170
describe('OpenTelemetry', () => {

0 commit comments

Comments
 (0)