Skip to content

Commit e5f21ab

Browse files
refactor out some optional chaining
1 parent bbdc8f0 commit e5f21ab

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,14 @@ function registerInpInteractionListener(
543543
const client = getClient();
544544
// We need to get the replay, user, and activeTransaction from the current scope
545545
// so that we can associate replay id, profile id, and a user display to the span
546-
const replay = client?.getIntegrationByName?.('Replay') as
547-
| (Integration & { getReplayId: () => string })
548-
| undefined;
546+
const replay =
547+
client !== undefined && client.getIntegrationByName !== undefined
548+
? (client.getIntegrationByName('Replay') as Integration & { getReplayId: () => string })
549+
: undefined;
549550
// eslint-disable-next-line deprecation/deprecation
550551
const activeTransaction = getActiveTransaction();
551-
const user = getCurrentScope()?.getUser();
552+
const currentScope = getCurrentScope();
553+
const user = currentScope !== undefined ? currentScope.getUser() : undefined;
552554
for (const entry of entries) {
553555
if (isPerformanceEventTiming(entry)) {
554556
const duration = entry.duration;

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ function _trackINP(interactionIdtoRouteNameMapping: InteractionRouteNameMapping)
224224
user: undefined,
225225
replay: undefined,
226226
};
227+
const userDisplay = user !== undefined ? user.email || user.id || user.ip_address : undefined;
227228
// eslint-disable-next-line deprecation/deprecation
228-
const userDisplay = user?.email || user?.id || user?.ip_address;
229-
const profileId = activeTransaction?.getProfileId();
230-
const replayId = replay?.getReplayId();
229+
const profileId = activeTransaction !== undefined ? activeTransaction.getProfileId() : undefined;
230+
const replayId = replay !== undefined ? replay.getReplayId() : undefined;
231231
const span = new Span({
232232
startTimestamp: startTime,
233233
endTimestamp: startTime + duration,

0 commit comments

Comments
 (0)