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-371] add batch time to rum intake requests #285

Merged
merged 2 commits into from
Feb 28, 2020
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
6 changes: 6 additions & 0 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BuildEnv, Datacenter, Environment } from './init'
import { ONE_KILO_BYTE, ONE_SECOND } from './utils'

export const DEFAULT_CONFIGURATION = {
enableExperimentalFeatures: false,
isCollectingError: true,
maxErrorsByMinute: 3000,
maxInternalMonitoringMessagesPerPage: 15,
Expand Down Expand Up @@ -40,6 +41,7 @@ export interface UserConfiguration {
sampleRate?: number
resourceSampleRate?: number
datacenter?: Datacenter
enableExperimentalFeatures?: boolean

// Below is only taken into account for e2e-test bundle.
internalMonitoringEndpoint?: string
Expand Down Expand Up @@ -95,6 +97,10 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
configuration.resourceSampleRate = userConfiguration.resourceSampleRate!
}

if ('enableExperimentalFeatures' in userConfiguration) {
configuration.enableExperimentalFeatures = userConfiguration.enableExperimentalFeatures!
}

if (transportConfiguration.env === 'e2e-test') {
if (userConfiguration.internalMonitoringEndpoint !== undefined) {
configuration.internalMonitoringEndpoint = userConfiguration.internalMonitoringEndpoint
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ import { Context, jsonStringify, objectValues } from './utils'
* to be parsed correctly without content type header
*/
export class HttpRequest {
constructor(private endpointUrl: string, private bytesLimit: number) {}
constructor(private endpointUrl: string, private bytesLimit: number, private withBatchTime: boolean = false) {}

send(data: string, size: number) {
const batchTime = new Date().getTime()
const url = this.withBatchTime ? `${this.endpointUrl}&batch_time=${batchTime}` : this.endpointUrl
if (navigator.sendBeacon && size < this.bytesLimit) {
const isQueued = navigator.sendBeacon(this.endpointUrl, data)
const isQueued = navigator.sendBeacon(url, data)
if (isQueued) {
return
}
}
const request = new XMLHttpRequest()
request.open('POST', this.endpointUrl, true)
request.open('POST', url, true)
request.send(data)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rum/src/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function startRumBatch(
globalContextProvider: () => Context
) {
const batch = new Batch<Context>(
new HttpRequest(configuration.rumEndpoint, configuration.batchBytesLimit),
new HttpRequest(configuration.rumEndpoint, configuration.batchBytesLimit, configuration.enableExperimentalFeatures),
configuration.maxBatchSize,
configuration.batchBytesLimit,
configuration.maxMessageSize,
Expand Down