Skip to content

Commit

Permalink
πŸ”ŠπŸ› [RUMF-201] add internal logs for buggy load event measures (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer authored Dec 17, 2019
1 parent 1d9c222 commit 2e43277
Showing 1 changed file with 21 additions and 1 deletion.
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 reportAbnormalMeasure(contextualizedMessage: Context) {
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
reportAbnormalMeasure(contextualizedMessage)
const processedMessage = jsonStringify(contextualizedMessage)!
const messageBytesSize = this.sizeInBytes(processedMessage)
return { processedMessage, messageBytesSize }
Expand Down

0 comments on commit 2e43277

Please sign in to comment.