Skip to content

Commit

Permalink
Merge branch 'main' into congyao/RUM-4908-add-only-link-to-facet-list
Browse files Browse the repository at this point in the history
  • Loading branch information
cy-moi committed Feb 4, 2025
2 parents fe4e6ab + 8a7de5a commit 5c1218c
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 410 deletions.
32 changes: 32 additions & 0 deletions packages/core/src/domain/telemetry/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ export type TelemetryCommonFeaturesUsage =
| SetTrackingConsent
| StopSession
| StartView
| SetViewContext
| SetViewContextProperty
| SetViewName
| GetViewContext
| AddAction
| AddError
| SetGlobalContext
Expand Down Expand Up @@ -596,6 +600,34 @@ export interface StartView {
feature: 'start-view'
[k: string]: unknown
}
export interface SetViewContext {
/**
* setViewContext API
*/
feature: 'set-view-context'
[k: string]: unknown
}
export interface SetViewContextProperty {
/**
* setViewContextProperty API
*/
feature: 'set-view-context-property'
[k: string]: unknown
}
export interface SetViewName {
/**
* setViewName API
*/
feature: 'set-view-name'
[k: string]: unknown
}
export interface GetViewContext {
/**
* getViewContext API
*/
feature: 'get-view-context'
[k: string]: unknown
}
export interface AddAction {
/**
* addAction API
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum ExperimentalFeature {
REMOTE_CONFIGURATION = 'remote_configuration',
ACTION_NAME_MASKING = 'action_name_masking',
CONSISTENT_TRACE_SAMPLING = 'consistent_trace_sampling',
MISSING_URL_CONTEXT_TELEMETRY = 'missing_url_context_telemetry',
}

const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/tools/valueHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ValueHistory<Value> {
stop: () => void

getAllEntries: () => Context[]
getDeletedEntries: () => RelativeTime[]
}

export function createValueHistory<Value>({
Expand All @@ -41,12 +42,16 @@ export function createValueHistory<Value>({
maxEntries?: number
}): ValueHistory<Value> {
let entries: Array<ValueHistoryEntry<Value>> = []
const deletedEntries: RelativeTime[] = []
const clearOldValuesInterval: TimeoutId = setInterval(() => clearOldValues(), CLEAR_OLD_VALUES_INTERVAL)

function clearOldValues() {
const oldTimeThreshold = relativeNow() - expireDelay
while (entries.length > 0 && entries[entries.length - 1].endTime < oldTimeThreshold) {
entries.pop()
const entry = entries.pop()
if (entry) {
deletedEntries.push(entry.startTime)
}
}
}

Expand Down Expand Up @@ -127,6 +132,10 @@ export function createValueHistory<Value>({
})) as Context[]
}

function getDeletedEntries() {
return deletedEntries
}

/**
* Remove all entries from this collection.
*/
Expand All @@ -141,5 +150,5 @@ export function createValueHistory<Value>({
clearInterval(clearOldValuesInterval)
}

return { add, find, closeActive, findAll, reset, stop, getAllEntries }
return { add, find, closeActive, findAll, reset, stop, getAllEntries, getDeletedEntries }
}
8 changes: 7 additions & 1 deletion packages/rum-core/src/boot/rumPublicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,23 @@ export function makeRumPublicApi(

setViewName: monitor((name: string) => {
strategy.setViewName(name)
addTelemetryUsage({ feature: 'set-view-name' })
}),

setViewContext: monitor((context: Context) => {
strategy.setViewContext(context)
addTelemetryUsage({ feature: 'set-view-context' })
}),

setViewContextProperty: monitor((key: string, value: any) => {
strategy.setViewContextProperty(key, value)
addTelemetryUsage({ feature: 'set-view-context-property' })
}),

getViewContext: monitor(() => strategy.getViewContext()),
getViewContext: monitor(() => {
addTelemetryUsage({ feature: 'set-view-context-property' })
return strategy.getViewContext()
}),

setGlobalContext: monitor((context) => {
globalContextManager.setContext(context)
Expand Down
18 changes: 4 additions & 14 deletions packages/rum-core/src/boot/startRum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ import { startViewCollection } from '../domain/view/viewCollection'
import type { RumEvent, RumViewEvent } from '../rumEvent.types'
import type { LocationChange } from '../browser/locationChangeObservable'
import { startLongAnimationFrameCollection } from '../domain/longAnimationFrame/longAnimationFrameCollection'
import { startViewHistory, type RumSessionManager } from '..'
import type { RumSessionManager } from '..'
import type { RumConfiguration } from '../domain/configuration'
import { RumEventType } from '../rawRumEvent.types'
import { startFeatureFlagContexts } from '../domain/contexts/featureFlagContext'
import type { PageStateHistory } from '../domain/contexts/pageStateHistory'
import { createCustomVitalsState } from '../domain/vital/vitalCollection'
import { createHooks } from '../hooks'
import { startUrlContexts } from '../domain/contexts/urlContexts'
import { startRum, startRumEventCollection } from './startRum'

function collectServerEvents(lifeCycle: LifeCycle) {
Expand All @@ -68,20 +66,16 @@ function startRumStub(
pageStateHistory: PageStateHistory,
reportError: (error: RawError) => void
) {
const hooks = createHooks()
const viewHistory = startViewHistory(lifeCycle)
const urlContexts = startUrlContexts(lifeCycle, hooks, locationChangeObservable, location, viewHistory)

const { stop: rumEventCollectionStop } = startRumEventCollection(
lifeCycle,
hooks,
configuration,
location,
sessionManager,
pageStateHistory,
locationChangeObservable,
domMutationObservable,
startFeatureFlagContexts(lifeCycle, createCustomerDataTracker(noop)),
windowOpenObservable,
viewHistory,
() => ({
context: {},
user: {},
Expand All @@ -91,22 +85,18 @@ function startRumStub(
)
const { stop: viewCollectionStop } = startViewCollection(
lifeCycle,
hooks,
configuration,
location,
domMutationObservable,
windowOpenObservable,
locationChangeObservable,
pageStateHistory,
noopRecorderApi,
viewHistory
noopRecorderApi
)

startLongAnimationFrameCollection(lifeCycle, configuration)
return {
stop: () => {
viewHistory.stop()
urlContexts.stop()
rumEventCollectionStop()
viewCollectionStop()
},
Expand Down
30 changes: 15 additions & 15 deletions packages/rum-core/src/boot/startRum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { createWindowOpenObservable } from '../browser/windowOpenObservable'
import { startRumAssembly } from '../domain/assembly'
import { startInternalContext } from '../domain/contexts/internalContext'
import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle'
import type { ViewHistory } from '../domain/contexts/viewHistory'
import { startViewHistory } from '../domain/contexts/viewHistory'
import { startRequestCollection } from '../domain/requestCollection'
import { startActionCollection } from '../domain/action/actionCollection'
Expand All @@ -35,6 +34,7 @@ import { startRumSessionManager, startRumSessionManagerStub } from '../domain/ru
import { startRumBatch } from '../transport/startRumBatch'
import { startRumEventBridge } from '../transport/startRumEventBridge'
import { startUrlContexts } from '../domain/contexts/urlContexts'
import type { LocationChange } from '../browser/locationChangeObservable'
import { createLocationChangeObservable } from '../browser/locationChangeObservable'
import type { RumConfiguration } from '../domain/configuration'
import type { ViewOptions } from '../domain/view/trackViews'
Expand All @@ -51,8 +51,6 @@ import { startCiVisibilityContext } from '../domain/contexts/ciVisibilityContext
import { startLongAnimationFrameCollection } from '../domain/longAnimationFrame/longAnimationFrameCollection'
import { RumPerformanceEntryType } from '../browser/performanceObservable'
import { startLongTaskCollection } from '../domain/longTask/longTaskCollection'
import type { Hooks } from '../hooks'
import { createHooks } from '../hooks'
import type { RecorderApi } from './rumPublicApi'

export type StartRum = typeof startRum
Expand All @@ -74,7 +72,6 @@ export function startRum(
) {
const cleanupTasks: Array<() => void> = []
const lifeCycle = new LifeCycle()
const hooks = createHooks()

lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event) => sendToExtension('rum', event))

Expand Down Expand Up @@ -131,26 +128,25 @@ export function startRum(
const domMutationObservable = createDOMMutationObservable()
const locationChangeObservable = createLocationChangeObservable(configuration, location)
const pageStateHistory = startPageStateHistory(configuration)
const viewHistory = startViewHistory(lifeCycle)
const urlContexts = startUrlContexts(lifeCycle, hooks, locationChangeObservable, location, viewHistory)

const { observable: windowOpenObservable, stop: stopWindowOpen } = createWindowOpenObservable()
cleanupTasks.push(stopWindowOpen)

const {
viewHistory,
urlContexts,
actionContexts,
addAction,
stop: stopRumEventCollection,
} = startRumEventCollection(
lifeCycle,
hooks,
configuration,
location,
session,
pageStateHistory,
locationChangeObservable,
domMutationObservable,
featureFlagContexts,
windowOpenObservable,
viewHistory,
getCommonContext,
reportError
)
Expand All @@ -168,18 +164,15 @@ export function startRum(
stop: stopViewCollection,
} = startViewCollection(
lifeCycle,
hooks,
configuration,
location,
domMutationObservable,
windowOpenObservable,
locationChangeObservable,
pageStateHistory,
recorderApi,
viewHistory,
initialViewOptions
)

cleanupTasks.push(stopViewCollection)

const { stop: stopResourceCollection } = startResourceCollection(lifeCycle, configuration, pageStateHistory)
Expand Down Expand Up @@ -242,17 +235,20 @@ function startRumTelemetry(configuration: RumConfiguration) {

export function startRumEventCollection(
lifeCycle: LifeCycle,
hooks: Hooks,
configuration: RumConfiguration,
location: Location,
sessionManager: RumSessionManager,
pageStateHistory: PageStateHistory,
locationChangeObservable: Observable<LocationChange>,
domMutationObservable: Observable<void>,
featureFlagContexts: FeatureFlagContexts,
windowOpenObservable: Observable<void>,
viewHistory: ViewHistory,
getCommonContext: () => CommonContext,
reportError: (error: RawError) => void
) {
const viewHistory = startViewHistory(lifeCycle)
const urlContexts = startUrlContexts(lifeCycle, locationChangeObservable, location)

const actionCollection = startActionCollection(
lifeCycle,
domMutationObservable,
Expand All @@ -267,9 +263,9 @@ export function startRumEventCollection(
startRumAssembly(
configuration,
lifeCycle,
hooks,
sessionManager,
viewHistory,
urlContexts,
actionCollection.actionContexts,
displayContext,
ciVisibilityContext,
Expand All @@ -279,13 +275,17 @@ export function startRumEventCollection(
)

return {
viewHistory,
pageStateHistory,
urlContexts,
addAction: actionCollection.addAction,
actionContexts: actionCollection.actionContexts,
stop: () => {
actionCollection.stop()
ciVisibilityContext.stop()
displayContext.stop()
urlContexts.stop()
viewHistory.stop()
pageStateHistory.stop()
},
}
Expand Down
Loading

0 comments on commit 5c1218c

Please sign in to comment.