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

⚗️ [RUMF-1181] collect telemetry events #1351

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/core/src/domain/internalMonitoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export {
startInternalMonitoring,
} from './internalMonitoring'
export { TelemetryEvent } from './telemetryEvent.types'
export { startMonitoringBatch } from './startMonitoringBatch'
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export function startInternalMonitoring(configuration: Configuration): InternalM
bridge.send('internal_log', withContext(message))
)
} else if (configuration.internalMonitoringEndpointBuilder) {
const batch = startMonitoringBatch(configuration)
const batch = startMonitoringBatch(
configuration,
configuration.internalMonitoringEndpointBuilder,
configuration.replica?.internalMonitoringEndpointBuilder
)
monitoringMessageObservable.subscribe((message: MonitoringMessage) => batch.add(withContext(message)))
}
if (isExperimentalFeatureEnabled('telemetry')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Batch, HttpRequest } from '../../transport'
import type { Configuration, EndpointBuilder, MonitoringMessage } from '../..'
import type { Configuration, EndpointBuilder, Context } from '../..'

export function startMonitoringBatch(configuration: Configuration) {
const primaryBatch = createMonitoringBatch(configuration.internalMonitoringEndpointBuilder!)
export function startMonitoringBatch<T extends Context>(
Copy link
Member

Choose a reason for hiding this comment

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

💭 thought: ‏This is interesting, because now this function has no "monitoring"-related logic, and could be use in other places (could be factorized with startLoggerBatch or startRumBatch with a bit of changes). The Batch class could be seen as an internal implementation detail, and this new generic function could be used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, startLoggerBatch and startMonitoringBatch were almost the same thing 🤔
I had in mind to only keep this abstraction while having both systems but we could use that for logs as well and keep it.

For RUM, it seems a bit trickier since there are more behaviors related to the batch (upsert, unload, replica app id).

Wdyt of only mutualizing that with logs?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, for RUM it is trickier. I would still factorize it though:

  • while only used by RUM, upsert and unload are implemented in Batch, so it wouldn't hurt to expose it through the more abstract startBatch function.
  • for replica specificities, we could have a replicaContext

It could be done in a future task though

configuration: Configuration,
endpoint: EndpointBuilder,
replicaEndpoint?: EndpointBuilder
) {
const primaryBatch = createMonitoringBatch(endpoint)
let replicaBatch: Batch | undefined
if (configuration.replica !== undefined) {
replicaBatch = createMonitoringBatch(configuration.replica.internalMonitoringEndpointBuilder)
if (replicaEndpoint) {
replicaBatch = createMonitoringBatch(replicaEndpoint)
}

function createMonitoringBatch(endpointBuilder: EndpointBuilder) {
Expand All @@ -19,7 +23,7 @@ export function startMonitoringBatch(configuration: Configuration) {
}

return {
add(message: MonitoringMessage) {
add(message: T) {
primaryBatch.add(message)
if (replicaBatch) {
replicaBatch.add(message)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { computeStackTrace, StackTrace } from './domain/tracekit'
export { defineGlobal, makePublicApi } from './boot/init'
export {
startInternalMonitoring,
startMonitoringBatch,
InternalMonitoring,
MonitoringMessage,
TelemetryEvent,
Expand Down