Skip to content

Commit 8bfef51

Browse files
mydeacursoragent
andauthored
test: Avoid unnecessary definedness checks for attributes on SerializedStreamedSpan objects (#22060)
Adjusts tests to avoid checking for definedness on `SerializedStreamedSpan` `attributes` (following #22052) --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
1 parent 0e42a84 commit 8bfef51

52 files changed

Lines changed: 336 additions & 341 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev-packages/browser-integration-tests/suites/integrations/cultureContext-streamed/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sentryTest('cultureContextIntegration captures locale, timezone, and calendar',
1515

1616
const pageloadSpan = spans.find(s => getSpanOp(s) === 'pageload');
1717

18-
expect(pageloadSpan!.attributes?.['culture.locale']).toEqual({ type: 'string', value: expect.any(String) });
19-
expect(pageloadSpan!.attributes?.['culture.timezone']).toEqual({ type: 'string', value: expect.any(String) });
20-
expect(pageloadSpan!.attributes?.['culture.calendar']).toEqual({ type: 'string', value: expect.any(String) });
18+
expect(pageloadSpan!.attributes['culture.locale']).toEqual({ type: 'string', value: expect.any(String) });
19+
expect(pageloadSpan!.attributes['culture.timezone']).toEqual({ type: 'string', value: expect.any(String) });
20+
expect(pageloadSpan!.attributes['culture.calendar']).toEqual({ type: 'string', value: expect.any(String) });
2121
});

dev-packages/browser-integration-tests/suites/integrations/httpContext-streamed/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ sentryTest('httpContextIntegration captures url, user-agent, and referer', async
1515

1616
const pageloadSpan = spans.find(s => getSpanOp(s) === 'pageload');
1717

18-
expect(pageloadSpan!.attributes?.['url.full']).toEqual({ type: 'string', value: expect.any(String) });
19-
expect(pageloadSpan!.attributes?.['http.request.header.user_agent']).toEqual({
18+
expect(pageloadSpan!.attributes['url.full']).toEqual({ type: 'string', value: expect.any(String) });
19+
expect(pageloadSpan!.attributes['http.request.header.user_agent']).toEqual({
2020
type: 'string',
2121
value: expect.any(String),
2222
});
23-
expect(pageloadSpan!.attributes?.['http.request.header.referer']).toEqual({
23+
expect(pageloadSpan!.attributes['http.request.header.referer']).toEqual({
2424
type: 'string',
2525
value: 'https://sentry.io/',
2626
});

dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_streamed-spans/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ sentryTest(
2222
const rootSpan = spans.find(s => s.name === 'root-fibonacci');
2323
expect(rootSpan).toBeDefined();
2424

25-
expect(rootSpan!.attributes?.['thread.id']).toEqual({ type: 'string', value: '0' });
26-
expect(rootSpan!.attributes?.['thread.name']).toEqual({ type: 'string', value: 'main' });
25+
expect(rootSpan!.attributes['thread.id']).toEqual({ type: 'string', value: '0' });
26+
expect(rootSpan!.attributes['thread.name']).toEqual({ type: 'string', value: 'main' });
2727

2828
const childSpans = spans.filter(s => s.name === 'child-span-1' || s.name === 'child-span-2');
2929
expect(childSpans.length).toBeGreaterThanOrEqual(1);
3030

3131
for (const child of childSpans) {
32-
expect(child.attributes?.['thread.id']).toEqual({ type: 'string', value: '0' });
33-
expect(child.attributes?.['thread.name']).toEqual({ type: 'string', value: 'main' });
32+
expect(child.attributes['thread.id']).toEqual({ type: 'string', value: '0' });
33+
expect(child.attributes['thread.name']).toEqual({ type: 'string', value: 'main' });
3434
}
3535
},
3636
);

dev-packages/browser-integration-tests/suites/public-api/beforeSendSpan-streamed/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sentryTest('beforeSendSpan applies changes to streamed span', async ({ getLocalT
2626
},
2727
},
2828
]);
29-
expect(pageloadSpan.attributes?.['sentry.custom_attribute']).toEqual({
29+
expect(pageloadSpan.attributes['sentry.custom_attribute']).toEqual({
3030
type: 'string',
3131
value: 'customAttributeValue',
3232
});

dev-packages/browser-integration-tests/suites/replay/span-streaming/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sentryTest(
3333
expect(pageloadSpan).toBeDefined();
3434

3535
// Span attribute: sentry.replay_id
36-
expect(pageloadSpan!.attributes?.['sentry.replay_id']).toEqual({
36+
expect(pageloadSpan!.attributes['sentry.replay_id']).toEqual({
3737
type: 'string',
3838
value: replay.session?.id,
3939
});

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-streamed/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ sentryTest('finishes streamed pageload span when the page goes background', asyn
1414

1515
// TODO: Is this what we want?
1616
expect(pageloadSpan.status).toBe('ok');
17-
expect(pageloadSpan.attributes?.['sentry.cancellation_reason']?.value).toBe('document.hidden');
17+
expect(pageloadSpan.attributes['sentry.cancellation_reason']?.value).toBe('document.hidden');
1818
});

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces-streamed/consistent-sampling/default/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
2121
const pageloadSampleRand = Number(envelope[0].trace?.sample_rand);
2222
const pageloadSpan = envelope[1][0][1].items.find(s => getSpanOp(s) === 'pageload')!;
2323

24-
expect(pageloadSpan.attributes?.['sentry.sample_rate']?.value).toBe(1);
24+
expect(pageloadSpan.attributes['sentry.sample_rate']?.value).toBe(1);
2525
expect(Number.isNaN(pageloadSampleRand)).toBe(false);
2626
expect(pageloadSampleRand).toBeGreaterThanOrEqual(0);
2727
expect(pageloadSampleRand).toBeLessThanOrEqual(1);
@@ -101,7 +101,7 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
101101

102102
const pageloadSpan = envelope[1][0][1].items.find(s => getSpanOp(s) === 'pageload')!;
103103

104-
expect(pageloadSpan.attributes?.['sentry.sample_rate']?.value).toBe(1);
104+
expect(pageloadSpan.attributes['sentry.sample_rate']?.value).toBe(1);
105105

106106
return { pageloadSpan, pageloadSampleRand };
107107
});
@@ -125,8 +125,8 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
125125

126126
expect(fetchTraceSampleRand).toBe(pageloadSampleRand);
127127

128-
expect(fetchTraceSpan.attributes?.['sentry.sample_rate']?.value).toEqual(
129-
pageloadSpan.attributes?.['sentry.sample_rate']?.value,
128+
expect(fetchTraceSpan.attributes['sentry.sample_rate']?.value).toEqual(
129+
pageloadSpan.attributes['sentry.sample_rate']?.value,
130130
);
131131
expect(fetchTraceSpan.trace_id).not.toEqual(pageloadSpan.trace_id);
132132

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces-streamed/consistent-sampling/meta/test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains
3232
expect(Number(envelope[0].trace?.sample_rate)).toBe(metaTagSampleRate);
3333

3434
// since the local sample rate was not applied, the sample rate attribute shouldn't be set
35-
expect(span.attributes?.['sentry.sample_rate']).toBeUndefined();
36-
expect(span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]).toBeUndefined();
35+
expect(span.attributes['sentry.sample_rate']).toBeUndefined();
36+
expect(span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]).toBeUndefined();
3737

3838
return span;
3939
});
@@ -57,10 +57,10 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains
5757
expect(envelope[0].trace?.sampled).toBe('true');
5858

5959
// since the local sample rate was not applied, the sample rate attribute shouldn't be set
60-
expect(span.attributes?.['sentry.sample_rate']).toBeUndefined();
60+
expect(span.attributes['sentry.sample_rate']).toBeUndefined();
6161

6262
// but we need to set this attribute to still be able to correctly add the sample rate to the DSC (checked above in trace header)
63-
expect(span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(metaTagSampleRate);
63+
expect(span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(metaTagSampleRate);
6464

6565
return span;
6666
});
@@ -86,10 +86,10 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains
8686
expect(envelope[0].trace?.sampled).toEqual('true');
8787

8888
// since the local sample rate was not applied, the sample rate attribute shouldn't be set
89-
expect(navSpan.attributes?.['sentry.sample_rate']).toBeUndefined();
89+
expect(navSpan.attributes['sentry.sample_rate']).toBeUndefined();
9090

9191
// but we need to set this attribute to still be able to correctly add the sample rate to the DSC (checked above in trace header)
92-
expect(navSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(metaTagSampleRate);
92+
expect(navSpan.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(metaTagSampleRate);
9393
});
9494
});
9595

@@ -115,8 +115,8 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains
115115
expect(Number(envelope[0].trace?.sample_rate)).toBe(metaTagSampleRate);
116116

117117
// since the local sample rate was not applied, the sample rate attribute shouldn't be set
118-
expect(span.attributes?.['sentry.sample_rate']).toBeUndefined();
119-
expect(span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]).toBeUndefined();
118+
expect(span.attributes['sentry.sample_rate']).toBeUndefined();
119+
expect(span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]).toBeUndefined();
120120

