@datadog/mobile-react-native
Version:
A client-side React Native module to interact with Datadog
51 lines (50 loc) • 2.01 kB
JavaScript
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
import { InternalLog } from '../../../InternalLog';
import { SdkVerbosity } from '../../../SdkVerbosity';
import { firstPartyHostsRegexMapBuilder } from './distributedTracing/firstPartyHosts';
import { ResourceReporter } from './requestProxy/XHRProxy/DatadogRumResource/ResourceReporter';
import { filterDevResource } from './requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist';
import { XHRProxy } from './requestProxy/XHRProxy/XHRProxy';
/**
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
*/
export class DdRumResourceTracking {
static isTracking = false;
/**
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
*/
static startTracking({
tracingSamplingRate,
firstPartyHosts
}) {
// extra safety to avoid proxying the XHR class twice
if (DdRumResourceTracking.isTracking) {
InternalLog.log('Datadog SDK is already tracking XHR resources', SdkVerbosity.WARN);
return;
}
this.requestProxy = new XHRProxy({
xhrType: XMLHttpRequest,
resourceReporter: new ResourceReporter([filterDevResource])
});
this.requestProxy.onTrackingStart({
tracingSamplingRate,
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder(firstPartyHosts)
});
InternalLog.log('Datadog SDK is tracking XHR resources', SdkVerbosity.INFO);
DdRumResourceTracking.isTracking = true;
}
static stopTracking() {
if (DdRumResourceTracking.isTracking) {
DdRumResourceTracking.isTracking = false;
if (this.requestProxy) {
this.requestProxy.onTrackingStop();
}
this.requestProxy = null;
}
}
}
//# sourceMappingURL=DdRumResourceTracking.js.map