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-4360] monitor more API usages #2745

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
107 changes: 100 additions & 7 deletions packages/core/src/domain/telemetry/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,70 @@ export type TelemetryCommonFeaturesUsage =
feature: 'stop-session'
[k: string]: unknown
}
| {
/**
* startView API
*/
feature: 'start-view'
[k: string]: unknown
}
| {
/**
* addAction API
*/
feature: 'add-action'
[k: string]: unknown
}
| {
/**
* addError API
*/
feature: 'add-error'
[k: string]: unknown
}
| {
/**
* setGlobalContext, setGlobalContextProperty, addAttribute APIs
*/
feature: 'set-global-context'
[k: string]: unknown
}
| {
/**
* setUser, setUserProperty, setUserInfo APIs
*/
feature: 'set-user'
[k: string]: unknown
}
| {
/**
* addFeatureFlagEvaluation API
*/
feature: 'add-feature-flag-evaluation'
[k: string]: unknown
}
/**
* Schema of browser specific features usage
*/
export type TelemetryBrowserFeaturesUsage = {
/**
* startSessionReplayRecording API
*/
feature: 'start-session-replay-recording'
[k: string]: unknown
}
export type TelemetryBrowserFeaturesUsage =
| {
/**
* startSessionReplayRecording API
*/
feature: 'start-session-replay-recording'
/**
* Whether the recording is allowed to start even on sessions sampled out of replay
*/
is_forced?: boolean
[k: string]: unknown
}
| {
/**
* startDurationVital API
*/
feature: 'start-duration-vital'
[k: string]: unknown
}

/**
* Schema of common properties of Telemetry events
Expand Down Expand Up @@ -487,5 +541,44 @@ export interface CommonTelemetryProperties {
* Enabled experimental features
*/
readonly experimental_features?: string[]
telemetry?: {
/**
* Device properties
*/
device?: {
/**
* Architecture of the device
*/
architecture?: string
/**
* Brand of the device
*/
brand?: string
/**
* Model of the device
*/
model?: string
[k: string]: unknown
}
/**
* OS properties
*/
os?: {
/**
* Build of the OS
*/
build?: string
/**
* Name of the OS
*/
name?: string
/**
* Version of the OS
*/
version?: string
[k: string]: unknown
}
[k: string]: unknown
}
[k: string]: unknown
}
17 changes: 15 additions & 2 deletions packages/rum-core/src/boot/rumPublicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
startClocks: options?.startTime ? timeStampToClocks(options.startTime as TimeStamp) : clocksNow(),
context: sanitize(options?.context) as Context,
})
addTelemetryUsage({ feature: 'start-duration-vital' })
}
)

Expand Down Expand Up @@ -188,6 +189,7 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
} = monitor((options?: string | ViewOptions) => {
const sanitizedOptions = typeof options === 'object' ? options : { name: options }
strategy.startView(sanitizedOptions)
addTelemetryUsage({ feature: 'start-view' })
})
const rumPublicApi = makePublicApi({
init: monitor((initConfiguration: RumInitConfiguration) => strategy.init(initConfiguration)),
Expand All @@ -209,13 +211,19 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
addTelemetryUsage({ feature: 'set-tracking-consent', tracking_consent: trackingConsent })
}),

setGlobalContextProperty: monitor((key, value) => globalContextManager.setContextProperty(key, value)),
setGlobalContextProperty: monitor((key, value) => {
globalContextManager.setContextProperty(key, value)
addTelemetryUsage({ feature: 'set-global-context' })
}),

removeGlobalContextProperty: monitor((key) => globalContextManager.removeContextProperty(key)),

getGlobalContext: monitor(() => globalContextManager.getContext()),

setGlobalContext: monitor((context) => globalContextManager.setContext(context)),
setGlobalContext: monitor((context) => {
globalContextManager.setContext(context)
addTelemetryUsage({ feature: 'set-global-context' })
}),

clearGlobalContext: monitor(() => globalContextManager.clearContext()),

Expand All @@ -230,6 +238,7 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
startClocks: clocksNow(),
type: ActionType.CUSTOM,
})
addTelemetryUsage({ feature: 'add-action' })
}),

addError: (error: unknown, context?: object) => {
Expand All @@ -241,6 +250,7 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
context: sanitize(context) as Context,
startClocks: clocksNow(),
})
addTelemetryUsage({ feature: 'add-error' })
})
},

Expand All @@ -264,13 +274,15 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
if (checkUser(newUser)) {
userContextManager.setContext(sanitizeUser(newUser as Context))
}
addTelemetryUsage({ feature: 'set-user' })
}),

getUser: monitor(() => userContextManager.getContext()),

setUserProperty: monitor((key, property) => {
const sanitizedProperty = sanitizeUser({ [key]: property })[key]
userContextManager.setContextProperty(key, sanitizedProperty)
addTelemetryUsage({ feature: 'set-user' })
}),

removeUserProperty: monitor((key) => userContextManager.removeContextProperty(key)),
Expand All @@ -296,6 +308,7 @@ export function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderAp
*/
addFeatureFlagEvaluation: monitor((key: string, value: any) => {
strategy.addFeatureFlagEvaluation(sanitize(key)!, sanitize(value))
addTelemetryUsage({ feature: 'add-feature-flag-evaluation' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: ‏almost all usages of addTelemetryUsage is only providing a feature name. It could be shorter to change the signature to something like:

addTelemetryUsage("feature", { optional_context: true })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when introducing the API, I spent some time trying something like this but did not managed to have the typings working.
Don't hesitate to have a shot at it, happy to tweak that in a following PR.

}),

getSessionReplayLink: monitor(() => recorderApi.getSessionReplayLink()),
Expand Down