Skip to content

Commit 4d16cfe

Browse files
committed
always set fallback traceLifecycle to 'static'
1 parent 85a792c commit 4d16cfe

File tree

5 files changed

+55
-43
lines changed

5 files changed

+55
-43
lines changed

packages/browser/src/integrations/spanstreaming.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ export const spanStreamingIntegration = defineIntegration(() => {
2727
setup(client) {
2828
const initialMessage = 'SpanStreaming integration requires';
2929
const fallbackMsg = 'Falling back to static trace lifecycle.';
30+
const clientOptions = client.getOptions();
3031

3132
if (!hasSpanStreamingEnabled(client)) {
33+
clientOptions.traceLifecycle = 'static';
3234
DEBUG_BUILD && debug.warn(`${initialMessage} \`traceLifecycle\` to be set to "stream"! ${fallbackMsg}`);
3335
return;
3436
}
3537

36-
const beforeSendSpan = client.getOptions().beforeSendSpan;
38+
const beforeSendSpan = clientOptions.beforeSendSpan;
3739
// If users misconfigure their SDK by opting into span streaming but
3840
// using an incompatible beforeSendSpan callback, we fall back to the static trace lifecycle.
3941
if (beforeSendSpan && !isStreamedBeforeSendSpanCallback(beforeSendSpan)) {
40-
client.getOptions().traceLifecycle = 'static';
42+
clientOptions.traceLifecycle = 'static';
4143
DEBUG_BUILD &&
4244
debug.warn(`${initialMessage} a beforeSendSpan callback using \`withStreamedSpan\`! ${fallbackMsg}`);
4345
return;

packages/browser/test/integrations/spanstreaming.test.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,29 @@ describe('spanStreamingIntegration', () => {
5050
expect(client.getOptions().traceLifecycle).toBe('stream');
5151
});
5252

53-
it('logs a warning if traceLifecycle is not set to "stream"', () => {
54-
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
55-
const client = new BrowserClient({
56-
...getDefaultBrowserClientOptions(),
57-
dsn: 'https://username@domain/123',
58-
integrations: [spanStreamingIntegration()],
59-
traceLifecycle: 'static',
60-
});
61-
62-
SentryCore.setCurrentClient(client);
63-
client.init();
64-
65-
expect(debugSpy).toHaveBeenCalledWith(
66-
'SpanStreaming integration requires `traceLifecycle` to be set to "stream"! Falling back to static trace lifecycle.',
67-
);
68-
debugSpy.mockRestore();
69-
70-
expect(client.getOptions().traceLifecycle).toBe('static');
71-
});
53+
it.each(['static', 'somethingElse'])(
54+
'logs a warning if traceLifecycle is not set to "stream" but to %s',
55+
traceLifecycle => {
56+
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
57+
const client = new BrowserClient({
58+
...getDefaultBrowserClientOptions(),
59+
dsn: 'https://username@domain/123',
60+
integrations: [spanStreamingIntegration()],
61+
// @ts-expect-error - we want to test the warning for invalid traceLifecycle values
62+
traceLifecycle,
63+
});
64+
65+
SentryCore.setCurrentClient(client);
66+
client.init();
67+
68+
expect(debugSpy).toHaveBeenCalledWith(
69+
'SpanStreaming integration requires `traceLifecycle` to be set to "stream"! Falling back to static trace lifecycle.',
70+
);
71+
debugSpy.mockRestore();
72+
73+
expect(client.getOptions().traceLifecycle).toBe('static');
74+
},
75+
);
7276

7377
it('falls back to static trace lifecycle if beforeSendSpan is not compatible with span streaming', () => {
7478
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});

packages/core/src/integrations/spanStreaming.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ export const spanStreamingIntegration = defineIntegration(() => {
1515
setup(client) {
1616
const initialMessage = 'SpanStreaming integration requires';
1717
const fallbackMsg = 'Falling back to static trace lifecycle.';
18+
const clientOptions = client.getOptions();
1819

1920
if (!hasSpanStreamingEnabled(client)) {
21+
clientOptions.traceLifecycle = 'static';
2022
DEBUG_BUILD && debug.warn(`${initialMessage} \`traceLifecycle\` to be set to "stream"! ${fallbackMsg}`);
2123
return;
2224
}
2325

24-
const beforeSendSpan = client.getOptions().beforeSendSpan;
26+
const beforeSendSpan = clientOptions.beforeSendSpan;
2527
if (beforeSendSpan && !isStreamedBeforeSendSpanCallback(beforeSendSpan)) {
26-
client.getOptions().traceLifecycle = 'static';
28+
clientOptions.traceLifecycle = 'static';
2729
DEBUG_BUILD &&
2830
debug.warn(`${initialMessage} a beforeSendSpan callback using \`withStreamedSpan\`! ${fallbackMsg}`);
2931
return;

packages/core/test/integrations/spanStreaming.test.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,29 @@ describe('spanStreamingIntegration (core)', () => {
3434
expect(integration.setup).toBeDefined();
3535
});
3636

37-
it('logs a warning if traceLifecycle is not set to "stream"', () => {
38-
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
39-
const client = new TestClient({
40-
...getDefaultTestClientOptions(),
41-
dsn: 'https://username@domain/123',
42-
integrations: [spanStreamingIntegration()],
43-
traceLifecycle: 'static',
44-
});
45-
46-
SentryCore.setCurrentClient(client);
47-
client.init();
48-
49-
expect(debugSpy).toHaveBeenCalledWith(
50-
'SpanStreaming integration requires `traceLifecycle` to be set to "stream"! Falling back to static trace lifecycle.',
51-
);
52-
debugSpy.mockRestore();
53-
54-
expect(client.getOptions().traceLifecycle).toBe('static');
55-
});
37+
it.each(['static', 'somethingElse'])(
38+
'logs a warning if traceLifecycle is not set to "stream" but to %s',
39+
traceLifecycle => {
40+
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
41+
const client = new TestClient({
42+
...getDefaultTestClientOptions(),
43+
dsn: 'https://username@domain/123',
44+
integrations: [spanStreamingIntegration()],
45+
// @ts-expect-error - we want to test the warning for invalid traceLifecycle values
46+
traceLifecycle,
47+
});
48+
49+
SentryCore.setCurrentClient(client);
50+
client.init();
51+
52+
expect(debugSpy).toHaveBeenCalledWith(
53+
'SpanStreaming integration requires `traceLifecycle` to be set to "stream"! Falling back to static trace lifecycle.',
54+
);
55+
debugSpy.mockRestore();
56+
57+
expect(client.getOptions().traceLifecycle).toBe('static');
58+
},
59+
);
5660

5761
it('falls back to static trace lifecycle if beforeSendSpan is not compatible with span streaming', () => {
5862
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});

packages/node/src/sdk/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { initOpenTelemetry } from './initOtel';
1515
/**
1616
* Get default integrations, excluding performance.
1717
*/
18-
export function getDefaultIntegrationsWithoutPerformance(options: Options): Integration[] {
18+
export function getDefaultIntegrationsWithoutPerformance(options?: Options | undefined): Integration[] {
1919
const nodeCoreIntegrations = getNodeCoreDefaultIntegrations(options);
2020

2121
// Filter out the node-core HTTP and NodeFetch integrations and replace them with Node SDK's composite versions

0 commit comments

Comments
 (0)