@datadog/mobile-react-native 1.1.4 → 1.2.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -14
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +8 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +10 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +25 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +52 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +7 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -0
- package/ios/Sources/DdSdk.m +10 -0
- package/ios/Sources/DdSdk.swift +17 -0
- package/ios/Sources/DdSdkConfiguration.swift +4 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +2 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/commonjs/DdSdkReactNative.js +138 -56
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +102 -9
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +60 -0
- package/lib/commonjs/errorUtils.js.map +1 -0
- package/lib/commonjs/foundation.js +19 -12
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/types.js +2 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
- package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +130 -54
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +91 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +45 -0
- package/lib/module/errorUtils.js.map +1 -0
- package/lib/module/foundation.js +18 -12
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/types.js +2 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
- package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
- package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
- package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
- package/lib/typescript/DdSdkReactNative.d.ts +23 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +63 -0
- package/lib/typescript/errorUtils.d.ts +4 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/nativeModulesTypes.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
- package/lib/typescript/types.d.ts +2 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
- package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
- package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
- package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
- package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
- package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
- package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
- package/src/DatadogProvider/DatadogProvider.tsx +122 -0
- package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +174 -0
- package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
- package/src/DdSdkReactNative.tsx +205 -105
- package/src/DdSdkReactNativeConfiguration.tsx +160 -8
- package/src/__tests__/DdRumWrapper.test.tsx +3 -27
- package/src/__tests__/DdSdkReactNative.test.tsx +1 -0
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +168 -0
- package/src/__tests__/foundation.test.ts +11 -2
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
- package/src/errorUtils.ts +50 -0
- package/src/foundation.tsx +15 -12
- package/src/index.tsx +9 -1
- package/src/nativeModulesTypes.ts +14 -0
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
- package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +3 -0
- package/src/types.tsx +2 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bufferNativeCallWithId = exports.bufferNativeCallReturningId = exports.bufferVoidNativeCall = void 0;
|
|
7
|
+
|
|
8
|
+
var _BufferSingleton = require("./BufferSingleton");
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
12
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
13
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
14
|
+
*/
|
|
15
|
+
const bufferVoidNativeCall = callback => {
|
|
16
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallback(callback);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.bufferVoidNativeCall = bufferVoidNativeCall;
|
|
20
|
+
|
|
21
|
+
const bufferNativeCallReturningId = callback => {
|
|
22
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallbackReturningId(callback);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.bufferNativeCallReturningId = bufferNativeCallReturningId;
|
|
26
|
+
|
|
27
|
+
const bufferNativeCallWithId = (callback, id) => {
|
|
28
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallbackWithId(callback, id);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.bufferNativeCallWithId = bufferNativeCallWithId;
|
|
32
|
+
//# sourceMappingURL=bufferNativeCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["bufferNativeCall.ts"],"names":["bufferVoidNativeCall","callback","BufferSingleton","getInstance","addCallback","bufferNativeCallReturningId","addCallbackReturningId","bufferNativeCallWithId","id","addCallbackWithId"],"mappings":";;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AAIO,MAAMA,oBAAoB,GAAIC,QAAD,IAAmC;AACnE,SAAOC,iCAAgBC,WAAhB,GAA8BC,WAA9B,CAA0CH,QAA1C,CAAP;AACH,CAFM;;;;AAIA,MAAMI,2BAA2B,GACpCJ,QADuC,IAEtC;AACD,SAAOC,iCAAgBC,WAAhB,GAA8BG,sBAA9B,CAAqDL,QAArD,CAAP;AACH,CAJM;;;;AAMA,MAAMM,sBAAsB,GAAG,CAClCN,QADkC,EAElCO,EAFkC,KAGjC;AACD,SAAON,iCAAgBC,WAAhB,GAA8BM,iBAA9B,CAAgDR,QAAhD,EAA0DO,EAA1D,CAAP;AACH,CALM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { BufferSingleton } from './BufferSingleton';\n\nexport const bufferVoidNativeCall = (callback: () => Promise<void>) => {\n return BufferSingleton.getInstance().addCallback(callback);\n};\n\nexport const bufferNativeCallReturningId = (\n callback: () => Promise<string>\n) => {\n return BufferSingleton.getInstance().addCallbackReturningId(callback);\n};\n\nexport const bufferNativeCallWithId = (\n callback: (id: string) => Promise<void>,\n id: string\n) => {\n return BufferSingleton.getInstance().addCallbackWithId(callback, id);\n};\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.__internalResetIsInitializedForTesting = exports.DatadogProvider = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _DdSdkReactNativeConfiguration = require("../DdSdkReactNativeConfiguration");
|
|
11
|
+
|
|
12
|
+
var _DdSdkReactNative = require("../DdSdkReactNative");
|
|
13
|
+
|
|
14
|
+
var _InternalLog = require("../InternalLog");
|
|
15
|
+
|
|
16
|
+
var _SdkVerbosity = require("../SdkVerbosity");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
22
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
23
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
24
|
+
*/
|
|
25
|
+
let isInitialized = false;
|
|
26
|
+
|
|
27
|
+
const isConfigurationPartial = configuration => {
|
|
28
|
+
if (configuration instanceof _DdSdkReactNativeConfiguration.DatadogProviderConfiguration) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (configuration instanceof _DdSdkReactNativeConfiguration.DdSdkReactNativeConfiguration) {
|
|
33
|
+
// Not using InternalLog here as it is not yet instanciated
|
|
34
|
+
console.warn('A DdSdkReactNativeConfiguration was passed to DatadogProvider. Please use DatadogProviderConfiguration instead.');
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const initializeDatadog = async (configuration, onInitialization) => {
|
|
42
|
+
await _DdSdkReactNative.DdSdkReactNative._initializeFromDatadogProvider(configuration);
|
|
43
|
+
|
|
44
|
+
if (onInitialization) {
|
|
45
|
+
try {
|
|
46
|
+
onInitialization();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
_InternalLog.InternalLog.log(`Error running onInitialization callback ${error}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Set up the Datadog React Native SDK.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const DatadogProvider = ({
|
|
58
|
+
children,
|
|
59
|
+
configuration,
|
|
60
|
+
onInitialization
|
|
61
|
+
}) => {
|
|
62
|
+
if (!isInitialized) {
|
|
63
|
+
// Here we cannot use a useEffect hook since it would be called after
|
|
64
|
+
// the first render. Thus, we wouldn't enable auto-instrumentation on
|
|
65
|
+
// the elements rendered in this first render and what happens during
|
|
66
|
+
// the first render.
|
|
67
|
+
if (isConfigurationPartial(configuration)) {
|
|
68
|
+
_DdSdkReactNative.DdSdkReactNative._enableFeaturesFromDatadogProvider(configuration);
|
|
69
|
+
|
|
70
|
+
DatadogProvider.onInitialization = onInitialization;
|
|
71
|
+
} else {
|
|
72
|
+
initializeDatadog(configuration, onInitialization);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
isInitialized = true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Initialize the Datadog SDK to start sending RUM events, logs and traces,
|
|
82
|
+
* then execute onInitialization callback if any was provided.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
exports.DatadogProvider = DatadogProvider;
|
|
87
|
+
|
|
88
|
+
DatadogProvider.initialize = async configuration => {
|
|
89
|
+
await _DdSdkReactNative.DdSdkReactNative._initializeFromDatadogProviderWithConfigurationAsync(configuration);
|
|
90
|
+
|
|
91
|
+
if (DatadogProvider.onInitialization) {
|
|
92
|
+
DatadogProvider.onInitialization();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const __internalResetIsInitializedForTesting = () => {
|
|
97
|
+
isInitialized = false;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
exports.__internalResetIsInitializedForTesting = __internalResetIsInitializedForTesting;
|
|
101
|
+
//# sourceMappingURL=DatadogProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DatadogProvider.tsx"],"names":["isInitialized","isConfigurationPartial","configuration","DatadogProviderConfiguration","DdSdkReactNativeConfiguration","console","warn","initializeDatadog","onInitialization","DdSdkReactNative","_initializeFromDatadogProvider","error","InternalLog","log","SdkVerbosity","WARN","DatadogProvider","children","_enableFeaturesFromDatadogProvider","initialize","_initializeFromDatadogProviderWithConfigurationAsync","__internalResetIsInitializedForTesting"],"mappings":";;;;;;;AAKA;;AAGA;;AAQA;;AACA;;AACA;;;;AAlBA;AACA;AACA;AACA;AACA;AAgBA,IAAIA,aAAa,GAAG,KAApB;;AAwBA,MAAMC,sBAAsB,GACxBC,aAD2B,IAIyB;AACpD,MAAIA,aAAa,YAAYC,2DAA7B,EAA2D;AACvD,WAAO,KAAP;AACH;;AACD,MAAID,aAAa,YAAYE,4DAA7B,EAA4D;AACxD;AACAC,IAAAA,OAAO,CAACC,IAAR,CACI,iHADJ;AAGA,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,CAhBD;;AAkBA,MAAMC,iBAAiB,GAAG,OACtBL,aADsB,EAEtBM,gBAFsB,KAGrB;AACD,QAAMC,mCAAiBC,8BAAjB,CAAgDR,aAAhD,CAAN;;AACA,MAAIM,gBAAJ,EAAsB;AAClB,QAAI;AACAA,MAAAA,gBAAgB;AACnB,KAFD,CAEE,OAAOG,KAAP,EAAc;AACZC,+BAAYC,GAAZ,CACK,2CAA0CF,KAAM,EADrD,EAEIG,2BAAaC,IAFjB;AAIH;AACJ;AACJ,CAfD;AAiBA;AACA;AACA;;;AACO,MAAMC,eAAmD,GAAG,CAAC;AAChEC,EAAAA,QADgE;AAEhEf,EAAAA,aAFgE;AAGhEM,EAAAA;AAHgE,CAAD,KAI7D;AACF,MAAI,CAACR,aAAL,EAAoB;AAChB;AACA;AACA;AACA;AACA,QAAIC,sBAAsB,CAACC,aAAD,CAA1B,EAA2C;AACvCO,yCAAiBS,kCAAjB,CAAoDhB,aAApD;;AACAc,MAAAA,eAAe,CAACR,gBAAhB,GAAmCA,gBAAnC;AACH,KAHD,MAGO;AACHD,MAAAA,iBAAiB,CAACL,aAAD,EAAgBM,gBAAhB,CAAjB;AACH;;AACDR,IAAAA,aAAa,GAAG,IAAhB;AACH;;AAED,sBAAO,4DAAGiB,QAAH,CAAP;AACH,CApBM;AAsBP;AACA;AACA;AACA;;;;;AACAD,eAAe,CAACG,UAAhB,GAA6B,MACzBjB,aADyB,IAExB;AACD,QAAMO,mCAAiBW,oDAAjB,CACFlB,aADE,CAAN;;AAGA,MAAIc,eAAe,CAACR,gBAApB,EAAsC;AAClCQ,IAAAA,eAAe,CAACR,gBAAhB;AACH;AACJ,CATD;;AAWO,MAAMa,sCAAsC,GAAG,MAAM;AACxDrB,EAAAA,aAAa,GAAG,KAAhB;AACH,CAFM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\nimport React from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport {\n DatadogProviderConfiguration,\n DdSdkReactNativeConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport type {\n PartialInitializationConfiguration,\n AutoInstrumentationConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport { DdSdkReactNative } from '../DdSdkReactNative';\nimport { InternalLog } from '../InternalLog';\nimport { SdkVerbosity } from '../SdkVerbosity';\n\nlet isInitialized = false;\n\ntype Props = PropsWithChildren<{\n /**\n * If a `DatadogProviderConfiguration` instance is passed, the SDK will start tracking errors, resources and actions and sending events.\n *\n * If a `AutoInstrumentationConfiguration` object is passed, the SDK will start tracking errors, resources and actions. To start sending events, call `DatadogProvider.initialize`.\n */\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration;\n /**\n * Callback to be run once the SDK starts sending events.\n */\n onInitialization?: () => void;\n}>;\n\ntype StaticProperties = {\n initialize: (\n configuration: PartialInitializationConfiguration\n ) => Promise<void>;\n onInitialization?: () => void;\n};\n\nconst isConfigurationPartial = (\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration\n): configuration is AutoInstrumentationConfiguration => {\n if (configuration instanceof DatadogProviderConfiguration) {\n return false;\n }\n if (configuration instanceof DdSdkReactNativeConfiguration) {\n // Not using InternalLog here as it is not yet instanciated\n console.warn(\n 'A DdSdkReactNativeConfiguration was passed to DatadogProvider. Please use DatadogProviderConfiguration instead.'\n );\n return false;\n }\n return true;\n};\n\nconst initializeDatadog = async (\n configuration: DatadogProviderConfiguration,\n onInitialization?: () => void\n) => {\n await DdSdkReactNative._initializeFromDatadogProvider(configuration);\n if (onInitialization) {\n try {\n onInitialization();\n } catch (error) {\n InternalLog.log(\n `Error running onInitialization callback ${error}`,\n SdkVerbosity.WARN\n );\n }\n }\n};\n\n/**\n * Set up the Datadog React Native SDK.\n */\nexport const DatadogProvider: React.FC<Props> & StaticProperties = ({\n children,\n configuration,\n onInitialization\n}) => {\n if (!isInitialized) {\n // Here we cannot use a useEffect hook since it would be called after\n // the first render. Thus, we wouldn't enable auto-instrumentation on\n // the elements rendered in this first render and what happens during\n // the first render.\n if (isConfigurationPartial(configuration)) {\n DdSdkReactNative._enableFeaturesFromDatadogProvider(configuration);\n DatadogProvider.onInitialization = onInitialization;\n } else {\n initializeDatadog(configuration, onInitialization);\n }\n isInitialized = true;\n }\n\n return <>{children}</>;\n};\n\n/**\n * Initialize the Datadog SDK to start sending RUM events, logs and traces,\n * then execute onInitialization callback if any was provided.\n */\nDatadogProvider.initialize = async (\n configuration: PartialInitializationConfiguration\n) => {\n await DdSdkReactNative._initializeFromDatadogProviderWithConfigurationAsync(\n configuration\n );\n if (DatadogProvider.onInitialization) {\n DatadogProvider.onInitialization();\n }\n};\n\nexport const __internalResetIsInitializedForTesting = () => {\n isInitialized = false;\n};\n"]}
|
|
@@ -5,6 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DdSdkReactNative = void 0;
|
|
7
7
|
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _BufferSingleton = require("./DatadogProvider/Buffer/BufferSingleton");
|
|
11
|
+
|
|
12
|
+
var _DdSdkReactNativeConfiguration = require("./DdSdkReactNativeConfiguration");
|
|
13
|
+
|
|
8
14
|
var _InternalLog = require("./InternalLog");
|
|
9
15
|
|
|
10
16
|
var _ProxyConfiguration = require("./ProxyConfiguration");
|
|
@@ -36,77 +42,53 @@ class DdSdkReactNative {
|
|
|
36
42
|
* @param configuration the configuration for the SDK library
|
|
37
43
|
* @returns a Promise.
|
|
38
44
|
*/
|
|
39
|
-
static initialize(configuration) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
resolve();
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_InternalLog.InternalLog.verbosity = configuration.verbosity;
|
|
49
|
-
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
|
|
50
|
-
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = _version.version;
|
|
51
|
-
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
|
|
45
|
+
static async initialize(configuration) {
|
|
46
|
+
await DdSdkReactNative.initializeNativeSDK(configuration);
|
|
47
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
48
|
+
}
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
/**
|
|
51
|
+
* FOR INTERNAL USE ONLY.
|
|
52
|
+
*/
|
|
53
|
+
static async _initializeFromDatadogProvider(configuration) {
|
|
54
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
55
|
+
DdSdkReactNative.configuration = configuration;
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
|
|
61
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
|
|
62
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
|
|
63
|
-
|
|
64
|
-
if (proxyConfig.username && proxyConfig.password) {
|
|
65
|
-
if (proxyConfig.type === _ProxyConfiguration.ProxyType.SOCKS) {
|
|
66
|
-
console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
|
|
67
|
-
} else {
|
|
68
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
|
|
69
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
57
|
+
if (configuration.initializationMode === _DdSdkReactNativeConfiguration.InitializationMode.SYNC) {
|
|
58
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
59
|
+
}
|
|
73
60
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
if (configuration.initializationMode === _DdSdkReactNativeConfiguration.InitializationMode.ASYNC) {
|
|
62
|
+
return _reactNative.InteractionManager.runAfterInteractions(() => {
|
|
63
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
64
|
+
});
|
|
65
|
+
} // TODO: Remove when DdSdkReactNativeConfiguration is deprecated
|
|
77
66
|
|
|
78
|
-
if (configuration.version) {
|
|
79
|
-
configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${configuration.version}${configuration.versionSuffix ? `-${configuration.versionSuffix}` : ''}`;
|
|
80
|
-
} // If both version and version suffix are provided, we merge them into the version field.
|
|
81
|
-
// To avoid adding it in again the native part, we only set it if the version isn't set.
|
|
82
67
|
|
|
68
|
+
if (configuration instanceof _DdSdkReactNativeConfiguration.DdSdkReactNativeConfiguration) {
|
|
69
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* FOR INTERNAL USE ONLY.
|
|
74
|
+
*/
|
|
83
75
|
|
|
84
|
-
if (configuration.versionSuffix && !configuration.version) {
|
|
85
|
-
configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
|
|
86
|
-
}
|
|
87
76
|
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
static async _enableFeaturesFromDatadogProvider(features) {
|
|
78
|
+
DdSdkReactNative.features = features;
|
|
79
|
+
DdSdkReactNative.enableFeatures((0, _DdSdkReactNativeConfiguration.addDefaultValuesToAutoInstrumentationConfiguration)(features));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* FOR INTERNAL USE ONLY.
|
|
83
|
+
*/
|
|
90
84
|
|
|
91
|
-
_foundation.DdSdk.initialize(new _types.DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
|
|
92
|
-
_InternalLog.InternalLog.log('Datadog SDK was initialized', _SdkVerbosity.SdkVerbosity.INFO);
|
|
93
85
|
|
|
94
|
-
DdSdkReactNative.enableFeatures(configuration);
|
|
95
|
-
DdSdkReactNative.wasInitialized = true;
|
|
96
|
-
resolve();
|
|
97
|
-
}, rejection => {
|
|
98
|
-
reject(rejection);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
86
|
/**
|
|
103
87
|
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
104
88
|
* @param attributes: The global context attributes.
|
|
105
89
|
* @returns a Promise.
|
|
106
90
|
*/
|
|
107
91
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
108
|
-
|
|
109
|
-
|
|
110
92
|
static setAttributes(attributes) {
|
|
111
93
|
_InternalLog.InternalLog.log(`Setting attributes ${JSON.stringify(attributes)}`, _SdkVerbosity.SdkVerbosity.DEBUG);
|
|
112
94
|
|
|
@@ -139,6 +121,12 @@ class DdSdkReactNative {
|
|
|
139
121
|
}
|
|
140
122
|
|
|
141
123
|
static enableFeatures(configuration) {
|
|
124
|
+
if (DdSdkReactNative.wasAutoInstrumented) {
|
|
125
|
+
_InternalLog.InternalLog.log("Can't auto instrument Datadog, SDK was already instrumented", _SdkVerbosity.SdkVerbosity.WARN);
|
|
126
|
+
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
142
130
|
if (configuration.trackInteractions) {
|
|
143
131
|
_DdRumUserInteractionTracking.DdRumUserInteractionTracking.startTracking();
|
|
144
132
|
}
|
|
@@ -153,6 +141,8 @@ class DdSdkReactNative {
|
|
|
153
141
|
if (configuration.trackErrors) {
|
|
154
142
|
_DdRumErrorTracking.DdRumErrorTracking.startTracking();
|
|
155
143
|
}
|
|
144
|
+
|
|
145
|
+
DdSdkReactNative.wasAutoInstrumented = true;
|
|
156
146
|
}
|
|
157
147
|
|
|
158
148
|
}
|
|
@@ -188,4 +178,96 @@ _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", '_dd.long
|
|
|
188
178
|
_defineProperty(DdSdkReactNative, "NATIVE_LONG_TASK_THRESHOLD_MS", 200);
|
|
189
179
|
|
|
190
180
|
_defineProperty(DdSdkReactNative, "wasInitialized", false);
|
|
181
|
+
|
|
182
|
+
_defineProperty(DdSdkReactNative, "wasAutoInstrumented", false);
|
|
183
|
+
|
|
184
|
+
_defineProperty(DdSdkReactNative, "configuration", void 0);
|
|
185
|
+
|
|
186
|
+
_defineProperty(DdSdkReactNative, "features", void 0);
|
|
187
|
+
|
|
188
|
+
_defineProperty(DdSdkReactNative, "initializeNativeSDK", async configuration => {
|
|
189
|
+
if (DdSdkReactNative.wasInitialized) {
|
|
190
|
+
_InternalLog.InternalLog.log("Can't initialize Datadog, SDK was already initialized", _SdkVerbosity.SdkVerbosity.WARN);
|
|
191
|
+
|
|
192
|
+
if (!__DEV__) {
|
|
193
|
+
_foundation.DdSdk.telemetryDebug('RN SDK was already initialized in javascript');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return new Promise(resolve => resolve());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_InternalLog.InternalLog.verbosity = configuration.verbosity;
|
|
200
|
+
DdSdkReactNative.buildConfiguration(configuration);
|
|
201
|
+
await _foundation.DdSdk.initialize(new _types.DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig, configuration.telemetrySampleRate));
|
|
202
|
+
|
|
203
|
+
_InternalLog.InternalLog.log('Datadog SDK was initialized', _SdkVerbosity.SdkVerbosity.INFO);
|
|
204
|
+
|
|
205
|
+
DdSdkReactNative.wasInitialized = true;
|
|
206
|
+
|
|
207
|
+
_BufferSingleton.BufferSingleton.onInitialization();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
_defineProperty(DdSdkReactNative, "_initializeFromDatadogProviderAsync", async () => {
|
|
211
|
+
if (!DdSdkReactNative.configuration) {
|
|
212
|
+
_InternalLog.InternalLog.log("Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function", _SdkVerbosity.SdkVerbosity.WARN);
|
|
213
|
+
|
|
214
|
+
return new Promise(resolve => resolve());
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return DdSdkReactNative.initializeNativeSDK(DdSdkReactNative.configuration);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
_defineProperty(DdSdkReactNative, "_initializeFromDatadogProviderWithConfigurationAsync", async configuration => {
|
|
221
|
+
if (!DdSdkReactNative.features) {
|
|
222
|
+
_InternalLog.InternalLog.log("Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function", _SdkVerbosity.SdkVerbosity.WARN);
|
|
223
|
+
|
|
224
|
+
return new Promise(resolve => resolve());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return DdSdkReactNative.initializeNativeSDK((0, _DdSdkReactNativeConfiguration.buildConfigurationFromPartialConfiguration)(DdSdkReactNative.features, configuration));
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
_defineProperty(DdSdkReactNative, "buildConfiguration", configuration => {
|
|
231
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
|
|
232
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = _version.version;
|
|
233
|
+
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
|
|
234
|
+
|
|
235
|
+
if (configuration.verbosity) {
|
|
236
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (configuration.proxyConfig) {
|
|
240
|
+
const additionalConfig = configuration.additionalConfig;
|
|
241
|
+
const proxyConfig = configuration.proxyConfig;
|
|
242
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
|
|
243
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
|
|
244
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
|
|
245
|
+
|
|
246
|
+
if (proxyConfig.username && proxyConfig.password) {
|
|
247
|
+
if (proxyConfig.type === _ProxyConfiguration.ProxyType.SOCKS) {
|
|
248
|
+
console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
|
|
249
|
+
} else {
|
|
250
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
|
|
251
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (configuration.serviceName) {
|
|
257
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (configuration.version) {
|
|
261
|
+
configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${configuration.version}${configuration.versionSuffix ? `-${configuration.versionSuffix}` : ''}`;
|
|
262
|
+
} // If both version and version suffix are provided, we merge them into the version field.
|
|
263
|
+
// To avoid adding it in again the native part, we only set it if the version isn't set.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
if (configuration.versionSuffix && !configuration.version) {
|
|
267
|
+
configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
271
|
+
configuration.additionalConfig['_dd.first_party_hosts'] = configuration.firstPartyHosts;
|
|
272
|
+
});
|
|
191
273
|
//# sourceMappingURL=DdSdkReactNative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","InternalLog","log","SdkVerbosity","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","version","DD_VERSION","versionSuffix","DD_VERSION_SUFFIX","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS","firstPartyHosts","DdSdk","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","tracingSamplingRate","resourceTracingSamplingRate","trackErrors","DdRumErrorTracking"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,gBAAN,CAAuB;AAU1B;;AAaA;AACJ;AACA;AACA;AACA;AACqB,SAAVC,UAAU,CACbC,aADa,EAEA;AACb,WAAO,IAAIC,OAAJ,CAAkB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC1C,UAAIL,gBAAgB,CAACM,cAArB,EAAqC;AACjCC,iCAAYC,GAAZ,CACI,uDADJ,EAEIC,2BAAaC,IAFjB;;AAIAN,QAAAA,OAAO;AACP;AACH;;AAEDG,+BAAYI,SAAZ,GAAwBT,aAAa,CAACS,SAAtC;AAEAT,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACa,aAAhD,IACI,cADJ;AAEAX,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACc,cADrB,IAEIC,gBAFJ;AAGAb,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACgB,2BADrB,IAEId,aAAa,CAACe,kBAFlB;;AAGA,UAAIf,aAAa,CAACS,SAAlB,EAA6B;AACzBT,QAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACkB,oBADrB,IAEIhB,aAAa,CAACS,SAFlB;AAGH;;AAED,UAAIT,aAAa,CAACiB,WAAlB,EAA+B;AAC3B,cAAMP,gBAAgB,GAAGV,aAAa,CAACU,gBAAvC;AACA,cAAMO,WAAW,GAAGjB,aAAa,CAACiB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,EADzC,EAEIvD,2BAAaqD,KAFjB;;AAIA,WAAOnB,kBAAMoB,OAAN,CAAcC,IAAd,CAAP;AACH;AAED;AACJ;AACA;AACA;AACA;;;AAC6B,SAAlBC,kBAAkB,CAACC,OAAD,EAA0C;AAC/D3D,6BAAYC,GAAZ,CAAiB,mBAAkB0D,OAAQ,EAA3C,EAA8CzD,2BAAaqD,KAA3D;;AACA,WAAOnB,kBAAMsB,kBAAN,CAAyBC,OAAzB,CAAP;AACH;;AAE4B,SAAdV,cAAc,CACzBtD,aADyB,EAE3B;AACE,QAAIA,aAAa,CAACiE,iBAAlB,EAAqC;AACjCC,iEAA6BC,aAA7B;AACH;;AAED,QAAInE,aAAa,CAACoE,cAAlB,EAAkC;AAC9BC,mDAAsBF,aAAtB,CAAoC;AAChCG,QAAAA,mBAAmB,EAAEtE,aAAa,CAACuE,2BADH;AAEhC/B,QAAAA,eAAe,EAAExC,aAAa,CAACwC;AAFC,OAApC;AAIH;;AAED,QAAIxC,aAAa,CAACwE,WAAlB,EAA+B;AAC3BC,6CAAmBN,aAAnB;AACH;AACJ;;AAvMyB;;;;gBAAjBrE,gB,mBAC+B,Y;;gBAD/BA,gB,oBAEgC,iB;;gBAFhCA,gB,qBAGiC,kB;;gBAHjCA,gB,0BAIsC,mB;;gBAJtCA,gB,iCAML,0B;;gBANKA,gB,gBAO4B,a;;gBAP5BA,gB,uBAQmC,oB;;gBARnCA,gB,uBAWmC,gB;;gBAXnCA,gB,0BAYsC,mB;;gBAZtCA,gB,uBAamC,gB;;gBAbnCA,gB,2BAcuC,oB;;gBAdvCA,gB,2BAeuC,oB;;gBAfvCA,gB,uCAkBL,yB;;gBAlBKA,gB,mCAmB+C,G;;gBAnB/CA,gB,oBAqBuB,K","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';\nimport { InternalLog } from './InternalLog';\nimport { ProxyType } from './ProxyConfiguration';\nimport { SdkVerbosity } from './SdkVerbosity';\nimport type { TrackingConsent } from './TrackingConsent';\nimport { DdSdk } from './foundation';\nimport { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';\nimport { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';\nimport { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';\nimport { DdSdkConfiguration } from './types';\nimport { version as sdkVersion } from './version';\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n private static readonly DD_SOURCE_KEY = '_dd.source';\n private static readonly DD_SDK_VERSION = '_dd.sdk_version';\n private static readonly DD_SERVICE_NAME = '_dd.service_name';\n private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY =\n '_dd.native_view_tracking';\n private static readonly DD_VERSION = '_dd.version';\n private static readonly DD_VERSION_SUFFIX = '_dd.version_suffix';\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';\n private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';\n private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';\n private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';\n private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =\n '_dd.long_task.threshold';\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;\n\n private static wasInitialized = false;\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\n \"Can't initialize Datadog, SDK was already initialized\",\n SdkVerbosity.WARN\n );\n resolve();\n return;\n }\n\n InternalLog.verbosity = configuration.verbosity;\n\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =\n 'react-native';\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERSION\n ] = sdkVersion;\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY\n ] = configuration.nativeViewTracking;\n if (configuration.verbosity) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERBOSITY_KEY\n ] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =\n proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =\n proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =\n proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type === ProxyType.SOCKS) {\n console.warn(\n \"SOCKS proxy configuration doesn't support Basic authentication.\"\n );\n } else {\n additionalConfig[\n DdSdkReactNative.DD_PROXY_USERNAME_KEY\n ] = proxyConfig.username;\n additionalConfig[\n DdSdkReactNative.DD_PROXY_PASSWORD_KEY\n ] = proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SERVICE_NAME\n ] = configuration.serviceName;\n }\n\n if (configuration.version) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_VERSION\n ] = `${configuration.version}${\n configuration.versionSuffix\n ? `-${configuration.versionSuffix}`\n : ''\n }`;\n }\n\n // If both version and version suffix are provided, we merge them into the version field.\n // To avoid adding it in again the native part, we only set it if the version isn't set.\n if (configuration.versionSuffix && !configuration.version) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_VERSION_SUFFIX\n ] = `-${configuration.versionSuffix}`;\n }\n\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY\n ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;\n\n configuration.additionalConfig['_dd.first_party_hosts'] =\n configuration.firstPartyHosts;\n\n DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate === undefined\n ? configuration.sessionSamplingRate\n : configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig\n )\n ).then(\n () => {\n InternalLog.log(\n 'Datadog SDK was initialized',\n SdkVerbosity.INFO\n );\n DdSdkReactNative.enableFeatures(configuration);\n DdSdkReactNative.wasInitialized = true;\n resolve();\n },\n rejection => {\n reject(rejection);\n }\n );\n });\n }\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\n `Setting attributes ${JSON.stringify(attributes)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setAttributes(attributes);\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\n `Setting user ${JSON.stringify(user)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setUser(user);\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent);\n }\n\n private static enableFeatures(\n configuration: DdSdkReactNativeConfiguration\n ) {\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking({\n tracingSamplingRate: configuration.resourceTracingSamplingRate,\n firstPartyHosts: configuration.firstPartyHosts\n });\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","initializeNativeSDK","enableFeatures","_initializeFromDatadogProvider","initializationMode","InitializationMode","SYNC","ASYNC","InteractionManager","runAfterInteractions","DdSdkReactNativeConfiguration","_enableFeaturesFromDatadogProvider","features","setAttributes","attributes","InternalLog","log","JSON","stringify","SdkVerbosity","DEBUG","DdSdk","setUser","user","setTrackingConsent","consent","wasAutoInstrumented","WARN","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","tracingSamplingRate","resourceTracingSamplingRate","firstPartyHosts","trackErrors","DdRumErrorTracking","wasInitialized","__DEV__","telemetryDebug","Promise","resolve","verbosity","buildConfiguration","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","additionalConfig","telemetrySampleRate","INFO","BufferSingleton","onInitialization","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","version","DD_VERSION","versionSuffix","DD_VERSION_SUFFIX","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;AAYA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA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EIzF,gBAAgB,CAAC0F,6BAFrB;AAIAxF,EAAAA,aAAa,CAACuD,gBAAd,CAA+B,uBAA/B,IACIvD,aAAa,CAACmC,eADlB;AAEH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InteractionManager } from 'react-native';\n\nimport { BufferSingleton } from './DatadogProvider/Buffer/BufferSingleton';\nimport {\n DdSdkReactNativeConfiguration,\n buildConfigurationFromPartialConfiguration,\n addDefaultValuesToAutoInstrumentationConfiguration,\n InitializationMode\n} from './DdSdkReactNativeConfiguration';\nimport type {\n AutoInstrumentationParameters,\n DatadogProviderConfiguration,\n PartialInitializationConfiguration,\n AutoInstrumentationConfiguration\n} from './DdSdkReactNativeConfiguration';\nimport { InternalLog } from './InternalLog';\nimport { ProxyType } from './ProxyConfiguration';\nimport { SdkVerbosity } from './SdkVerbosity';\nimport type { TrackingConsent } from './TrackingConsent';\nimport { DdSdk } from './foundation';\nimport { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';\nimport { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';\nimport { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';\nimport { DdSdkConfiguration } from './types';\nimport { version as sdkVersion } from './version';\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n private static readonly DD_SOURCE_KEY = '_dd.source';\n private static readonly DD_SDK_VERSION = '_dd.sdk_version';\n private static readonly DD_SERVICE_NAME = '_dd.service_name';\n private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY =\n '_dd.native_view_tracking';\n private static readonly DD_VERSION = '_dd.version';\n private static readonly DD_VERSION_SUFFIX = '_dd.version_suffix';\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';\n private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';\n private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';\n private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';\n private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =\n '_dd.long_task.threshold';\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;\n\n private static wasInitialized = false;\n private static wasAutoInstrumented = false;\n private static configuration?: DdSdkReactNativeConfiguration;\n private static features?: AutoInstrumentationConfiguration;\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static async initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n await DdSdkReactNative.initializeNativeSDK(configuration);\n DdSdkReactNative.enableFeatures(configuration);\n }\n\n private static initializeNativeSDK = async (\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\n \"Can't initialize Datadog, SDK was already initialized\",\n SdkVerbosity.WARN\n );\n if (!__DEV__) {\n DdSdk.telemetryDebug(\n 'RN SDK was already initialized in javascript'\n );\n }\n return new Promise(resolve => resolve());\n }\n\n InternalLog.verbosity = configuration.verbosity;\n\n DdSdkReactNative.buildConfiguration(configuration);\n\n await DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate === undefined\n ? configuration.sessionSamplingRate\n : configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig,\n configuration.telemetrySampleRate\n )\n );\n InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);\n DdSdkReactNative.wasInitialized = true;\n BufferSingleton.onInitialization();\n };\n\n /**\n * FOR INTERNAL USE ONLY.\n */\n static async _initializeFromDatadogProvider(\n configuration: DatadogProviderConfiguration\n ): Promise<void> {\n DdSdkReactNative.enableFeatures(configuration);\n DdSdkReactNative.configuration = configuration;\n if (configuration.initializationMode === InitializationMode.SYNC) {\n return DdSdkReactNative.initializeNativeSDK(configuration);\n }\n if (configuration.initializationMode === InitializationMode.ASYNC) {\n return InteractionManager.runAfterInteractions(() => {\n return DdSdkReactNative.initializeNativeSDK(configuration);\n });\n }\n // TODO: Remove when DdSdkReactNativeConfiguration is deprecated\n if (configuration instanceof DdSdkReactNativeConfiguration) {\n return DdSdkReactNative.initializeNativeSDK(configuration);\n }\n }\n\n /**\n * FOR INTERNAL USE ONLY.\n */\n static async _enableFeaturesFromDatadogProvider(\n features: AutoInstrumentationConfiguration\n ): Promise<void> {\n DdSdkReactNative.features = features;\n DdSdkReactNative.enableFeatures(\n addDefaultValuesToAutoInstrumentationConfiguration(features)\n );\n }\n\n /**\n * FOR INTERNAL USE ONLY.\n */\n static _initializeFromDatadogProviderAsync = async (): Promise<void> => {\n if (!DdSdkReactNative.configuration) {\n InternalLog.log(\n \"Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function\",\n SdkVerbosity.WARN\n );\n return new Promise(resolve => resolve());\n }\n return DdSdkReactNative.initializeNativeSDK(\n DdSdkReactNative.configuration\n );\n };\n\n /**\n * FOR INTERNAL USE ONLY.\n */\n static _initializeFromDatadogProviderWithConfigurationAsync = async (\n configuration: PartialInitializationConfiguration\n ): Promise<void> => {\n if (!DdSdkReactNative.features) {\n InternalLog.log(\n \"Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function\",\n SdkVerbosity.WARN\n );\n return new Promise(resolve => resolve());\n }\n\n return DdSdkReactNative.initializeNativeSDK(\n buildConfigurationFromPartialConfiguration(\n DdSdkReactNative.features,\n configuration\n )\n );\n };\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\n `Setting attributes ${JSON.stringify(attributes)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setAttributes(attributes);\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\n `Setting user ${JSON.stringify(user)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setUser(user);\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent);\n }\n\n private static buildConfiguration = (\n configuration: DdSdkReactNativeConfiguration\n ) => {\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =\n 'react-native';\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERSION\n ] = sdkVersion;\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY\n ] = configuration.nativeViewTracking;\n if (configuration.verbosity) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERBOSITY_KEY\n ] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =\n proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =\n proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =\n proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type === ProxyType.SOCKS) {\n console.warn(\n \"SOCKS proxy configuration doesn't support Basic authentication.\"\n );\n } else {\n additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] =\n proxyConfig.username;\n additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] =\n proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] =\n configuration.serviceName;\n }\n\n if (configuration.version) {\n configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${\n configuration.version\n }${\n configuration.versionSuffix\n ? `-${configuration.versionSuffix}`\n : ''\n }`;\n }\n\n // If both version and version suffix are provided, we merge them into the version field.\n // To avoid adding it in again the native part, we only set it if the version isn't set.\n if (configuration.versionSuffix && !configuration.version) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_VERSION_SUFFIX\n ] = `-${configuration.versionSuffix}`;\n }\n\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY\n ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;\n\n configuration.additionalConfig['_dd.first_party_hosts'] =\n configuration.firstPartyHosts;\n };\n\n private static enableFeatures(\n configuration: AutoInstrumentationParameters\n ) {\n if (DdSdkReactNative.wasAutoInstrumented) {\n InternalLog.log(\n \"Can't auto instrument Datadog, SDK was already instrumented\",\n SdkVerbosity.WARN\n );\n return;\n }\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking({\n tracingSamplingRate: configuration.resourceTracingSamplingRate,\n firstPartyHosts: configuration.firstPartyHosts\n });\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n DdSdkReactNative.wasAutoInstrumented = true;\n }\n}\n"]}
|
|
@@ -3,16 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DdSdkReactNativeConfiguration = void 0;
|
|
6
|
+
exports.InitializationMode = exports.DatadogProviderConfiguration = exports.buildConfigurationFromPartialConfiguration = exports.addDefaultValuesToAutoInstrumentationConfiguration = exports.DdSdkReactNativeConfiguration = void 0;
|
|
7
7
|
|
|
8
8
|
var _TrackingConsent = require("./TrackingConsent");
|
|
9
9
|
|
|
10
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
11
|
|
|
12
|
+
const DEFAULTS = {
|
|
13
|
+
nativeCrashReportEnabled: false,
|
|
14
|
+
sessionSamplingRate: 100.0,
|
|
15
|
+
resourceTracingSamplingRate: 20.0,
|
|
16
|
+
site: 'US1',
|
|
17
|
+
nativeViewTracking: false,
|
|
18
|
+
getFirstPartyHosts: () => [],
|
|
19
|
+
getAdditionalConfig: () => ({}),
|
|
20
|
+
trackingConsent: _TrackingConsent.TrackingConsent.GRANTED,
|
|
21
|
+
telemetrySampleRate: 20.0
|
|
22
|
+
};
|
|
12
23
|
/**
|
|
13
24
|
* The SDK configuration class.
|
|
14
25
|
* It will be used to configure the SDK functionality at initialization.
|
|
15
26
|
*/
|
|
27
|
+
|
|
16
28
|
class DdSdkReactNativeConfiguration {
|
|
17
29
|
/**
|
|
18
30
|
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
@@ -45,7 +57,17 @@ class DdSdkReactNativeConfiguration {
|
|
|
45
57
|
*
|
|
46
58
|
* A dash (`-`) will be automatically added between the version and the suffix
|
|
47
59
|
*/
|
|
48
|
-
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The sampling rate for Internal Telemetry (info related to the work of the
|
|
63
|
+
* SDK internals).
|
|
64
|
+
*
|
|
65
|
+
* The sampling rate must be a value between 0 and 100. A value of 0 means no
|
|
66
|
+
* telemetry will be sent, 100 means all telemetry will be sent. When
|
|
67
|
+
* `telemetrySampleRate` is not set, the default value from the iOS and
|
|
68
|
+
* Android SDK is used, which is 20.
|
|
69
|
+
*/
|
|
70
|
+
constructor(clientToken, env, applicationId, trackInteractions = false, trackResources = false, trackErrors = false, trackingConsent = DEFAULTS.trackingConsent) {
|
|
49
71
|
this.clientToken = clientToken;
|
|
50
72
|
this.env = env;
|
|
51
73
|
this.applicationId = applicationId;
|
|
@@ -54,34 +76,105 @@ class DdSdkReactNativeConfiguration {
|
|
|
54
76
|
this.trackErrors = trackErrors;
|
|
55
77
|
this.trackingConsent = trackingConsent;
|
|
56
78
|
|
|
57
|
-
_defineProperty(this, "nativeCrashReportEnabled",
|
|
79
|
+
_defineProperty(this, "nativeCrashReportEnabled", DEFAULTS.nativeCrashReportEnabled);
|
|
58
80
|
|
|
59
81
|
_defineProperty(this, "sampleRate", void 0);
|
|
60
82
|
|
|
61
|
-
_defineProperty(this, "sessionSamplingRate",
|
|
83
|
+
_defineProperty(this, "sessionSamplingRate", DEFAULTS.sessionSamplingRate);
|
|
62
84
|
|
|
63
|
-
_defineProperty(this, "resourceTracingSamplingRate",
|
|
85
|
+
_defineProperty(this, "resourceTracingSamplingRate", DEFAULTS.resourceTracingSamplingRate);
|
|
64
86
|
|
|
65
|
-
_defineProperty(this, "site",
|
|
87
|
+
_defineProperty(this, "site", DEFAULTS.site);
|
|
66
88
|
|
|
67
89
|
_defineProperty(this, "verbosity", undefined);
|
|
68
90
|
|
|
69
|
-
_defineProperty(this, "nativeViewTracking",
|
|
91
|
+
_defineProperty(this, "nativeViewTracking", DEFAULTS.nativeViewTracking);
|
|
70
92
|
|
|
71
93
|
_defineProperty(this, "proxyConfig", undefined);
|
|
72
94
|
|
|
73
95
|
_defineProperty(this, "serviceName", undefined);
|
|
74
96
|
|
|
75
|
-
_defineProperty(this, "firstPartyHosts",
|
|
97
|
+
_defineProperty(this, "firstPartyHosts", DEFAULTS.getFirstPartyHosts());
|
|
76
98
|
|
|
77
99
|
_defineProperty(this, "version", void 0);
|
|
78
100
|
|
|
79
101
|
_defineProperty(this, "versionSuffix", void 0);
|
|
80
102
|
|
|
81
|
-
_defineProperty(this, "
|
|
103
|
+
_defineProperty(this, "telemetrySampleRate", DEFAULTS.telemetrySampleRate);
|
|
104
|
+
|
|
105
|
+
_defineProperty(this, "additionalConfig", DEFAULTS.getAdditionalConfig());
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Auto Instrumentation configuration passed to DatadogProvider.
|
|
111
|
+
* Does not include default values.
|
|
112
|
+
*/
|
|
113
|
+
|
|
85
114
|
|
|
86
115
|
exports.DdSdkReactNativeConfiguration = DdSdkReactNativeConfiguration;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* We could use `Proxy` instead of this function, but `Proxy` is not available on
|
|
119
|
+
* the older android jsc that can still be used.
|
|
120
|
+
*/
|
|
121
|
+
const addDefaultValuesToAutoInstrumentationConfiguration = features => {
|
|
122
|
+
return { ...features,
|
|
123
|
+
firstPartyHosts: features.firstPartyHosts || DEFAULTS.getFirstPartyHosts(),
|
|
124
|
+
resourceTracingSamplingRate: features.resourceTracingSamplingRate || DEFAULTS.resourceTracingSamplingRate
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
exports.addDefaultValuesToAutoInstrumentationConfiguration = addDefaultValuesToAutoInstrumentationConfiguration;
|
|
129
|
+
|
|
130
|
+
const setConfigurationAttribute = (attribute, configuration) => {
|
|
131
|
+
if (attribute.value !== undefined) {
|
|
132
|
+
configuration[attribute.name] = attribute.value;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const buildConfigurationFromPartialConfiguration = (features, configuration) => {
|
|
137
|
+
const {
|
|
138
|
+
clientToken,
|
|
139
|
+
env,
|
|
140
|
+
applicationId,
|
|
141
|
+
...remainingConfiguration
|
|
142
|
+
} = configuration;
|
|
143
|
+
const SdkConfiguration = new DdSdkReactNativeConfiguration(clientToken, env, applicationId, features.trackInteractions, features.trackResources, features.trackErrors, configuration.trackingConsent);
|
|
144
|
+
Object.keys(remainingConfiguration).forEach(name => {
|
|
145
|
+
setConfigurationAttribute({
|
|
146
|
+
value: remainingConfiguration[name],
|
|
147
|
+
name
|
|
148
|
+
}, SdkConfiguration);
|
|
149
|
+
});
|
|
150
|
+
setConfigurationAttribute({
|
|
151
|
+
name: 'resourceTracingSamplingRate',
|
|
152
|
+
value: features.resourceTracingSamplingRate
|
|
153
|
+
}, SdkConfiguration);
|
|
154
|
+
setConfigurationAttribute({
|
|
155
|
+
name: 'firstPartyHosts',
|
|
156
|
+
value: features.firstPartyHosts
|
|
157
|
+
}, SdkConfiguration);
|
|
158
|
+
return SdkConfiguration;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
exports.buildConfigurationFromPartialConfiguration = buildConfigurationFromPartialConfiguration;
|
|
162
|
+
|
|
163
|
+
class DatadogProviderConfiguration extends DdSdkReactNativeConfiguration {
|
|
164
|
+
constructor(...args) {
|
|
165
|
+
super(...args);
|
|
166
|
+
|
|
167
|
+
_defineProperty(this, "initializationMode", InitializationMode.SYNC);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
exports.DatadogProviderConfiguration = DatadogProviderConfiguration;
|
|
173
|
+
let InitializationMode;
|
|
174
|
+
exports.InitializationMode = InitializationMode;
|
|
175
|
+
|
|
176
|
+
(function (InitializationMode) {
|
|
177
|
+
InitializationMode["SYNC"] = "SYNC";
|
|
178
|
+
InitializationMode["ASYNC"] = "ASYNC";
|
|
179
|
+
})(InitializationMode || (exports.InitializationMode = InitializationMode = {}));
|
|
87
180
|
//# sourceMappingURL=DdSdkReactNativeConfiguration.js.map
|