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

⚡ Performance Friday Reduce Bundle Size #2875

Merged
merged 12 commits into from
Jul 24, 2024
2 changes: 1 addition & 1 deletion packages/core/src/domain/error/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function computeRawError({
? toStackTraceString(stackTrace)
: NO_ERROR_STACK_PRESENT_MESSAGE
const causes = isErrorInstance ? flattenErrorCauses(originalError as ErrorWithCause, source) : undefined
const type = stackTrace?.name
const type = stackTrace ? stackTrace.name : undefined
const fingerprint = tryToGetFingerprint(originalError)

return {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tools/serialisation/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export function sanitize(source: unknown, maxCharacterCount = SANITIZE_DEFAULT_M
containerQueue,
visitedObjectsWithPath
)
let accumulatedCharacterCount = JSON.stringify(sanitizedData)?.length || 0
const serializedSanitizedData = JSON.stringify(sanitizedData)
let accumulatedCharacterCount = serializedSanitizedData ? serializedSanitizedData.length : 0

if (accumulatedCharacterCount > maxCharacterCount) {
warnOverCharacterLimit(maxCharacterCount, 'discarded', source)
return undefined
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/transport/startBatchWithReplica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export function startBatchWithReplica<T extends Context>(

stop: () => {
primaryBatch.stop()
replicaBatch?.stop()
if (replicaBatch) {
replicaBatch.stop()
}
},
}
}
4 changes: 3 additions & 1 deletion packages/core/test/interceptRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export function interceptRequests() {
if (originalFetch) {
window.fetch = originalFetch
}
xhrManager?.reset()
if (xhrManager) {
xhrManager.reset()
}
MockXhr.onSend = noop
},
}
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function startLogsAssembly(
const log = combine(
{
service: configuration.service,
session_id: session?.id,
session_id: session ? session.id : undefined,
// Insert user first to allow overrides from global context
usr: !isEmptyObject(commonContext.user) ? commonContext.user : undefined,
view: commonContext.view,
Expand Down
10 changes: 5 additions & 5 deletions packages/rum-core/src/boot/rumPublicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ export function makeRumPublicApi(
addTelemetryUsage({ feature: 'start-duration-vital' })
return strategy.startDurationVital({
name: sanitize(name)!,
context: sanitize(options?.context) as Context,
details: sanitize(options?.details) as string | undefined,
context: sanitize(options && options.context) as Context,
details: sanitize(options && options.details) as string | undefined,
})
}
)
Expand All @@ -355,8 +355,8 @@ export function makeRumPublicApi(
type: VitalType.DURATION,
startClocks: timeStampToClocks(options.startTime as TimeStamp),
duration: options.duration as Duration,
context: sanitize(options?.context) as Context,
details: sanitize(options?.details) as string | undefined,
context: sanitize(options && options.context) as Context,
details: sanitize(options && options.details) as string | undefined,
})
}
)
Expand Down Expand Up @@ -524,7 +524,7 @@ export function makeRumPublicApi(
getSessionReplayLink: monitor(() => recorderApi.getSessionReplayLink()),
startSessionReplayRecording: monitor((options?: StartRecordingOptions) => {
recorderApi.start(options)
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options?.force })
addTelemetryUsage({ feature: 'start-session-replay-recording', force: options && options.force })
}),

stopSessionReplayRecording: monitor(() => recorderApi.stop()),
Expand Down
4 changes: 3 additions & 1 deletion packages/rum-core/src/browser/performanceObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ export function createPerformanceObservable<T extends RumPerformanceEntryType>(
manageResourceTimingBufferFull(configuration)

return () => {
observer?.disconnect()
if (observer) {
observer.disconnect()
}
if (timeoutId) {
clearTimeout(timeoutId)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/browser/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function getClassList(element: Element): DOMTokenList | string[] {
return element.classList
}

const classes = element.getAttribute('class')?.trim()
const classes = (element.getAttribute('class') || '').trim()
return classes ? classes.split(/\s+/) : []
}

Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ function shouldSend(
}

const rateLimitReached = eventRateLimiters[event.type]?.isLimitReached()

return !rateLimitReached
}

Expand Down
4 changes: 3 additions & 1 deletion packages/rum-core/src/domain/view/trackViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export function trackViews(
},

stop: () => {
locationChangeSubscription?.unsubscribe()
if (locationChangeSubscription) {
locationChangeSubscription.unsubscribe()
}
currentView.end()
activeViews.forEach((view) => view.stop())
},
Expand Down
4 changes: 3 additions & 1 deletion packages/rum-core/test/testSetupBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ export function setup(): TestSetupBuilder {
registerCleanupTask(() => {
cleanupTasks.forEach((task) => task())
// perform these steps at the end to generate correct events in cleanup and validate them
clock?.cleanup()
if (clock) {
clock.cleanup()
}
rawRumEventsCollected.unsubscribe()
})
return setupBuilder
Expand Down
4 changes: 2 additions & 2 deletions packages/rum/src/boot/recorderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function makeRecorderApi(

startStrategy = (options?: StartRecordingOptions) => {
const session = sessionManager.findTrackedSession()
if (!session || (session.sessionReplay === SessionReplayState.OFF && !options?.force)) {
if (!session || (session.sessionReplay === SessionReplayState.OFF && (!options || !options.force))) {
state = { status: RecorderStatus.IntentToStart }
return
}
Expand Down Expand Up @@ -181,7 +181,7 @@ export function makeRecorderApi(
}
})

if (options?.force && session.sessionReplay === SessionReplayState.OFF) {
if (options && options.force && session.sessionReplay === SessionReplayState.OFF) {
sessionManager.setForcedReplay()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function trackFrustration(
data.rawRumEvent.action.type === ActionType.CLICK &&
data.rawRumEvent.action.frustration?.type?.length &&
'events' in data.domainContext &&
data.domainContext.events?.length
data.domainContext.events &&
data.domainContext.events.length
) {
frustrationCb({
timestamp: data.rawRumEvent.date,
Expand Down
2 changes: 1 addition & 1 deletion packages/rum/src/domain/record/trackers/trackMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function processAttributesMutations(
const handledElements = new Map<Element, Set<string>>()
const filteredMutations = mutations.filter((mutation) => {
const handledAttributes = handledElements.get(mutation.target)
if (handledAttributes?.has(mutation.attributeName!)) {
if (handledAttributes && handledAttributes.has(mutation.attributeName!)) {
return false
}
if (!handledAttributes) {
Expand Down