Skip to content

Commit

Permalink
Integrate seth.fowler/new-web-vitals-attribution-fields (#3251) into …
Browse files Browse the repository at this point in the history
…staging-03

Integrated commit sha: dde4a81

Co-authored-by: Seth Fowler <[email protected]>
  • Loading branch information
dd-mergequeue[bot] and sethfowler-datadog authored Jan 14, 2025
2 parents c7284f8 + dde4a81 commit 9cedaef
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 8 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/domain/telemetry/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
*/
is_main_process?: boolean
/**
* The list of events that include feature flags collection
* The list of events that include feature flags collection. The tracking is always enabled for views and errors.
*/
collect_feature_flags_on?: ('view' | 'error' | 'vital')[]
track_feature_flags_for_events?: ('vital' | 'resource' | 'action' | 'long_task')[]
/**
* Whether the anonymous users are tracked
*/
Expand Down Expand Up @@ -433,6 +433,7 @@ export type TelemetryCommonFeaturesUsage =
| AddError
| SetGlobalContext
| SetUser
| SetAccount
| AddFeatureFlagEvaluation
/**
* Schema of browser specific features usage
Expand Down Expand Up @@ -623,6 +624,13 @@ export interface SetUser {
feature: 'set-user'
[k: string]: unknown
}
export interface SetAccount {
/**
* setAccount, setAccountProperty APIs
*/
feature: 'set-account'
[k: string]: unknown
}
export interface AddFeatureFlagEvaluation {
/**
* addFeatureFlagEvaluation API
Expand Down
24 changes: 24 additions & 0 deletions packages/rum-core/src/domain/view/viewCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ describe('viewCollection', () => {
long_task: {
count: 10,
},
performance: {
cls: {
score: 1,
timestamp: (100 * 1e6) as ServerDuration,
target_selector: undefined,
},
fcp: {
timestamp: (10 * 1e6) as ServerDuration,
},
fid: {
duration: (12 * 1e6) as ServerDuration,
timestamp: (10 * 1e6) as ServerDuration,
target_selector: undefined,
},
inp: {
duration: (10 * 1e6) as ServerDuration,
timestamp: (100 * 1e6) as ServerDuration,
target_selector: undefined,
},
lcp: {
timestamp: (10 * 1e6) as ServerDuration,
target_selector: undefined,
},
},
resource: {
count: 10,
},
Expand Down
33 changes: 32 additions & 1 deletion packages/rum-core/src/domain/view/viewCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Duration, ServerDuration, Observable } from '@datadog/browser-core
import { isEmptyObject, mapValues, toServerDuration } from '@datadog/browser-core'
import { discardNegativeDuration } from '../discardNegativeDuration'
import type { RecorderApi } from '../../boot/rumPublicApi'
import type { RawRumViewEvent } from '../../rawRumEvent.types'
import type { RawRumViewEvent, ViewPerformanceData } from '../../rawRumEvent.types'
import { RumEventType } from '../../rawRumEvent.types'
import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle'
import { LifeCycleEventType } from '../lifeCycle'
Expand All @@ -12,6 +12,8 @@ import type { FeatureFlagContexts } from '../contexts/featureFlagContext'
import type { PageStateHistory } from '../contexts/pageStateHistory'
import type { ViewEvent, ViewOptions } from './trackViews'
import { trackViews } from './trackViews'
import type { CommonViewMetrics } from './viewMetrics/trackCommonViewMetrics'
import type { InitialViewMetrics } from './viewMetrics/trackInitialViewMetrics'

export function startViewCollection(
lifeCycle: LifeCycle,
Expand Down Expand Up @@ -98,6 +100,7 @@ function processViewUpdate(
long_task: {
count: view.eventCounts.longTaskCount,
},
performance: computeViewPerformanceData(view.commonViewMetrics, view.initialViewMetrics),
resource: {
count: view.eventCounts.resourceCount,
},
Expand Down Expand Up @@ -137,3 +140,31 @@ function processViewUpdate(
},
}
}

function computeViewPerformanceData(
{ cumulativeLayoutShift, interactionToNextPaint }: CommonViewMetrics,
{ firstContentfulPaint, firstInput, largestContentfulPaint }: InitialViewMetrics
): ViewPerformanceData {
return {
cls: cumulativeLayoutShift && {
score: cumulativeLayoutShift.value,
timestamp: toServerDuration(cumulativeLayoutShift.time),
target_selector: cumulativeLayoutShift.targetSelector,
},
fcp: firstContentfulPaint && { timestamp: toServerDuration(firstContentfulPaint) },
fid: firstInput && {
duration: toServerDuration(firstInput.delay),
timestamp: toServerDuration(firstInput.time),
target_selector: firstInput.targetSelector,
},
inp: interactionToNextPaint && {
duration: toServerDuration(interactionToNextPaint.value),
timestamp: toServerDuration(interactionToNextPaint.time),
target_selector: interactionToNextPaint.targetSelector,
},
lcp: largestContentfulPaint && {
timestamp: toServerDuration(largestContentfulPaint.value),
target_selector: largestContentfulPaint.targetSelector,
},
}
}
26 changes: 26 additions & 0 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface RawRumViewEvent {
long_task: Count
resource: Count
frustration: Count
performance?: ViewPerformanceData
}
session: {
has_replay: true | undefined
Expand Down Expand Up @@ -152,6 +153,31 @@ interface ViewDisplay {
}
}

export interface ViewPerformanceData {
cls?: {
score: number
timestamp?: ServerDuration
target_selector?: string
}
fcp?: {
timestamp: number
}
fid?: {
duration: ServerDuration
timestamp: ServerDuration
target_selector?: string
}
inp?: {
duration: ServerDuration
timestamp?: ServerDuration
target_selector?: string
}
lcp?: {
timestamp: ServerDuration
target_selector?: string
}
}

export type PageStateServerEntry = { state: PageState; start: ServerDuration }

export const enum ViewLoadingType {
Expand Down
52 changes: 48 additions & 4 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ export type RumViewEvent = CommonProperties &
* The JavaScript refresh rate for React Native
*/
js_refresh_rate?: RumPerfMetric
/**
* Performance data. (Web Vitals, etc.)
*/
performance?: ViewPerformanceData
[k: string]: unknown
}
/**
Expand Down Expand Up @@ -1169,10 +1173,6 @@ export type RumViewEvent = CommonProperties &
}
[k: string]: unknown
}
/**
* Performance data. (Web Vitals, etc.)
*/
performance?: ViewPerformanceData
[k: string]: unknown
}
/**
Expand Down Expand Up @@ -1343,6 +1343,20 @@ export interface CommonProperties {
readonly anonymous_id?: string
[k: string]: unknown
}
/**
* Account properties
*/
readonly account?: {
/**
* Identifier of the account
*/
readonly id: string
/**
* Name of the account
*/
readonly name?: string
[k: string]: unknown
}
/**
* Device connectivity properties
*/
Expand Down Expand Up @@ -1630,6 +1644,14 @@ export interface ViewPerformanceData {
* CSS selector path of the first element (in document order) of the largest layout shift contributing to CLS
*/
readonly target_selector?: string
/**
* Bounding client rect of the element before the layout shift
*/
previous_rect?: RumRect
/**
* Bounding client rect of the element after the layout shift
*/
current_rect?: RumRect
[k: string]: unknown
}
/**
Expand Down Expand Up @@ -1694,3 +1716,25 @@ export interface ViewPerformanceData {
}
[k: string]: unknown
}
/**
* Schema for DOMRect-like rectangles describing an element's bounding client rect
*/
export interface RumRect {
/**
* The x coordinate of the element's origin
*/
readonly x: number
/**
* The y coordinate of the element's origin
*/
readonly y: number
/**
* The element's width
*/
readonly width: number
/**
* The element's height
*/
readonly height: number
[k: string]: unknown
}

0 comments on commit 9cedaef

Please sign in to comment.