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-6581] Add an init parameter to chose feature flags event collection #3198

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
Extract feature flag collection check as a function
RomanGaignault committed Dec 11, 2024
commit 9b51f1bdde33b75cd3badd7926d237743f5ba299
19 changes: 19 additions & 0 deletions packages/rum-core/src/domain/collectFeatureFlags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Context, RelativeTime } from '@datadog/browser-core'
import { includes, isEmptyObject } from '@datadog/browser-core'
import type { FeatureFlagEvent } from './configuration'
import type { FeatureFlagContexts } from './contexts/featureFlagContext'

export function enableFeatureFlagsCollection(
eventType: FeatureFlagEvent,
eventStartTime: RelativeTime,
collectFeatureFlagsOn: FeatureFlagEvent[],
featureFlagContexts: FeatureFlagContexts,
rawRumEvent: { feature_flags?: Context }
) {
if (includes(collectFeatureFlagsOn, eventType)) {
const featureFlagContext = featureFlagContexts.findFeatureFlagEvaluations(eventStartTime)
if (featureFlagContext && !isEmptyObject(featureFlagContext)) {
rawRumEvent.feature_flags = featureFlagContext
}
}
}
16 changes: 8 additions & 8 deletions packages/rum-core/src/domain/error/errorCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Context, RawError, ClocksState } from '@datadog/browser-core'
import {
isEmptyObject,
assign,
ErrorSource,
generateUUID,
@@ -11,8 +10,8 @@ import {
trackRuntimeError,
NonErrorPrefix,
isError,
includes,
} from '@datadog/browser-core'
import { enableFeatureFlagsCollection } from '../collectFeatureFlags'
import type { FeatureFlagEvent, RumConfiguration } from '../configuration'
import type { RawRumErrorEvent } from '../../rawRumEvent.types'
import { RumEventType } from '../../rawRumEvent.types'
@@ -119,12 +118,13 @@ function processError(
view: { in_foreground: pageStateHistory.wasInPageStateAt(PageState.ACTIVE, error.startClocks.relative) },
}

if (includes(collectFeatureFlagsOn, 'error')) {
const featureFlagContext = featureFlagContexts.findFeatureFlagEvaluations(error.startClocks.relative)
if (featureFlagContext && !isEmptyObject(featureFlagContext)) {
rawRumEvent.feature_flags = featureFlagContext
}
}
enableFeatureFlagsCollection(
'error',
error.startClocks.relative,
collectFeatureFlagsOn,
featureFlagContexts,
rawRumEvent
)

const domainContext: RumErrorEventDomainContext = {
error: error.originalError,
16 changes: 9 additions & 7 deletions packages/rum-core/src/domain/view/viewCollection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Duration, ServerDuration, Observable } from '@datadog/browser-core'
import { isEmptyObject, mapValues, toServerDuration, includes } from '@datadog/browser-core'
import { isEmptyObject, mapValues, toServerDuration } from '@datadog/browser-core'
import { enableFeatureFlagsCollection } from '../collectFeatureFlags'
import { discardNegativeDuration } from '../discardNegativeDuration'
import type { RecorderApi } from '../../boot/rumPublicApi'
import type { RawRumViewEvent } from '../../rawRumEvent.types'
@@ -125,12 +126,13 @@ function processViewUpdate(
)
}

if (includes(configuration.collectFeatureFlagsOn, 'view')) {
const featureFlagContext = featureFlagContexts.findFeatureFlagEvaluations(view.startClocks.relative)
if (featureFlagContext && !isEmptyObject(featureFlagContext)) {
viewEvent.feature_flags = featureFlagContext
}
}
enableFeatureFlagsCollection(
'view',
view.startClocks.relative,
configuration.collectFeatureFlagsOn,
featureFlagContexts,
viewEvent
)

return {
rawRumEvent: viewEvent,
24 changes: 9 additions & 15 deletions packages/rum-core/src/domain/vital/vitalCollection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import type { ClocksState, Duration, Context } from '@datadog/browser-core'
import {
clocksNow,
combine,
elapsed,
generateUUID,
toServerDuration,
isEmptyObject,
includes,
} from '@datadog/browser-core'
import { clocksNow, combine, elapsed, generateUUID, toServerDuration } from '@datadog/browser-core'
import { enableFeatureFlagsCollection } from '../collectFeatureFlags'
import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle'
import { LifeCycleEventType } from '../lifeCycle'
import type { RawRumVitalEvent } from '../../rawRumEvent.types'
@@ -169,12 +162,13 @@ function processVital(
}
}

if (includes(collectFeatureFlagsOn, 'vital')) {
const featureFlagContext = featureFlagContexts.findFeatureFlagEvaluations(vital.startClocks.relative)
if (featureFlagContext && !isEmptyObject(featureFlagContext)) {
rawRumEvent.feature_flags = featureFlagContext
}
}
enableFeatureFlagsCollection(
'vital',
vital.startClocks.relative,
collectFeatureFlagsOn,
featureFlagContexts,
rawRumEvent
)

return {
rawRumEvent,