@datadog/mobile-react-native 1.0.0-rc3 → 1.0.0-rc4
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/DatadogSDKReactNative.podspec +1 -1
- package/android/build.gradle +2 -3
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
- package/ios/Sources/DdRum.m +10 -9
- package/ios/Sources/DdRum.swift +24 -24
- package/ios/Sources/DdTrace.m +2 -2
- package/ios/Sources/DdTrace.swift +6 -6
- package/lib/commonjs/DdSdkReactNative.js +5 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/foundation.js +13 -31
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +24 -4
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +87 -2
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +4 -0
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/foundation.js +13 -31
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +23 -4
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +83 -2
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/DdSdkReactNative.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
- package/lib/typescript/types.d.ts +12 -11
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +3 -3
- package/src/DdSdkReactNative.tsx +4 -0
- package/src/__tests__/DdRumWrapper.test.tsx +91 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +15 -0
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +104 -10
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +265 -15
- package/src/foundation.tsx +64 -70
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +28 -7
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +74 -2
- package/src/types.tsx +12 -11
- package/src/version.ts +2 -0
|
@@ -6,6 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
* Copyright 2016-Present Datadog, Inc.
|
|
7
7
|
*/
|
|
8
8
|
import { DdRum } from '../../foundation';
|
|
9
|
+
const EMPTY_MESSAGE = "Unknown Error";
|
|
9
10
|
const EMPTY_STACK_TRACE = "";
|
|
10
11
|
const TYPE_SOURCE = "SOURCE";
|
|
11
12
|
const TYPE_CONSOLE = "CONSOLE";
|
|
@@ -38,7 +39,9 @@ export class DdRumErrorTracking {
|
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
static onGlobalError(error, isFatal) {
|
|
41
|
-
|
|
42
|
+
const message = DdRumErrorTracking.getErrorMessage(error);
|
|
43
|
+
const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
|
|
44
|
+
DdRum.addError(message, TYPE_SOURCE, stacktrace, {
|
|
42
45
|
"_dd.error.is_crash": isFatal,
|
|
43
46
|
"_dd.error.raw": error
|
|
44
47
|
}).then(() => {
|
|
@@ -72,10 +75,8 @@ export class DdRumErrorTracking {
|
|
|
72
75
|
const message = params.map(param => {
|
|
73
76
|
if (typeof param === 'string') {
|
|
74
77
|
return param;
|
|
75
|
-
} else if (param instanceof Error) {
|
|
76
|
-
return String(param);
|
|
77
78
|
} else {
|
|
78
|
-
return
|
|
79
|
+
return DdRumErrorTracking.getErrorMessage(param);
|
|
79
80
|
}
|
|
80
81
|
}).join(' ');
|
|
81
82
|
DdRum.addError(message, TYPE_CONSOLE, stack).then(() => {
|
|
@@ -83,6 +84,20 @@ export class DdRumErrorTracking {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
static getErrorMessage(error) {
|
|
88
|
+
let message = EMPTY_MESSAGE;
|
|
89
|
+
|
|
90
|
+
if (error == undefined) {
|
|
91
|
+
message = EMPTY_MESSAGE;
|
|
92
|
+
} else if ("message" in error) {
|
|
93
|
+
message = String(error.message);
|
|
94
|
+
} else {
|
|
95
|
+
message = String(error);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return message;
|
|
99
|
+
}
|
|
100
|
+
|
|
86
101
|
static getErrorStackTrace(error) {
|
|
87
102
|
let stack = EMPTY_STACK_TRACE;
|
|
88
103
|
|
|
@@ -92,6 +107,10 @@ export class DdRumErrorTracking {
|
|
|
92
107
|
stack = EMPTY_STACK_TRACE;
|
|
93
108
|
} else if ('componentStack' in error) {
|
|
94
109
|
stack = String(error.componentStack);
|
|
110
|
+
} else if ('stacktrace' in error) {
|
|
111
|
+
stack = String(error.stacktrace);
|
|
112
|
+
} else if ('stack' in error) {
|
|
113
|
+
stack = String(error.stack);
|
|
95
114
|
} else if ('sourceURL' in error && 'line' in error && 'column' in error) {
|
|
96
115
|
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
97
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumErrorTracking.tsx"],"names":["DdRum","EMPTY_STACK_TRACE","TYPE_SOURCE","TYPE_CONSOLE","DdRumErrorTracking","startTracking","isTracking","console","log","ErrorUtils","defaultErrorHandler","getGlobalHandler","defaultConsoleError","error","setGlobalHandler","onGlobalError","onConsoleError","isFatal","
|
|
1
|
+
{"version":3,"sources":["DdRumErrorTracking.tsx"],"names":["DdRum","EMPTY_MESSAGE","EMPTY_STACK_TRACE","TYPE_SOURCE","TYPE_CONSOLE","DdRumErrorTracking","startTracking","isTracking","console","log","ErrorUtils","defaultErrorHandler","getGlobalHandler","defaultConsoleError","error","setGlobalHandler","onGlobalError","onConsoleError","isFatal","message","getErrorMessage","stacktrace","getErrorStackTrace","addError","then","isInDefaultErrorHandler","params","stack","i","length","param","paramStack","undefined","map","join","apply","String","componentStack","sourceURL","line","column","_error","_isFatal","_params"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,KAAT,QAAsB,kBAAtB;AAGA,MAAMC,aAAa,GAAG,eAAtB;AACA,MAAMC,iBAAiB,GAAG,EAA1B;AACA,MAAMC,WAAW,GAAG,QAApB;AACA,MAAMC,YAAY,GAAG,SAArB;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,kBAAN,CAAyB;AAM5B;AAGA;;AAGA;AACJ;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,kBAAkB,CAACE,UAAvB,EAAmC;AAC/BC,MAAAA,OAAO,CAACC,GAAR,CAAY,oCAAZ;AACA;AACH;;AAED,QAAIC,UAAJ,EAAgB;AACZL,MAAAA,kBAAkB,CAACM,mBAAnB,GAAyCD,UAAU,CAACE,gBAAX,EAAzC;AACAP,MAAAA,kBAAkB,CAACQ,mBAAnB,GAAyCL,OAAO,CAACM,KAAjD;AAGAJ,MAAAA,UAAU,CAACK,gBAAX,CAA4BV,kBAAkB,CAACW,aAA/C;AACAR,MAAAA,OAAO,CAACM,KAAR,GAAgBT,kBAAkB,CAACY,cAAnC;AAEAZ,MAAAA,kBAAkB,CAACE,UAAnB,GAAgC,IAAhC;AACH;AAEJ,GAjC2B,CAmC5B;;;AACoB,SAAbS,aAAa,CAACF,KAAD,EAAaI,OAAb,EAAsC;AACtD,UAAMC,OAAO,GAAGd,kBAAkB,CAACe,eAAnB,CAAmCN,KAAnC,CAAhB;AACA,UAAMO,UAAU,GAAGhB,kBAAkB,CAACiB,kBA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AK,CAACwB,SAAU,IAAGxB,KAAK,CAACyB,IAAK,IAAGzB,KAAK,CAAC0B,MAAO,EAA5D;AACH;;AAED,WAAOb,KAAP;AACH;;AArH2B;;gBAAnBtB,kB,gBAEmB,K;;gBAFnBA,kB,6BAIgC,K;;gBAJhCA,kB,yBAOkD,CAACoC,MAAD,EAAcC,QAAd,KAAqC,CAAG,C;;gBAP1FrC,kB,yBAU4B,CAAC,GAAGsC,OAAJ,KAA2B,CAAG,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 type { ErrorHandlerCallback } from 'react-native';\nimport { DdRum } from '../../foundation';\n\n\nconst EMPTY_MESSAGE = \"Unknown Error\"\nconst EMPTY_STACK_TRACE = \"\"\nconst TYPE_SOURCE = \"SOURCE\"\nconst TYPE_CONSOLE = \"CONSOLE\"\n\n/**\n* Provides RUM auto-instrumentation feature to track errors as RUM events.\n*/\nexport class DdRumErrorTracking {\n\n private static isTracking = false;\n\n private static isInDefaultErrorHandler = false;\n\n // eslint-disable-next-line \n private static defaultErrorHandler: ErrorHandlerCallback = (_error: any, _isFatal?: boolean) => { }\n\n // eslint-disable-next-line \n private static defaultConsoleError = (..._params: unknown[]) => { }\n\n /**\n * Starts tracking errors and sends a RUM Error event every time an error is detected.\n */\n static startTracking(): void {\n // extra safety to avoid wrapping the Error handler twice\n if (DdRumErrorTracking.isTracking) {\n console.log(\"DdRumErrorTracking already started\");\n return\n }\n\n if (ErrorUtils) {\n DdRumErrorTracking.defaultErrorHandler = ErrorUtils.getGlobalHandler();\n DdRumErrorTracking.defaultConsoleError = console.error;\n\n\n ErrorUtils.setGlobalHandler(DdRumErrorTracking.onGlobalError);\n console.error = DdRumErrorTracking.onConsoleError;\n\n DdRumErrorTracking.isTracking = true;\n }\n\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static onGlobalError(error: any, isFatal?: boolean): void {\n const message = DdRumErrorTracking.getErrorMessage(error);\n const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);\n DdRum.addError(\n message,\n TYPE_SOURCE,\n stacktrace,\n { \"_dd.error.is_crash\": isFatal, \"_dd.error.raw\": error }\n ).then(() => {\n DdRumErrorTracking.isInDefaultErrorHandler = true;\n try {\n DdRumErrorTracking.defaultErrorHandler(error, isFatal);\n } finally {\n DdRumErrorTracking.isInDefaultErrorHandler = false;\n }\n });\n }\n\n static onConsoleError(...params: unknown[]): void {\n\n if (DdRumErrorTracking.isInDefaultErrorHandler) {\n return;\n }\n\n let stack: string = EMPTY_STACK_TRACE;\n for (let i = 0; i < params.length; i += 1) {\n const param = params[i];\n const paramStack = DdRumErrorTracking.getErrorStackTrace(param);\n if (paramStack != undefined && paramStack != EMPTY_STACK_TRACE) {\n stack = paramStack;\n break;\n }\n }\n\n const message = params.map((param) => { \n if (typeof param === 'string') { return param; }\n else { return DdRumErrorTracking.getErrorMessage(param); }\n }).join(' ');\n\n\n DdRum.addError(\n message,\n TYPE_CONSOLE,\n stack\n ).then(() => {\n DdRumErrorTracking.defaultConsoleError.apply(console, params);\n });\n\n }\n\n private static getErrorMessage(error: any | undefined): string {\n let message = EMPTY_MESSAGE;\n if (error == undefined) {\n message = EMPTY_MESSAGE;\n } else if (\"message\" in error){\n message = String(error.message);\n } else {\n message = String(error);\n }\n\n return message\n }\n\n private static getErrorStackTrace(error: any | undefined): string {\n let stack = EMPTY_STACK_TRACE\n\n if (error == undefined) {\n stack = EMPTY_STACK_TRACE;\n } else if (typeof error === 'string') {\n stack = EMPTY_STACK_TRACE;\n } else if ('componentStack' in error) {\n stack = String(error.componentStack);\n } else if ('stacktrace' in error) {\n stack = String(error.stacktrace);\n } else if ('stack' in error) {\n stack = String(error.stack);\n } else if (('sourceURL' in error) && ('line' in error) && ('column' in error)) {\n stack = `at ${error.sourceURL}:${error.line}:${error.column}`;\n }\n\n return stack\n }\n}\n\n"]}
|
|
@@ -12,8 +12,11 @@ import { generateTraceId } from './TraceIdentifier';
|
|
|
12
12
|
export const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
13
13
|
export const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
14
14
|
export const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
15
|
+
export const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
16
|
+
export const SAMPLED_HEADER_KEY = "x-datadog-sampled";
|
|
15
17
|
export const ORIGIN_RUM = "rum";
|
|
16
18
|
const RESPONSE_START_LABEL = "response_start";
|
|
19
|
+
const MISSING_RESOURCE_SIZE = -1;
|
|
17
20
|
|
|
18
21
|
function createTimings(startTime, responseStartTime, responseEndTime) {
|
|
19
22
|
const firstByte = formatTiming(startTime, startTime, responseStartTime);
|
|
@@ -45,11 +48,86 @@ function formatTiming(origin, start, end) {
|
|
|
45
48
|
function timeToNanos(durationMs) {
|
|
46
49
|
return +(durationMs * 1e6).toFixed(0);
|
|
47
50
|
}
|
|
51
|
+
|
|
52
|
+
function byteLength(str) {
|
|
53
|
+
// This is a weird trick, but it works.
|
|
54
|
+
// Output is the same as TextEncoder.encode(...).length
|
|
55
|
+
return unescape(encodeURI(str)).length;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getResponseContentLengthFromHeader(xhr) {
|
|
59
|
+
var _xhr$getResponseHeade;
|
|
60
|
+
|
|
61
|
+
const contentLengthHeader = parseInt((_xhr$getResponseHeade = xhr.getResponseHeader('Content-Length')) !== null && _xhr$getResponseHeade !== void 0 ? _xhr$getResponseHeade : '', 10);
|
|
62
|
+
|
|
63
|
+
if (!isNaN(contentLengthHeader)) {
|
|
64
|
+
return contentLengthHeader;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function calculateResponseSize(xhr) {
|
|
71
|
+
const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
|
|
72
|
+
|
|
73
|
+
if (contentLengthHeader != null) {
|
|
74
|
+
return contentLengthHeader;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const response = xhr.response;
|
|
78
|
+
|
|
79
|
+
if (!response) {
|
|
80
|
+
return MISSING_RESOURCE_SIZE;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let size;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
switch (xhr.responseType) {
|
|
87
|
+
case '':
|
|
88
|
+
case 'text':
|
|
89
|
+
// String
|
|
90
|
+
size = byteLength(response);
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 'blob':
|
|
94
|
+
size = response.size;
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
case 'arraybuffer':
|
|
98
|
+
size = response.byteLength;
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
case 'document':
|
|
102
|
+
// currently not supported by RN as of 0.66
|
|
103
|
+
// HTML Document or XML Document
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case 'json':
|
|
107
|
+
// plain JS object
|
|
108
|
+
// original size was lost, because this is the object which was parsed.
|
|
109
|
+
// We can only convert back to the string and calculate the size,
|
|
110
|
+
// which will roughly match original.
|
|
111
|
+
size = byteLength(JSON.stringify(response));
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
default:
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error("Couldn't get resource size, because of the error", e);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (typeof size !== 'number') {
|
|
122
|
+
return MISSING_RESOURCE_SIZE;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return size;
|
|
126
|
+
}
|
|
48
127
|
/**
|
|
49
128
|
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
50
129
|
*/
|
|
51
130
|
|
|
52
|
-
|
|
53
131
|
export class DdRumResourceTracking {
|
|
54
132
|
/**
|
|
55
133
|
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
@@ -120,6 +198,8 @@ export class DdRumResourceTracking {
|
|
|
120
198
|
this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId);
|
|
121
199
|
this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId);
|
|
122
200
|
this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
|
|
201
|
+
this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, "1");
|
|
202
|
+
this.setRequestHeader(SAMPLED_HEADER_KEY, "1");
|
|
123
203
|
}
|
|
124
204
|
|
|
125
205
|
DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType); // eslint-disable-next-line prefer-rest-params
|
|
@@ -149,6 +229,7 @@ export class DdRumResourceTracking {
|
|
|
149
229
|
}
|
|
150
230
|
|
|
151
231
|
static reportXhr(xhrProxy) {
|
|
232
|
+
const responseSize = calculateResponseSize(xhrProxy);
|
|
152
233
|
const context = xhrProxy._datadog_xhr;
|
|
153
234
|
const key = context.timer.startTime + "/" + context.method;
|
|
154
235
|
context.timer.stop();
|
|
@@ -156,7 +237,7 @@ export class DdRumResourceTracking {
|
|
|
156
237
|
"_dd.span_id": context.spanId,
|
|
157
238
|
"_dd.trace_id": context.traceId
|
|
158
239
|
}, context.timer.startTime).then(() => {
|
|
159
|
-
DdRum.stopResource(key, xhrProxy.status, "xhr", {
|
|
240
|
+
DdRum.stopResource(key, xhrProxy.status, "xhr", responseSize, {
|
|
160
241
|
"_dd.resource_timings": context.timer.hasTickFor(RESPONSE_START_LABEL) ? createTimings(context.timer.startTime, context.timer.timeAt(RESPONSE_START_LABEL), context.timer.stopTime) : null
|
|
161
242
|
}, context.timer.stopTime);
|
|
162
243
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","DdRum","Timer","generateTraceId","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","stopTracking","proxyOpen","proxySend","method","url","spanId","traceId","_datadog_xhr","reported","timer","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","context","key","stop","startResource","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,OAAOC,KAAP,MAAkB,aAAlB;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AAEA,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP,OAAO,MAAMC,iBAAiB,GAAG,kBAA1B;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AAEP,MAAMC,oBAAoB,GAAG,gBAA7B;;AAuBA,SAASC,aAAT,CAAuBC,SAAvB,EACEC,iBADF,EAC6BC,eAD7B,EACuE;AAErE,QAAMC,SAAS,GAAGC,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBC,iBAAvB,CAA9B;AACA,QAAMI,QAAQ,GAAGD,YAAY,CAACJ,SAAD,EAAYC,iBAAZ,EAA+BC,eAA/B,CAA7B,CAHqE,CAIrE;;AACA,QAAMI,KAAK,GAAGF,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBE,eAAvB,CAA1B;AAEA,SAAO;AACLC,IAAAA,SADK;AAELE,IAAAA,QAFK;AAGLC,IAAAA;AAH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AAgBiB,OAAO,CAAChB;AAF1B,KAJF,EAQEgB,OAAO,CAACb,KAAR,CAAcpC,SARhB,EASEqD,IATF,CASO,MAAM;AACX9D,MAAAA,KAAK,CAAC+D,YAAN,CACEJ,GADF,EAEET,QAAQ,CAACc,MAFX,EAGE,KAHF,EAIE;AACE,gCAAwBN,OAAO,CAACb,KAAR,CAAcoB,UAAd,CAAyB1D,oBAAzB,IACtBC,aAAa,CACXkD,OAAO,CAACb,KAAR,CAAcpC,SADH,EAEXiD,OAAO,CAACb,KAAR,CAAcqB,MAAd,CAAqB3D,oBAArB,CAFW,EAGXmD,OAAO,CAACb,KAAR,CAAcsB,QAHH,CADS,GAKlB;AANR,OAJF,EAYET,OAAO,CAACb,KAAR,CAAcsB,QAZhB;AAaD,KAvBD;AAwBD;;AAxIgC;;gBAAtB3C,qB,gBAEiB,K;;gBAFjBA,qB;;gBAAAA,qB","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 { Platform } from 'react-native';\nimport { DdRum } from '../../foundation'\nimport Timer from '../../Timer';\nimport type { DdRumXhr } from './DdRumXhr'\nimport { generateTraceId } from './TraceIdentifier';\n\nexport const TRACE_ID_HEADER_KEY = \"x-datadog-trace-id\"\nexport const PARENT_ID_HEADER_KEY = \"x-datadog-parent-id\"\nexport const ORIGIN_HEADER_KEY = \"x-datadog-origin\"\nexport const ORIGIN_RUM = \"rum\"\n\nconst RESPONSE_START_LABEL = \"response_start\"\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number\n /**\n * Duration in ns.\n */\n duration: number\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing,\n download: Timing,\n // required by iOS, total timing from the beginning to the end\n fetch: Timing\n}\n\nfunction createTimings(startTime: number,\n responseStartTime: number, responseEndTime: number): ResourceTimings {\n\n const firstByte = formatTiming(startTime, startTime, responseStartTime)\n const download = formatTiming(startTime, responseStartTime, responseEndTime)\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime)\n\n return {\n firstByte,\n download,\n fetch\n }\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)\n }\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0)\n}\n\n/**\n* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n*/\nexport class DdRumResourceTracking {\n\n private static isTracking = false\n\n private static originalXhrOpen: any\n private static originalXhrSend: any\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking(): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static startTrackingInternal(xhrType: any): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n return\n }\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType)\n }\n\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static proxyXhr(xhrType: any): void {\n this.proxyOpen(xhrType);\n this.proxySend(xhrType);\n }\n\n private static proxyOpen(xhrType: any): void {\n const originalXhrOpen = this.originalXhrOpen;\n xhrType.prototype.open = function (this: DdRumXhr, method: string, url: string) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n const spanId = generateTraceId()\n const traceId = generateTraceId()\n this._datadog_xhr = {\n method,\n url: url,\n reported: false,\n timer: new Timer(),\n spanId: spanId,\n traceId: traceId\n }\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any)\n }\n }\n\n private static proxySend(xhrType: any): void {\n const originalXhrSend = this.originalXhrSend;\n xhrType.prototype.send = function (this: DdRumXhr) {\n\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start()\n this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId)\n this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId)\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM)\n\n }\n\n DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n }\n }\n\n private static proxyOnReadyStateChange(xhrProxy: DdRumXhr, xhrType: any): void {\n const originalOnreadystatechange = xhrProxy.onreadystatechange\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n DdRumResourceTracking.reportXhr(xhrProxy);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL)\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any)\n }\n }\n }\n\n private static reportXhr(xhrProxy: DdRumXhr): void {\n\n const context = xhrProxy._datadog_xhr\n\n const key = context.timer.startTime + \"/\" + context.method\n\n context.timer.stop()\n\n DdRum.startResource(\n key,\n context.method,\n context.url,\n {\n \"_dd.span_id\": context.spanId,\n \"_dd.trace_id\": context.traceId\n },\n context.timer.startTime\n ).then(() => {\n DdRum.stopResource(\n key,\n xhrProxy.status,\n \"xhr\",\n {\n \"_dd.resource_timings\": context.timer.hasTickFor(RESPONSE_START_LABEL) ?\n createTimings(\n context.timer.startTime,\n context.timer.timeAt(RESPONSE_START_LABEL),\n context.timer.stopTime\n ) : null\n },\n context.timer.stopTime);\n })\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","DdRum","Timer","generateTraceId","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","SAMPLED_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","MISSING_RESOURCE_SIZE","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","console","error","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","stopTracking","proxyOpen","proxySend","method","url","spanId","traceId","_datadog_xhr","reported","timer","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","responseSize","context","key","stop","startResource","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,OAAOC,KAAP,MAAk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AHF,EAIEP,YAJF,EAKE;AACE,gCAAwBC,OAAO,CAACd,KAAR,CAAcqB,UAAd,CAAyBhF,oBAAzB,IACtBE,aAAa,CACXuE,OAAO,CAACd,KAAR,CAAcxD,SADH,EAEXsE,OAAO,CAACd,KAAR,CAAcsB,MAAd,CAAqBjF,oBAArB,CAFW,EAGXyE,OAAO,CAACd,KAAR,CAAcuB,QAHH,CADS,GAKlB;AANR,OALF,EAaET,OAAO,CAACd,KAAR,CAAcuB,QAbhB;AAeD,KAzBD;AA0BD;;AA7IgC;;gBAAtB5C,qB,gBAEiB,K;;gBAFjBA,qB;;gBAAAA,qB","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 { Platform } from 'react-native';\nimport { DdRum } from '../../foundation'\nimport Timer from '../../Timer';\nimport type { DdRumXhr } from './DdRumXhr'\nimport { generateTraceId } from './TraceIdentifier';\n\nexport const TRACE_ID_HEADER_KEY = \"x-datadog-trace-id\"\nexport const PARENT_ID_HEADER_KEY = \"x-datadog-parent-id\"\nexport const ORIGIN_HEADER_KEY = \"x-datadog-origin\"\nexport const SAMPLING_PRIORITY_HEADER_KEY = \"x-datadog-sampling-priority\"\nexport const SAMPLED_HEADER_KEY = \"x-datadog-sampled\"\nexport const ORIGIN_RUM = \"rum\"\n\nconst RESPONSE_START_LABEL = \"response_start\"\nconst MISSING_RESOURCE_SIZE = -1\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number\n /**\n * Duration in ns.\n */\n duration: number\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing,\n download: Timing,\n // required by iOS, total timing from the beginning to the end\n fetch: Timing\n}\n\nfunction createTimings(startTime: number,\n responseStartTime: number, responseEndTime: number): ResourceTimings {\n\n const firstByte = formatTiming(startTime, startTime, responseStartTime)\n const download = formatTiming(startTime, responseStartTime, responseEndTime)\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime)\n\n return {\n firstByte,\n download,\n fetch\n }\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)\n }\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0)\n}\n\nfunction byteLength(str: string): number {\n // This is a weird trick, but it works.\n // Output is the same as TextEncoder.encode(...).length\n return unescape(encodeURI(str)).length;\n}\n\nfunction getResponseContentLengthFromHeader(xhr: XMLHttpRequest): number | null {\n const contentLengthHeader = parseInt(xhr.getResponseHeader('Content-Length') ?? '', 10);\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\n\n const contentLengthHeader = getResponseContentLengthFromHeader(xhr);\n if (contentLengthHeader != null) {\n return contentLengthHeader as number;\n }\n\n const response = xhr.response\n if (!response) {\n return MISSING_RESOURCE_SIZE;\n }\n\n let size;\n try {\n switch (xhr.responseType) {\n case '':\n case 'text':\n // String\n size = byteLength(response);\n break;\n case 'blob':\n size = response.size;\n break;\n case 'arraybuffer':\n size = response.byteLength;\n break;\n case 'document':\n // currently not supported by RN as of 0.66\n // HTML Document or XML Document\n break;\n case 'json':\n // plain JS object\n // original size was lost, because this is the object which was parsed.\n // We can only convert back to the string and calculate the size,\n // which will roughly match original.\n size = byteLength(JSON.stringify(response))\n break;\n default:\n break;\n }\n } catch (e) {\n console.error(\"Couldn't get resource size, because of the error\", e);\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n\n/**\n* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n*/\nexport class DdRumResourceTracking {\n\n private static isTracking = false\n\n private static originalXhrOpen: any\n private static originalXhrSend: any\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking(): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static startTrackingInternal(xhrType: any): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n return\n }\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType)\n }\n\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static proxyXhr(xhrType: any): void {\n this.proxyOpen(xhrType);\n this.proxySend(xhrType);\n }\n\n private static proxyOpen(xhrType: any): void {\n const originalXhrOpen = this.originalXhrOpen;\n xhrType.prototype.open = function (this: DdRumXhr, method: string, url: string) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n const spanId = generateTraceId()\n const traceId = generateTraceId()\n this._datadog_xhr = {\n method,\n url: url,\n reported: false,\n timer: new Timer(),\n spanId: spanId,\n traceId: traceId\n }\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any)\n }\n }\n\n private static proxySend(xhrType: any): void {\n const originalXhrSend = this.originalXhrSend;\n xhrType.prototype.send = function (this: DdRumXhr) {\n\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start()\n this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId)\n this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId)\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM)\n this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, \"1\")\n this.setRequestHeader(SAMPLED_HEADER_KEY, \"1\")\n }\n\n DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n }\n }\n\n private static proxyOnReadyStateChange(xhrProxy: DdRumXhr, xhrType: any): void {\n const originalOnreadystatechange = xhrProxy.onreadystatechange\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n DdRumResourceTracking.reportXhr(xhrProxy);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL)\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any)\n }\n }\n }\n\n private static reportXhr(xhrProxy: DdRumXhr): void {\n\n const responseSize = calculateResponseSize(xhrProxy)\n\n const context = xhrProxy._datadog_xhr\n\n const key = context.timer.startTime + \"/\" + context.method\n\n context.timer.stop()\n\n DdRum.startResource(\n key,\n context.method,\n context.url,\n {\n \"_dd.span_id\": context.spanId,\n \"_dd.trace_id\": context.traceId\n },\n context.timer.startTime\n ).then(() => {\n DdRum.stopResource(\n key,\n xhrProxy.status,\n \"xhr\",\n responseSize,\n {\n \"_dd.resource_timings\": context.timer.hasTickFor(RESPONSE_START_LABEL) ?\n createTimings(\n context.timer.startTime,\n context.timer.timeAt(RESPONSE_START_LABEL),\n context.timer.stopTime\n ) : null\n },\n context.timer.stopTime\n );\n })\n }\n\n}\n"]}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACAC,WADA,EAEAC,GAFA,EAGAC,aAHA,EAIAC,wBAJA,EAKAC,UALA,EAMAC,IANA,EAOAC,eAPA,EAQAC,gBARA,EAST;AAAA,SARSP,WAQT,GARSA,WAQT;AAAA,SAPSC,GAOT,GAPSA,GAOT;AAAA,SANSC,aAMT,GANSA,aAMT;AAAA,SALSC,wBAKT,GALSA,wBAKT;AAAA,SAJSC,UAIT,GAJSA,UAIT;AAAA,SAHSC,IAGT,GAHSA,IAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,gBACT,GADSA,gBACT;AAAE;;AAV0B;AAahC;AACA;AACA","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\n/**\n * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\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 */\n setAttributes(attributes: object): Promise<void>;\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 */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds).\n */\n startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds).\n */\n finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds).\n */\n startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds).\n */\n stopView(key: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds).\n */\n startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds).\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds).\n */\n addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds).\n */\n startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds).\n */\n stopResource(key: string, statusCode: number, kind: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds).\n */\n addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n\n};\n\n"]}
|
|
1
|
+
{"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACAC,WADA,EAEAC,GAFA,EAGAC,aAHA,EAIAC,wBAJA,EAKAC,UALA,EAMAC,IANA,EAOAC,eAPA,EAQAC,gBARA,EAST;AAAA,SARSP,WAQT,GARSA,WAQT;AAAA,SAPSC,GAOT,GAPSA,GAOT;AAAA,SANSC,aAMT,GANSA,aAMT;AAAA,SALSC,wBAKT,GALSA,wBAKT;AAAA,SAJSC,UAIT,GAJSA,UAIT;AAAA,SAHSC,IAGT,GAHSA,IAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,gBACT,GADSA,gBACT;AAAE;;AAV0B;AAahC;AACA;AACA","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\n/**\n * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\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 */\n setAttributes(attributes: object): Promise<void>;\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 */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(key: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n\n};\n\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,WAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.0.0-rc4';\n"]}
|
|
@@ -5,6 +5,7 @@ import type { TrackingConsent } from "./TrackingConsent";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class DdSdkReactNative {
|
|
7
7
|
private static readonly DD_SOURCE_KEY;
|
|
8
|
+
private static readonly DD_SDK_VERSION;
|
|
8
9
|
private static readonly DD_SERVICE_NAME;
|
|
9
10
|
private static readonly DD_SDK_VERBOSITY_KEY;
|
|
10
11
|
private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
|
|
@@ -12,5 +12,6 @@ export declare class DdRumErrorTracking {
|
|
|
12
12
|
static startTracking(): void;
|
|
13
13
|
static onGlobalError(error: any, isFatal?: boolean): void;
|
|
14
14
|
static onConsoleError(...params: unknown[]): void;
|
|
15
|
+
private static getErrorMessage;
|
|
15
16
|
private static getErrorStackTrace;
|
|
16
17
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/// <reference types="react-native" />
|
|
1
2
|
export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
2
3
|
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
3
4
|
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
5
|
+
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
6
|
+
export declare const SAMPLED_HEADER_KEY = "x-datadog-sampled";
|
|
4
7
|
export declare const ORIGIN_RUM = "rum";
|
|
8
|
+
export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
|
|
5
9
|
/**
|
|
6
10
|
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
7
11
|
*/
|
|
@@ -74,14 +74,14 @@ export declare type DdTraceType = {
|
|
|
74
74
|
* Start a span, and returns a unique identifier for the span.
|
|
75
75
|
* @param operation: The operation name of the span.
|
|
76
76
|
* @param context: The additional context to send.
|
|
77
|
-
* @param timestampMs: The timestamp when the operation started (in milliseconds).
|
|
77
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
78
78
|
*/
|
|
79
79
|
startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
|
|
80
80
|
/**
|
|
81
81
|
* Finish a started span.
|
|
82
82
|
* @param spanId: The unique identifier of the span.
|
|
83
83
|
* @param context: The additional context to send.
|
|
84
|
-
* @param timestampMs: The timestamp when the operation stopped (in milliseconds).
|
|
84
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
85
85
|
*/
|
|
86
86
|
finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
|
|
87
87
|
};
|
|
@@ -94,14 +94,14 @@ export declare type DdRumType = {
|
|
|
94
94
|
* @param key: The view unique key identifier.
|
|
95
95
|
* @param name: The view name.
|
|
96
96
|
* @param context: The additional context to send.
|
|
97
|
-
* @param timestampMs: The timestamp when the view started (in milliseconds).
|
|
97
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
98
98
|
*/
|
|
99
99
|
startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Stop tracking a RUM View.
|
|
102
102
|
* @param key: The view unique key identifier.
|
|
103
103
|
* @param context: The additional context to send.
|
|
104
|
-
* @param timestampMs: The timestamp when the view stopped (in milliseconds).
|
|
104
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
105
105
|
*/
|
|
106
106
|
stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
|
|
107
107
|
/**
|
|
@@ -109,13 +109,13 @@ export declare type DdRumType = {
|
|
|
109
109
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
110
110
|
* @param name: The action name.
|
|
111
111
|
* @param context: The additional context to send.
|
|
112
|
-
* @param timestampMs: The timestamp when the action started (in milliseconds).
|
|
112
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
113
113
|
*/
|
|
114
114
|
startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
115
115
|
/**
|
|
116
116
|
* Stop tracking the ongoing RUM Action.
|
|
117
117
|
* @param context: The additional context to send.
|
|
118
|
-
* @param timestampMs: The timestamp when the action stopped (in milliseconds).
|
|
118
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
119
119
|
*/
|
|
120
120
|
stopAction(context?: object, timestampMs?: number): Promise<void>;
|
|
121
121
|
/**
|
|
@@ -123,7 +123,7 @@ export declare type DdRumType = {
|
|
|
123
123
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
124
124
|
* @param name: The action name.
|
|
125
125
|
* @param context: The additional context to send.
|
|
126
|
-
* @param timestampMs: The timestamp when the action occurred (in milliseconds).
|
|
126
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
127
127
|
*/
|
|
128
128
|
addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
129
129
|
/**
|
|
@@ -132,7 +132,7 @@ export declare type DdRumType = {
|
|
|
132
132
|
* @param method: The resource method (GET, POST, …).
|
|
133
133
|
* @param url: The resource url.
|
|
134
134
|
* @param context: The additional context to send.
|
|
135
|
-
* @param timestampMs: The timestamp when the resource started (in milliseconds).
|
|
135
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
136
136
|
*/
|
|
137
137
|
startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
|
|
138
138
|
/**
|
|
@@ -140,17 +140,18 @@ export declare type DdRumType = {
|
|
|
140
140
|
* @param key: The resource unique key identifier.
|
|
141
141
|
* @param statusCode: The resource status code.
|
|
142
142
|
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
143
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
143
144
|
* @param context: The additional context to send.
|
|
144
|
-
* @param timestampMs: The timestamp when the resource stopped (in milliseconds).
|
|
145
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
145
146
|
*/
|
|
146
|
-
stopResource(key: string, statusCode: number, kind: string, context?: object, timestampMs?: number): Promise<void>;
|
|
147
|
+
stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;
|
|
147
148
|
/**
|
|
148
149
|
* Add a RUM Error.
|
|
149
150
|
* @param message: The error message.
|
|
150
151
|
* @param source: The error source (network, source, console, logger, …).
|
|
151
152
|
* @param stacktrace: The error stacktrace.
|
|
152
153
|
* @param context: The additional context to send.
|
|
153
|
-
* @param timestampMs: The timestamp when the error occurred (in milliseconds).
|
|
154
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
154
155
|
*/
|
|
155
156
|
addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
|
|
156
157
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.0.0-rc4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc4",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": ">=16.13.1",
|
|
45
|
-
"react-native": "
|
|
45
|
+
"react-native": ">=0.63.4 <1.0"
|
|
46
46
|
},
|
|
47
47
|
"jest": {
|
|
48
48
|
"preset": "react-native",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
]
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c1bd4e6ded0b84298ca011eba679027ae7fe7841"
|
|
72
72
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -13,12 +13,15 @@ import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracki
|
|
|
13
13
|
import type { TrackingConsent } from "./TrackingConsent"
|
|
14
14
|
import { ProxyType } from "./ProxyConfiguration"
|
|
15
15
|
|
|
16
|
+
import {version as sdkVersion } from './version';
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
18
20
|
*/
|
|
19
21
|
export class DdSdkReactNative {
|
|
20
22
|
|
|
21
23
|
private static readonly DD_SOURCE_KEY = "_dd.source";
|
|
24
|
+
private static readonly DD_SDK_VERSION = "_dd.sdk_version";
|
|
22
25
|
private static readonly DD_SERVICE_NAME = "_dd.service_name";
|
|
23
26
|
private static readonly DD_SDK_VERBOSITY_KEY = "_dd.sdk_verbosity";
|
|
24
27
|
private static readonly DD_NATIVE_VIEW_TRACKING_KEY = "_dd.native_view_tracking";
|
|
@@ -49,6 +52,7 @@ export class DdSdkReactNative {
|
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
|
|
55
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
|
|
52
56
|
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
|
|
53
57
|
if (configuration.verbosity != undefined) {
|
|
54
58
|
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { NativeModules } from 'react-native'
|
|
8
|
+
import { DdRum } from '../foundation'
|
|
9
|
+
|
|
10
|
+
jest.mock('react-native', () => {
|
|
11
|
+
return {
|
|
12
|
+
NativeModules: {
|
|
13
|
+
DdRum: {
|
|
14
|
+
startView: jest.fn().mockImplementation(() => { }),
|
|
15
|
+
stopView: jest.fn().mockImplementation(() => { }),
|
|
16
|
+
startAction: jest.fn().mockImplementation(() => { }),
|
|
17
|
+
stopAction: jest.fn().mockImplementation(() => { }),
|
|
18
|
+
addAction: jest.fn().mockImplementation(() => { }),
|
|
19
|
+
startResource: jest.fn().mockImplementation(() => { }),
|
|
20
|
+
stopResource: jest.fn().mockImplementation(() => { }),
|
|
21
|
+
addError: jest.fn().mockImplementation(() => { }),
|
|
22
|
+
addTiming: jest.fn().mockImplementation(() => { })
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
NativeModules.DdRum.startView.mockClear();
|
|
30
|
+
NativeModules.DdRum.stopView.mockClear();
|
|
31
|
+
NativeModules.DdRum.startAction.mockClear();
|
|
32
|
+
NativeModules.DdRum.stopAction.mockClear();
|
|
33
|
+
NativeModules.DdRum.addAction.mockClear();
|
|
34
|
+
NativeModules.DdRum.startResource.mockClear();
|
|
35
|
+
NativeModules.DdRum.stopResource.mockClear();
|
|
36
|
+
NativeModules.DdRum.addError.mockClear();
|
|
37
|
+
NativeModules.DdRum.addTiming.mockClear();
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
it('M add error source type W addError()', async () => {
|
|
42
|
+
// Given
|
|
43
|
+
const message = "Oops I did it again!";
|
|
44
|
+
const source = "SOURCE"
|
|
45
|
+
const stacktrace = "doSomething() at ./path/to/file.js:67:3";
|
|
46
|
+
const before = Date.now();
|
|
47
|
+
|
|
48
|
+
// When
|
|
49
|
+
DdRum.addError(message, source, stacktrace);
|
|
50
|
+
|
|
51
|
+
// Then
|
|
52
|
+
const after = Date.now();
|
|
53
|
+
expect(NativeModules.DdRum.addError.mock.calls.length).toBe(1);
|
|
54
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
55
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][1]).toBe(source);
|
|
56
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][2]).toBe(stacktrace);
|
|
57
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeGreaterThanOrEqual(before);
|
|
58
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeLessThanOrEqual(before);
|
|
59
|
+
const context = NativeModules.DdRum.addError.mock.calls[0][3];
|
|
60
|
+
expect(context["_dd.error.source_type"]).toStrictEqual("react-native");
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
it('M add error source type W addError() {with custom attributes}', async () => {
|
|
65
|
+
// Given
|
|
66
|
+
const message = "Oops I did it again!";
|
|
67
|
+
const source = "SOURCE"
|
|
68
|
+
const stacktrace = "doSomething() at ./path/to/file.js:67:3";
|
|
69
|
+
const random = Math.random();
|
|
70
|
+
const attributes = {
|
|
71
|
+
"foo": "bar",
|
|
72
|
+
"spam": random
|
|
73
|
+
}
|
|
74
|
+
const before = Date.now();
|
|
75
|
+
|
|
76
|
+
// When
|
|
77
|
+
DdRum.addError(message, source, stacktrace, attributes);
|
|
78
|
+
|
|
79
|
+
// Then
|
|
80
|
+
const after = Date.now();
|
|
81
|
+
expect(NativeModules.DdRum.addError.mock.calls.length).toBe(1);
|
|
82
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
83
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][1]).toBe(source);
|
|
84
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][2]).toBe(stacktrace);
|
|
85
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeGreaterThanOrEqual(before);
|
|
86
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeLessThanOrEqual(before);
|
|
87
|
+
const context = NativeModules.DdRum.addError.mock.calls[0][3];
|
|
88
|
+
expect(context["_dd.error.source_type"]).toStrictEqual("react-native");
|
|
89
|
+
expect(context["foo"]).toStrictEqual("bar");
|
|
90
|
+
expect(context["spam"]).toStrictEqual(random);
|
|
91
|
+
})
|