Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): Remove optional chaining in INP code #12196

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/browser-utils/src/metrics/inp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ function _trackINP(): () => void {
const replayId = replay && replay.getReplayId();

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

const name = htmlTreeAsString(entry.target);
const attributes: SpanAttributes = dropUndefinedKeys({
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Contexts extends Record<string, Context | undefined> {
trace?: TraceContext;
cloud_resource?: CloudResourceContext;
state?: StateContext;
profile?: ProfileContext;
}

export interface StateContext extends Record<string, unknown> {
Expand Down Expand Up @@ -114,3 +115,7 @@ export interface CloudResourceContext extends Record<string, unknown> {
['host.id']?: string;
['host.type']?: string;
}

export interface ProfileContext extends Record<string, unknown> {
profile_id: string;
}
Loading