Skip to content

Commit

Permalink
⚗️[RUMF-371] add batch time to rum intake requests (#285)
Browse files Browse the repository at this point in the history
* ⚗️ add batch time to rum intake requests

* 🚩 add an `enableExperimentalFeatures` init options

would allow us to test some features only on datadog app
  • Loading branch information
bcaudan authored Feb 28, 2020
1 parent 4867a87 commit 312ada8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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

0 comments on commit 312ada8

Please sign in to comment.