Skip to content

Commit a9cef35

Browse files
authored
fix(browser): Remove optional chaining in INP code (#12196)
1 parent 0ac519a commit a9cef35

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/browser-utils/src/metrics/inp.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ function _trackINP(): () => void {
9393
const replayId = replay && replay.getReplayId();
9494

9595
const userDisplay = user !== undefined ? user.email || user.id || user.ip_address : undefined;
96-
const profileId = scope.getScopeData().contexts?.profile?.profile_id as string | undefined;
96+
let profileId: string | undefined = undefined;
97+
try {
98+
// @ts-expect-error skip optional chaining to save bundle size with try catch
99+
profileId = scope.getScopeData().contexts.profile.profile_id;
100+
} catch {
101+
// do nothing
102+
}
97103

98104
const name = htmlTreeAsString(entry.target);
99105
const attributes: SpanAttributes = dropUndefinedKeys({

packages/types/src/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface Contexts extends Record<string, Context | undefined> {
1212
trace?: TraceContext;
1313
cloud_resource?: CloudResourceContext;
1414
state?: StateContext;
15+
profile?: ProfileContext;
1516
}
1617

1718
export interface StateContext extends Record<string, unknown> {
@@ -114,3 +115,7 @@ export interface CloudResourceContext extends Record<string, unknown> {
114115
['host.id']?: string;
115116
['host.type']?: string;
116117
}
118+
119+
export interface ProfileContext extends Record<string, unknown> {
120+
profile_id: string;
121+
}

0 commit comments

Comments
 (0)