@datadog/mobile-react-native 1.0.0-rc9 → 1.1.1
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 +2 -1
- package/android/build.gradle +73 -3
- package/android/gradle.properties +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
- package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
- package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
- package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
- package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
- package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
- package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
- package/datadog-sourcemaps.gradle +137 -0
- package/ios/Sources/AnyEncodable.swift +138 -0
- package/ios/Sources/Attributes.swift +101 -0
- package/ios/Sources/DdLogs.swift +35 -11
- package/ios/Sources/DdRum.m +3 -1
- package/ios/Sources/DdRum.swift +184 -22
- package/ios/Sources/DdSdk.swift +190 -10
- package/ios/Sources/DdSdkConfiguration.swift +51 -0
- package/ios/Sources/DdTrace.swift +41 -6
- package/ios/Sources/GlobalState.swift +28 -0
- package/ios/Sources/QueueHolder.swift +10 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
- package/lib/commonjs/DdSdkReactNative.js +14 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/foundation.js +36 -2
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +36 -0
- package/lib/commonjs/nativeModulesTypes.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/types.js +26 -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/DdSdkReactNative.js +14 -0
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/foundation.js +36 -2
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +26 -0
- package/lib/module/nativeModulesTypes.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/module/types.js +23 -0
- 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/DdSdkReactNative.d.ts +2 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
- package/lib/typescript/foundation.d.ts +3 -2
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts +168 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
- package/lib/typescript/types.d.ts +42 -7
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -4
- package/src/DdSdkReactNative.tsx +20 -0
- package/src/DdSdkReactNativeConfiguration.tsx +20 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +76 -0
- package/src/__tests__/foundation.test.ts +79 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +8 -8
- package/src/foundation.tsx +40 -11
- package/src/index.tsx +3 -0
- package/src/nativeModulesTypes.ts +258 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
- package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +22 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +8 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
- package/src/types.tsx +62 -7
- package/src/version.ts +1 -1
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
- package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
package/src/foundation.tsx
CHANGED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
|
-
import { DdSdkConfiguration,
|
|
8
|
+
import { DdSdkConfiguration, DdLogsType, DdTraceType, DdRumType, RumActionType, ResourceKind, ErrorSource } from './types';
|
|
9
9
|
import {InternalLog} from "./InternalLog"
|
|
10
10
|
import {SdkVerbosity} from "./SdkVerbosity";
|
|
11
11
|
import {TimeProvider} from "./TimeProvider";
|
|
12
|
+
import type { DdNativeLogsType, DdNativeRumType, DdNativeSdkType, DdNativeTraceType } from './nativeModulesTypes';
|
|
12
13
|
|
|
13
14
|
const timeProvider = new TimeProvider();
|
|
14
15
|
|
|
15
16
|
class DdLogsWrapper implements DdLogsType {
|
|
16
17
|
|
|
17
|
-
private nativeLogs:
|
|
18
|
+
private nativeLogs: DdNativeLogsType = NativeModules.DdLogs;
|
|
18
19
|
|
|
19
20
|
debug(message: string, context: object = {}): Promise<void> {
|
|
20
21
|
InternalLog.log("Tracking debug log “" + message + "”", SdkVerbosity.DEBUG);
|
|
@@ -40,7 +41,7 @@ class DdLogsWrapper implements DdLogsType {
|
|
|
40
41
|
|
|
41
42
|
class DdTraceWrapper implements DdTraceType {
|
|
42
43
|
|
|
43
|
-
private nativeTrace:
|
|
44
|
+
private nativeTrace: DdNativeTraceType = NativeModules.DdTrace;
|
|
44
45
|
|
|
45
46
|
startSpan(operation: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<string> {
|
|
46
47
|
let spanId = this.nativeTrace.startSpan(operation, context, timestampMs);
|
|
@@ -54,9 +55,18 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
const isNewStopActionAPI = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): args is [type: RumActionType, name: string, context?: object, timestampMs?: number] => {
|
|
59
|
+
return typeof args[0] === 'string'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const isOldStopActionAPI = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): args is [context?: object, timestampMs?: number] => {
|
|
63
|
+
return typeof args[0] === 'object' || typeof args[0] === 'undefined'
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
class DdRumWrapper implements DdRumType {
|
|
58
67
|
|
|
59
|
-
private nativeRum:
|
|
68
|
+
private nativeRum: DdNativeRumType = NativeModules.DdRum;
|
|
69
|
+
private lastActionData?: {type: RumActionType, name: string}
|
|
60
70
|
|
|
61
71
|
startView(key: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
62
72
|
InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG);
|
|
@@ -68,17 +78,36 @@ class DdRumWrapper implements DdRumType {
|
|
|
68
78
|
return this.nativeRum.stopView(key, context, timestampMs);
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
startAction(type:
|
|
81
|
+
startAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
72
82
|
InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
83
|
+
this.lastActionData={type, name}
|
|
73
84
|
return this.nativeRum.startAction(type, name, context, timestampMs);
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
stopAction(
|
|
87
|
+
stopAction(...args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> {
|
|
77
88
|
InternalLog.log("Stopping current RUM Action", SdkVerbosity.DEBUG);
|
|
78
|
-
|
|
89
|
+
let returnPromise = this.getStopActionNativeCall(args)
|
|
90
|
+
this.lastActionData = undefined
|
|
91
|
+
return returnPromise
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private getStopActionNativeCall = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> => {
|
|
95
|
+
if (isNewStopActionAPI(args)) {
|
|
96
|
+
return this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now())
|
|
97
|
+
}
|
|
98
|
+
if (isOldStopActionAPI(args)) {
|
|
99
|
+
if (this.lastActionData) {
|
|
100
|
+
return this.nativeRum.stopAction(this.lastActionData.type, this.lastActionData.name, args[0] || {}, args[1] || timeProvider.now());
|
|
101
|
+
}
|
|
102
|
+
InternalLog.log("DdRum.startAction needs to be called before DdRum.stopAction", SdkVerbosity.WARN);
|
|
103
|
+
} else {
|
|
104
|
+
InternalLog.log("DdRum.stopAction was called with wrong arguments", SdkVerbosity.WARN);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return new Promise<void>(resolve => resolve())
|
|
79
108
|
}
|
|
80
109
|
|
|
81
|
-
addAction(type:
|
|
110
|
+
addAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
82
111
|
InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
83
112
|
return this.nativeRum.addAction(type, name, context, timestampMs);
|
|
84
113
|
}
|
|
@@ -88,12 +117,12 @@ class DdRumWrapper implements DdRumType {
|
|
|
88
117
|
return this.nativeRum.startResource(key, method, url, context, timestampMs);
|
|
89
118
|
}
|
|
90
119
|
|
|
91
|
-
stopResource(key: string, statusCode: number, kind:
|
|
120
|
+
stopResource(key: string, statusCode: number, kind: ResourceKind, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
92
121
|
InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG);
|
|
93
122
|
return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs);
|
|
94
123
|
}
|
|
95
124
|
|
|
96
|
-
addError(message: string, source:
|
|
125
|
+
addError(message: string, source: ErrorSource, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
97
126
|
InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG);
|
|
98
127
|
let updatedContext: any = context;
|
|
99
128
|
updatedContext["_dd.error.source_type"] = "react-native";
|
|
@@ -106,7 +135,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
106
135
|
}
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
const DdSdk:
|
|
138
|
+
const DdSdk: DdNativeSdkType = NativeModules.DdSdk;
|
|
110
139
|
const DdLogs: DdLogsType = new DdLogsWrapper();
|
|
111
140
|
const DdTrace: DdTraceType = new DdTraceWrapper();
|
|
112
141
|
const DdRum: DdRumType = new DdRumWrapper();
|
package/src/index.tsx
CHANGED
|
@@ -11,11 +11,14 @@ import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
|
11
11
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
12
12
|
import { TrackingConsent } from './TrackingConsent';
|
|
13
13
|
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
14
|
+
import { RumActionType, ErrorSource } from './types';
|
|
14
15
|
|
|
15
16
|
export {
|
|
16
17
|
DdLogs,
|
|
17
18
|
DdTrace,
|
|
18
19
|
DdRum,
|
|
20
|
+
RumActionType,
|
|
21
|
+
ErrorSource,
|
|
19
22
|
DdSdkReactNativeConfiguration,
|
|
20
23
|
DdSdkReactNative,
|
|
21
24
|
InternalLog,
|
|
@@ -0,0 +1,258 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* A configuration object to initialize Datadog's features.
|
|
9
|
+
*/
|
|
10
|
+
export class DdNativeSdkConfiguration {
|
|
11
|
+
constructor(
|
|
12
|
+
readonly clientToken: string,
|
|
13
|
+
readonly env: string,
|
|
14
|
+
readonly applicationId: string,
|
|
15
|
+
readonly nativeCrashReportEnabled: boolean,
|
|
16
|
+
readonly sampleRate: number,
|
|
17
|
+
readonly site: string,
|
|
18
|
+
readonly trackingConsent: string,
|
|
19
|
+
readonly additionalConfig: object
|
|
20
|
+
) {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The entry point to initialize Datadog's features.
|
|
25
|
+
*/
|
|
26
|
+
export type DdNativeSdkType = {
|
|
27
|
+
/**
|
|
28
|
+
* Initializes Datadog's features.
|
|
29
|
+
* @param configuration: The configuration to use.
|
|
30
|
+
*/
|
|
31
|
+
initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
35
|
+
* @param attributes: The global context attributes.
|
|
36
|
+
*/
|
|
37
|
+
setAttributes(attributes: object): Promise<void>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Set the user information.
|
|
41
|
+
* @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
|
|
42
|
+
*/
|
|
43
|
+
setUser(user: object): Promise<void>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Set the tracking consent regarding the data collection.
|
|
47
|
+
* @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
48
|
+
*/
|
|
49
|
+
setTrackingConsent(trackingConsent: string): Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The entry point to use Datadog's Logs feature.
|
|
54
|
+
*/
|
|
55
|
+
export type DdNativeLogsType = {
|
|
56
|
+
/**
|
|
57
|
+
* Send a log with level debug.
|
|
58
|
+
* @param message: The message to send.
|
|
59
|
+
* @param context: The additional context to send.
|
|
60
|
+
*/
|
|
61
|
+
debug(message: string, context?: object): Promise<void>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Send a log with level info.
|
|
65
|
+
* @param message: The message to send.
|
|
66
|
+
* @param context: The additional context to send.
|
|
67
|
+
*/
|
|
68
|
+
info(message: string, context?: object): Promise<void>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Send a log with level warn.
|
|
72
|
+
* @param message: The message to send.
|
|
73
|
+
* @param context: The additional context to send.
|
|
74
|
+
*/
|
|
75
|
+
warn(message: string, context?: object): Promise<void>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Send a log with level error.
|
|
79
|
+
* @param message: The message to send.
|
|
80
|
+
* @param context: The additional context to send.
|
|
81
|
+
*/
|
|
82
|
+
error(message: string, context?: object): Promise<void>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The entry point to use Datadog's Trace feature.
|
|
87
|
+
*/
|
|
88
|
+
export type DdNativeTraceType = {
|
|
89
|
+
/**
|
|
90
|
+
* Start a span, and returns a unique identifier for the span.
|
|
91
|
+
* @param operation: The operation name of the span.
|
|
92
|
+
* @param context: The additional context to send.
|
|
93
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
94
|
+
*/
|
|
95
|
+
startSpan(
|
|
96
|
+
operation: string,
|
|
97
|
+
context?: object,
|
|
98
|
+
timestampMs?: number
|
|
99
|
+
): Promise<string>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Finish a started span.
|
|
103
|
+
* @param spanId: The unique identifier of the span.
|
|
104
|
+
* @param context: The additional context to send.
|
|
105
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
106
|
+
*/
|
|
107
|
+
finishSpan(
|
|
108
|
+
spanId: string,
|
|
109
|
+
context?: object,
|
|
110
|
+
timestampMs?: number
|
|
111
|
+
): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The entry point to use Datadog's RUM feature.
|
|
116
|
+
*/
|
|
117
|
+
export type DdNativeRumType = {
|
|
118
|
+
/**
|
|
119
|
+
* Start tracking a RUM View.
|
|
120
|
+
* @param key: The view unique key identifier.
|
|
121
|
+
* @param name: The view name.
|
|
122
|
+
* @param context: The additional context to send.
|
|
123
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
124
|
+
*/
|
|
125
|
+
startView(
|
|
126
|
+
key: string,
|
|
127
|
+
name: string,
|
|
128
|
+
context?: object,
|
|
129
|
+
timestampMs?: number
|
|
130
|
+
): Promise<void>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Stop tracking a RUM View.
|
|
134
|
+
* @param key: The view unique key identifier.
|
|
135
|
+
* @param context: The additional context to send.
|
|
136
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
137
|
+
*/
|
|
138
|
+
stopView(
|
|
139
|
+
key: string,
|
|
140
|
+
context?: object,
|
|
141
|
+
timestampMs?: number
|
|
142
|
+
): Promise<void>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Start tracking a RUM Action.
|
|
146
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
147
|
+
* @param name: The action name.
|
|
148
|
+
* @param context: The additional context to send.
|
|
149
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
150
|
+
*/
|
|
151
|
+
startAction(
|
|
152
|
+
type: ActionType,
|
|
153
|
+
name: string,
|
|
154
|
+
context?: object,
|
|
155
|
+
timestampMs?: number
|
|
156
|
+
): Promise<void>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Stop tracking the ongoing RUM Action.
|
|
160
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
161
|
+
* @param name: The action name.
|
|
162
|
+
* @param context: The additional context to send.
|
|
163
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
164
|
+
*/
|
|
165
|
+
stopAction(
|
|
166
|
+
type: ActionType,
|
|
167
|
+
name: string,
|
|
168
|
+
context?: object,
|
|
169
|
+
timestampMs?: number
|
|
170
|
+
): Promise<void>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Add a RUM Action.
|
|
174
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
175
|
+
* @param name: The action name.
|
|
176
|
+
* @param context: The additional context to send.
|
|
177
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
178
|
+
*/
|
|
179
|
+
addAction(
|
|
180
|
+
type: ActionType,
|
|
181
|
+
name: string,
|
|
182
|
+
context?: object,
|
|
183
|
+
timestampMs?: number
|
|
184
|
+
): Promise<void>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Start tracking a RUM Resource.
|
|
188
|
+
* @param key: The resource unique key identifier.
|
|
189
|
+
* @param method: The resource method (GET, POST, …).
|
|
190
|
+
* @param url: The resource url.
|
|
191
|
+
* @param context: The additional context to send.
|
|
192
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
193
|
+
*/
|
|
194
|
+
startResource(
|
|
195
|
+
key: string,
|
|
196
|
+
method: string,
|
|
197
|
+
url: string,
|
|
198
|
+
context?: object,
|
|
199
|
+
timestampMs?: number
|
|
200
|
+
): Promise<void>;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Stop tracking a RUM Resource.
|
|
204
|
+
* @param key: The resource unique key identifier.
|
|
205
|
+
* @param statusCode: The resource status code.
|
|
206
|
+
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
207
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
208
|
+
* @param context: The additional context to send.
|
|
209
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
210
|
+
*/
|
|
211
|
+
stopResource(
|
|
212
|
+
key: string,
|
|
213
|
+
statusCode: number,
|
|
214
|
+
kind: ResourceKind,
|
|
215
|
+
size?: number,
|
|
216
|
+
context?: object,
|
|
217
|
+
timestampMs?: number
|
|
218
|
+
): Promise<void>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Add a RUM Error.
|
|
222
|
+
* @param message: The error message.
|
|
223
|
+
* @param source: The error source (network, source, console, webview, custom).
|
|
224
|
+
* @param stacktrace: The error stacktrace.
|
|
225
|
+
* @param context: The additional context to send.
|
|
226
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
227
|
+
*/
|
|
228
|
+
addError(
|
|
229
|
+
message: string,
|
|
230
|
+
source: ErrorSource,
|
|
231
|
+
stacktrace: string,
|
|
232
|
+
context?: object,
|
|
233
|
+
timestampMs?: number
|
|
234
|
+
): Promise<void>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 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.
|
|
238
|
+
* @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.
|
|
239
|
+
*/
|
|
240
|
+
addTiming(name: string): Promise<void>;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
|
|
244
|
+
|
|
245
|
+
type ResourceKind =
|
|
246
|
+
| 'image'
|
|
247
|
+
| 'xhr'
|
|
248
|
+
| 'beacon'
|
|
249
|
+
| 'css'
|
|
250
|
+
| 'document'
|
|
251
|
+
| 'fetch'
|
|
252
|
+
| 'font'
|
|
253
|
+
| 'js'
|
|
254
|
+
| 'media'
|
|
255
|
+
| 'other'
|
|
256
|
+
| 'native';
|
|
257
|
+
|
|
258
|
+
type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { InternalLog } from '../../InternalLog';
|
|
8
8
|
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
9
9
|
import { DdRum } from '../../foundation';
|
|
10
|
+
import { RumActionType } from '../../types';
|
|
10
11
|
|
|
11
12
|
import type EventsInterceptor from './EventsInterceptor';
|
|
12
13
|
|
|
@@ -46,7 +47,7 @@ export class DdEventsInterceptor implements EventsInterceptor {
|
|
|
46
47
|
private handleTargetEvent(targetNode: any | null) {
|
|
47
48
|
if (targetNode) {
|
|
48
49
|
const resolvedTargetName = this.resolveTargetName(targetNode);
|
|
49
|
-
DdRum.addAction(RumActionType.TAP
|
|
50
|
+
DdRum.addAction(RumActionType.TAP, resolvedTargetName);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -87,19 +88,3 @@ export class DdEventsInterceptor implements EventsInterceptor {
|
|
|
87
88
|
return null;
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Describe the type of a RUM Action.
|
|
93
|
-
*/
|
|
94
|
-
export enum RumActionType {
|
|
95
|
-
/** User tapped on a widget. */
|
|
96
|
-
TAP = 'TAP',
|
|
97
|
-
/** User scrolled a view. */
|
|
98
|
-
SCROLL = 'SCROLL',
|
|
99
|
-
/** User swiped on a view. */
|
|
100
|
-
SWIPE = 'SWIPE',
|
|
101
|
-
/** User clicked on a widget (not used on Mobile). */
|
|
102
|
-
CLICK = 'CLICK',
|
|
103
|
-
/** A custom action. */
|
|
104
|
-
CUSTOM = 'CUSTOM'
|
|
105
|
-
}
|
|
@@ -9,11 +9,10 @@ import type { ErrorHandlerCallback } from 'react-native';
|
|
|
9
9
|
import { InternalLog } from '../../InternalLog';
|
|
10
10
|
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
11
11
|
import { DdRum } from '../../foundation';
|
|
12
|
+
import { ErrorSource } from '../../types';
|
|
12
13
|
|
|
13
14
|
const EMPTY_MESSAGE = 'Unknown Error';
|
|
14
15
|
const EMPTY_STACK_TRACE = '';
|
|
15
|
-
const TYPE_SOURCE = 'SOURCE';
|
|
16
|
-
const TYPE_CONSOLE = 'CONSOLE';
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
@@ -66,7 +65,7 @@ export class DdRumErrorTracking {
|
|
|
66
65
|
static onGlobalError(error: any, isFatal?: boolean): void {
|
|
67
66
|
const message = DdRumErrorTracking.getErrorMessage(error);
|
|
68
67
|
const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
|
|
69
|
-
DdRum.addError(message,
|
|
68
|
+
DdRum.addError(message, ErrorSource.SOURCE, stacktrace, {
|
|
70
69
|
'_dd.error.is_crash': isFatal,
|
|
71
70
|
'_dd.error.raw': error
|
|
72
71
|
}).then(() => {
|
|
@@ -104,7 +103,7 @@ export class DdRumErrorTracking {
|
|
|
104
103
|
})
|
|
105
104
|
.join(' ');
|
|
106
105
|
|
|
107
|
-
DdRum.addError(message,
|
|
106
|
+
DdRum.addError(message, ErrorSource.CONSOLE, stack).then(() => {
|
|
108
107
|
DdRumErrorTracking.defaultConsoleError.apply(console, params);
|
|
109
108
|
});
|
|
110
109
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { firstPartyHostsRegexBuilder } from '../firstPartyHosts';
|
|
8
|
+
|
|
9
|
+
describe('firstPartyHosts', () => {
|
|
10
|
+
describe('firstPartyHostsRegexBuilder', () => {
|
|
11
|
+
it('returns a RegExp that matches hosts', () => {
|
|
12
|
+
const regex = firstPartyHostsRegexBuilder(['api.example.com']);
|
|
13
|
+
expect(regex.test('api.example.com')).toBe(true);
|
|
14
|
+
expect(regex.test('api.myapi.com')).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('escapes special characters in hosts', () => {
|
|
18
|
+
const regex = firstPartyHostsRegexBuilder(['api.example.com']);
|
|
19
|
+
expect(regex.test('apiiexample.com')).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -12,6 +12,11 @@ export type Hostname = { _type: 'Hostname' } & string;
|
|
|
12
12
|
// This regex does not match anything
|
|
13
13
|
export const NO_MATCH_REGEX = new RegExp('a^');
|
|
14
14
|
|
|
15
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
16
|
+
const escapeRegExp = (string: string) => {
|
|
17
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
export const firstPartyHostsRegexBuilder = (
|
|
16
21
|
firstPartyHosts: string[]
|
|
17
22
|
): RegExp => {
|
|
@@ -22,7 +27,9 @@ export const firstPartyHostsRegexBuilder = (
|
|
|
22
27
|
// A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
|
|
23
28
|
// "example.com", "api.example.com", but not "foo.com".
|
|
24
29
|
const firstPartyHostsRegex = new RegExp(
|
|
25
|
-
`^(.*\\.)*(${firstPartyHosts
|
|
30
|
+
`^(.*\\.)*(${firstPartyHosts
|
|
31
|
+
.map(host => `${escapeRegExp(host)}$`)
|
|
32
|
+
.join('|')})`
|
|
26
33
|
);
|
|
27
34
|
firstPartyHostsRegex.test('test_the_regex_is_valid');
|
|
28
35
|
return firstPartyHostsRegex;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { ResourceKind } from '../../../../../../../core/src/types';
|
|
7
8
|
import type { DdRumResourceTracingAttributes } from '../distributedTracing';
|
|
8
9
|
|
|
9
10
|
export interface RUMResource {
|
|
@@ -11,7 +12,7 @@ export interface RUMResource {
|
|
|
11
12
|
request: {
|
|
12
13
|
method: string;
|
|
13
14
|
url: string;
|
|
14
|
-
kind:
|
|
15
|
+
kind: ResourceKind;
|
|
15
16
|
};
|
|
16
17
|
tracingAttributes: DdRumResourceTracingAttributes;
|
|
17
18
|
response: {
|
package/src/types.tsx
CHANGED
|
@@ -143,13 +143,13 @@ export type DdRumType = {
|
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
145
|
* Start tracking a RUM Action.
|
|
146
|
-
* @param type: The action type (tap, scroll, swipe,
|
|
146
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
147
147
|
* @param name: The action name.
|
|
148
148
|
* @param context: The additional context to send.
|
|
149
149
|
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
150
150
|
*/
|
|
151
151
|
startAction(
|
|
152
|
-
type:
|
|
152
|
+
type: RumActionType,
|
|
153
153
|
name: string,
|
|
154
154
|
context?: object,
|
|
155
155
|
timestampMs?: number
|
|
@@ -157,6 +157,24 @@ export type DdRumType = {
|
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Stop tracking the ongoing RUM Action.
|
|
160
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
161
|
+
* @param name: The action name.
|
|
162
|
+
* @param context: The additional context to send.
|
|
163
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
164
|
+
*/
|
|
165
|
+
stopAction(
|
|
166
|
+
type: RumActionType,
|
|
167
|
+
name: string,
|
|
168
|
+
context?: object,
|
|
169
|
+
timestampMs?: number
|
|
170
|
+
): Promise<void>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Stop tracking the ongoing RUM Action.
|
|
174
|
+
*
|
|
175
|
+
* Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.
|
|
176
|
+
*
|
|
177
|
+
* @deprecated add the `type` and `name` of the action as first two arguments.
|
|
160
178
|
* @param context: The additional context to send.
|
|
161
179
|
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
162
180
|
*/
|
|
@@ -164,13 +182,13 @@ export type DdRumType = {
|
|
|
164
182
|
|
|
165
183
|
/**
|
|
166
184
|
* Add a RUM Action.
|
|
167
|
-
* @param type: The action type (tap, scroll, swipe,
|
|
185
|
+
* @param type: The action type (tap, scroll, swipe, back, custom).
|
|
168
186
|
* @param name: The action name.
|
|
169
187
|
* @param context: The additional context to send.
|
|
170
188
|
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
171
189
|
*/
|
|
172
190
|
addAction(
|
|
173
|
-
type:
|
|
191
|
+
type: RumActionType,
|
|
174
192
|
name: string,
|
|
175
193
|
context?: object,
|
|
176
194
|
timestampMs?: number
|
|
@@ -204,7 +222,7 @@ export type DdRumType = {
|
|
|
204
222
|
stopResource(
|
|
205
223
|
key: string,
|
|
206
224
|
statusCode: number,
|
|
207
|
-
kind:
|
|
225
|
+
kind: ResourceKind,
|
|
208
226
|
size?: number,
|
|
209
227
|
context?: object,
|
|
210
228
|
timestampMs?: number
|
|
@@ -213,14 +231,14 @@ export type DdRumType = {
|
|
|
213
231
|
/**
|
|
214
232
|
* Add a RUM Error.
|
|
215
233
|
* @param message: The error message.
|
|
216
|
-
* @param source: The error source (network, source, console,
|
|
234
|
+
* @param source: The error source (network, source, console, webview, custom).
|
|
217
235
|
* @param stacktrace: The error stacktrace.
|
|
218
236
|
* @param context: The additional context to send.
|
|
219
237
|
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
220
238
|
*/
|
|
221
239
|
addError(
|
|
222
240
|
message: string,
|
|
223
|
-
source:
|
|
241
|
+
source: ErrorSource,
|
|
224
242
|
stacktrace: string,
|
|
225
243
|
context?: object,
|
|
226
244
|
timestampMs?: number
|
|
@@ -232,3 +250,40 @@ export type DdRumType = {
|
|
|
232
250
|
*/
|
|
233
251
|
addTiming(name: string): Promise<void>;
|
|
234
252
|
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Describe the type of a RUM Action.
|
|
256
|
+
*/
|
|
257
|
+
export enum RumActionType {
|
|
258
|
+
/** User tapped on a widget. */
|
|
259
|
+
TAP = 'TAP',
|
|
260
|
+
/** User scrolled a view. */
|
|
261
|
+
SCROLL = 'SCROLL',
|
|
262
|
+
/** User swiped on a view. */
|
|
263
|
+
SWIPE = 'SWIPE',
|
|
264
|
+
/** User pressed hardware back button (Android only). */
|
|
265
|
+
BACK = 'BACK',
|
|
266
|
+
/** A custom action. */
|
|
267
|
+
CUSTOM = 'CUSTOM'
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type ResourceKind =
|
|
271
|
+
| 'image'
|
|
272
|
+
| 'xhr'
|
|
273
|
+
| 'beacon'
|
|
274
|
+
| 'css'
|
|
275
|
+
| 'document'
|
|
276
|
+
| 'fetch'
|
|
277
|
+
| 'font'
|
|
278
|
+
| 'js'
|
|
279
|
+
| 'media'
|
|
280
|
+
| 'other'
|
|
281
|
+
| 'native';
|
|
282
|
+
|
|
283
|
+
export enum ErrorSource {
|
|
284
|
+
NETWORK = 'NETWORK',
|
|
285
|
+
SOURCE = 'SOURCE',
|
|
286
|
+
CONSOLE = 'CONSOLE',
|
|
287
|
+
WEBVIEW = 'WEBVIEW',
|
|
288
|
+
CUSTOM = 'CUSTOM'
|
|
289
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.1.1';
|