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-201] add internal logs for buggy load event measures #204

Merged
Merged
Changes from 2 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
22 changes: 21 additions & 1 deletion packages/core/src/transport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashMerge from 'lodash.merge'

import { monitor } from './internalMonitoring'
import { addMonitoringMessage, monitor } from './internalMonitoring'
import { Context, jsonStringify } from './utils'

/**
Expand All @@ -27,6 +27,25 @@ export class HttpRequest {
}
}

const isObject = (o: unknown): o is { [k: string]: unknown } => typeof o === 'object' && o !== null

function reportAdbnormalMeasure(contextualizedMessage: Context) {
BenoitZugmeyer marked this conversation as resolved.
Show resolved Hide resolved
if (
isObject(contextualizedMessage.view) &&
isObject(contextualizedMessage.view.measures) &&
isObject(contextualizedMessage.rum)
) {
const loadEventEnd = contextualizedMessage.view.measures.load_event_end
if (typeof loadEventEnd === 'number' && loadEventEnd > 86400e9 /* 1 day in ns */) {
addMonitoringMessage(
`Buggy load event measure: ${loadEventEnd} - ` +
`View Id: ${contextualizedMessage.view.id} - ` +
`Document Version: ${contextualizedMessage.rum.document_version}`
)
}
}
}

export class Batch<T> {
private beforeFlushOnUnloadHandlers: Array<() => void> = []
private buffer: string = ''
Expand Down Expand Up @@ -82,6 +101,7 @@ export class Batch<T> {

private process(message: T) {
const contextualizedMessage = lodashMerge({}, this.contextProvider(), message) as Context
reportAdbnormalMeasure(contextualizedMessage)
const processedMessage = jsonStringify(contextualizedMessage)!
const messageBytesSize = this.sizeInBytes(processedMessage)
return { processedMessage, messageBytesSize }
Expand Down