121121
return span;
122122
});
@@ -140,8 +140,8 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains
140140

141141
expect(fetchTraceSampleRand).toEqual(metaTagSampleRand);
142142

143-
expect(fetchTraceSpan.attributes?.['sentry.sample_rate']).toBeUndefined();
144-
expect(fetchTraceSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(
143+
expect(fetchTraceSpan.attributes['sentry.sample_rate']).toBeUndefined();
144+
expect(fetchTraceSpan.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE]?.value).toBe(
145145
metaTagSampleRate,
146146
);
147147

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces-streamed/consistent-sampling/tracesSampler-precedence/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
3232
const envelope = await pageloadEnvelopePromise;
3333
const pageloadSpan = envelope[1][0][1].items.find(s => getSpanOp(s) === 'pageload')!;
3434

35-
expect(pageloadSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
35+
expect(pageloadSpan.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
3636
expect(Number(envelope[0].trace?.sample_rand)).toBeGreaterThanOrEqual(0);
3737

3838
return { pageloadSpan };
@@ -96,7 +96,7 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
9696
const envelope = await customEnvelopePromise;
9797
const customTrace2Span = envelope[1][0][1].items.find(s => getSpanOp(s) === 'custom')!;
9898

99-
expect(customTrace2Span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
99+
expect(customTrace2Span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
100100
expect(customTrace2Span.trace_id).not.toEqual(pageloadSpan.trace_id);
101101
expect(customTrace2Span.parent_span_id).toBeUndefined();
102102

@@ -129,7 +129,7 @@ sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
129129
const envelope = await navigationEnvelopePromise;
130130
const navigationSpan = envelope[1][0][1].items.find(s => getSpanOp(s) === 'navigation')!;
131131

132-
expect(navigationSpan.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
132+
expect(navigationSpan.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]?.value).toBe(1);
133133
expect(navigationSpan.trace_id).not.toEqual(customTrace2Span.trace_id);
134134
expect(navigationSpan.parent_span_id).toBeUndefined();
135135

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces-streamed/default/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sentryTest("navigation spans link back to previous trace's root span", async ({
4141
},
4242
]);
4343

44-
expect(navigation1Span.attributes?.['sentry.previous_trace']).toEqual({
44+
expect(navigation1Span.attributes['sentry.previous_trace']).toEqual({
4545
type: 'string',
4646
value: `${pageloadTraceId}-${pageloadSpan.span_id}-1`,
4747
});
@@ -60,7 +60,7 @@ sentryTest("navigation spans link back to previous trace's root span", async ({
6060
},
6161
]);
6262

63-
expect(navigation2Span.attributes?.['sentry.previous_trace']).toEqual({
63+
expect(navigation2Span.attributes['sentry.previous_trace']).toEqual({
6464
type: 'string',
6565
value: `${navigation1TraceId}-${navigation1Span.span_id}-1`,
6666
});

0 commit comments

Comments
 (0)