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

šŸ› [RUM-1666] Don't set negative action loading time #2764

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions packages/rum-core/src/domain/action/actionCollection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core'
import { createNewEvent } from '@datadog/browser-core/test'
import type { RawRumActionEvent } from '@datadog/browser-rum-core'
import type { TestSetupBuilder } from '../../../test'
import { setup } from '../../../test'
import { RumEventType, ActionType } from '../../rawRumEvent.types'
Expand Down Expand Up @@ -117,4 +118,24 @@ describe('actionCollection', () => {
})
expect(rawRumEvents[0].domainContext).toEqual({})
})
it('should not set the loading time field of the action', () => {
const { lifeCycle, rawRumEvents } = setupBuilder.build()
const event = createNewEvent('pointerup', { target: document.createElement('button') })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, {
counts: {
errorCount: 0,
longTaskCount: 0,
resourceCount: 0,
},
duration: -10 as Duration,
event,
events: [event],
frustrationTypes: [],
id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
name: 'foo',
startClocks: { relative: 0 as RelativeTime, timeStamp: 0 as TimeStamp },
type: ActionType.CLICK,
})
expect((rawRumEvents[0].rawRumEvent as RawRumActionEvent).action.loading_time).toBeUndefined()
})
})
3 changes: 2 additions & 1 deletion packages/rum-core/src/domain/action/actionCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ClocksState, Context, Observable } from '@datadog/browser-core'
import { noop, assign, combine, toServerDuration, generateUUID } from '@datadog/browser-core'

import { discardNegativeDuration } from '../view/viewCollection'
import type { RawRumActionEvent } from '../../rawRumEvent.types'
import { ActionType, RumEventType } from '../../rawRumEvent.types'
import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle'
Expand Down Expand Up @@ -62,7 +63,7 @@ function processAction(
? {
action: {
id: action.id,
loading_time: toServerDuration(action.duration),
loading_time: discardNegativeDuration(toServerDuration(action.duration)),
frustration: {
type: action.frustrationTypes,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/view/viewCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ function processViewUpdate(
}
}

function discardNegativeDuration(duration: ServerDuration | undefined): ServerDuration | undefined {
export function discardNegativeDuration(duration: ServerDuration | undefined): ServerDuration | undefined {
RomanGaignault marked this conversation as resolved.
Show resolved Hide resolved
return isNumber(duration) && duration < 0 ? undefined : duration
}