Skip to content

Commit f862dd6

Browse files
authored
ref: Remove unnecessary checks for SpanJSON.data existence (#14731)
Since this was reworked in #14693 to always return something, we can safe some checks/fallbacks. This most likely does not change all the things, but focuses on the places that were easy to find/replace.
1 parent edbb214 commit f862dd6

File tree

24 files changed

+45
-44
lines changed

24 files changed

+45
-44
lines changed

packages/browser/src/tracing/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function isPerformanceResourceTiming(entry: PerformanceEntry): entry is Performa
208208
* @param span A span that has yet to be finished, must contain `url` on data.
209209
*/
210210
function addHTTPTimings(span: Span): void {
211-
const { url } = spanToJSON(span).data || {};
211+
const { url } = spanToJSON(span).data;
212212

213213
if (!url || typeof url !== 'string') {
214214
return;

packages/browser/test/tracing/browserTracingIntegration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ describe('browserTracingIntegration', () => {
426426
const pageloadSpan = getActiveSpan();
427427

428428
expect(spanToJSON(pageloadSpan!).description).toBe('changed');
429-
expect(spanToJSON(pageloadSpan!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
429+
expect(spanToJSON(pageloadSpan!).data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
430430
});
431431

432432
describe('startBrowserTracingNavigationSpan', () => {
@@ -608,7 +608,7 @@ describe('browserTracingIntegration', () => {
608608
const pageloadSpan = getActiveSpan();
609609

610610
expect(spanToJSON(pageloadSpan!).description).toBe('changed');
611-
expect(spanToJSON(pageloadSpan!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
611+
expect(spanToJSON(pageloadSpan!).data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom');
612612
});
613613

614614
it('sets the navigation span name on `scope.transactionName`', () => {

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
9494
// Else, we generate it from the span
9595
const dsc = getDynamicSamplingContextFromClient(span.spanContext().traceId, client);
9696
const jsonSpan = spanToJSON(rootSpan);
97-
const attributes = jsonSpan.data || {};
97+
const attributes = jsonSpan.data;
9898
const maybeSampleRate = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
9999

100100
if (maybeSampleRate != null) {

packages/core/src/tracing/idleSpan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getClient, getCurrentScope } from '../currentScopes';
2-
import type { Span, SpanAttributes, StartSpanOptions } from '../types-hoist';
2+
import type { Span, StartSpanOptions } from '../types-hoist';
33

44
import { DEBUG_BUILD } from '../debug-build';
55
import { SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON } from '../semanticAttributes';
@@ -255,7 +255,7 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
255255
return;
256256
}
257257

258-
const attributes: SpanAttributes = spanJSON.data || {};
258+
const attributes = spanJSON.data;
259259
if (!attributes[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]) {
260260
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, _finishReason);
261261
}

packages/core/test/lib/tracing/sentrySpan.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('SentrySpan', () => {
3030

3131
const spanJson = spanToJSON(span);
3232
expect(spanJson.description).toEqual('new name');
33-
expect(spanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom');
33+
expect(spanJson.data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom');
3434
});
3535
});
3636

packages/nestjs/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function init(options: NodeOptions | undefined = {}): NodeClient | undefi
3030
}
3131

3232
function addNestSpanAttributes(span: Span): void {
33-
const attributes = spanToJSON(span).data || {};
33+
const attributes = spanToJSON(span).data;
3434

3535
// this is one of: app_creation, request_context, handler
3636
const type = attributes['nestjs.type'];

packages/nestjs/src/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Module({
252252
export { SentryModule };
253253

254254
function addNestSpanAttributes(span: Span): void {
255-
const attributes = spanToJSON(span).data || {};
255+
const attributes = spanToJSON(span).data;
256256

257257
// this is one of: app_creation, request_context, handler
258258
const type = attributes['nestjs.type'];

packages/nextjs/src/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ export function init(options: NodeOptions): NodeClient | undefined {
308308
event.type === 'transaction' &&
309309
event.contexts?.trace?.data?.['next.span_type'] === 'BaseServer.handleRequest'
310310
) {
311-
event.contexts.trace.data = event.contexts.trace.data || {};
312311
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';
313312
event.contexts.trace.op = 'http.server';
314313

packages/node/src/integrations/tracing/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const setupConnectErrorHandler = (app: ConnectApp): void => {
8989
};
9090

9191
function addConnectSpanAttributes(span: Span): void {
92-
const attributes = spanToJSON(span).data || {};
92+
const attributes = spanToJSON(span).data;
9393

9494
// this is one of: middleware, request_handler
9595
const type = attributes['connect.type'];

packages/node/src/integrations/tracing/express.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const instrumentExpress = generateInstrumentOnce(
2626
requestHook(span) {
2727
addOriginToSpan(span, 'auto.http.otel.express');
2828

29-
const attributes = spanToJSON(span).data || {};
29+
const attributes = spanToJSON(span).data;
3030
// this is one of: middleware, request_handler, router
3131
const type = attributes['express.type'];
3232

0 commit comments

Comments
 (0)