@datadog/mobile-react-native 1.0.0-rc2 → 1.0.0-rc5

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.
Files changed (108) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +8 -121
  3. package/android/build.gradle +2 -3
  4. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
  5. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
  6. package/ios/Sources/DdRum.m +10 -9
  7. package/ios/Sources/DdRum.swift +24 -24
  8. package/ios/Sources/DdTrace.m +2 -2
  9. package/ios/Sources/DdTrace.swift +6 -6
  10. package/ios/Sources/QueueHolder.swift +1 -1
  11. package/lib/commonjs/DdSdkReactNative.js +63 -0
  12. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js +9 -1
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  15. package/lib/commonjs/InternalLog.js +51 -0
  16. package/lib/commonjs/InternalLog.js.map +1 -0
  17. package/lib/commonjs/ProxyConfiguration.js +53 -0
  18. package/lib/commonjs/ProxyConfiguration.js.map +1 -0
  19. package/lib/commonjs/SdkVerbosity.js +26 -0
  20. package/lib/commonjs/SdkVerbosity.js.map +1 -0
  21. package/lib/commonjs/Timer.js +99 -0
  22. package/lib/commonjs/Timer.js.map +1 -0
  23. package/lib/commonjs/foundation.js +102 -45
  24. package/lib/commonjs/foundation.js.map +1 -1
  25. package/lib/commonjs/index.js +28 -6
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +6 -2
  28. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +61 -14
  30. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +110 -17
  32. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  33. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -4
  34. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  35. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +4 -0
  36. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  37. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  38. package/lib/commonjs/types.js.map +1 -1
  39. package/lib/commonjs/version.js +10 -0
  40. package/lib/commonjs/version.js.map +1 -0
  41. package/lib/module/DdSdkReactNative.js +54 -1
  42. package/lib/module/DdSdkReactNative.js.map +1 -1
  43. package/lib/module/DdSdkReactNativeConfiguration.js +9 -1
  44. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  45. package/lib/module/InternalLog.js +46 -0
  46. package/lib/module/InternalLog.js.map +1 -0
  47. package/lib/module/ProxyConfiguration.js +46 -0
  48. package/lib/module/ProxyConfiguration.js.map +1 -0
  49. package/lib/module/SdkVerbosity.js +18 -0
  50. package/lib/module/SdkVerbosity.js.map +1 -0
  51. package/lib/module/Timer.js +90 -0
  52. package/lib/module/Timer.js.map +1 -0
  53. package/lib/module/foundation.js +69 -44
  54. package/lib/module/foundation.js.map +1 -1
  55. package/lib/module/index.js +3 -1
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +5 -1
  58. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  59. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +56 -14
  60. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  61. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +99 -17
  62. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  63. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +12 -4
  64. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  65. package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
  66. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  67. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  68. package/lib/module/types.js.map +1 -1
  69. package/lib/module/version.js +3 -0
  70. package/lib/module/version.js.map +1 -0
  71. package/lib/typescript/DdSdkReactNative.d.ts +9 -0
  72. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +5 -2
  73. package/lib/typescript/InternalLog.d.ts +6 -0
  74. package/lib/typescript/ProxyConfiguration.d.ts +56 -0
  75. package/lib/typescript/SdkVerbosity.d.ts +9 -0
  76. package/lib/typescript/Timer.d.ts +20 -0
  77. package/lib/typescript/index.d.ts +3 -1
  78. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -0
  79. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
  80. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +2 -2
  81. package/lib/typescript/types.d.ts +12 -11
  82. package/lib/typescript/version.d.ts +1 -0
  83. package/package.json +3 -3
  84. package/src/DdSdkReactNative.tsx +57 -8
  85. package/src/DdSdkReactNativeConfiguration.tsx +6 -3
  86. package/src/InternalLog.tsx +48 -0
  87. package/src/ProxyConfiguration.tsx +37 -0
  88. package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +2 -2
  89. package/src/Timer.ts +96 -0
  90. package/src/__tests__/DdRumWrapper.test.tsx +91 -0
  91. package/src/__tests__/DdSdkReactNative.test.tsx +213 -13
  92. package/src/__tests__/InternalLog.test.tsx +382 -0
  93. package/src/__tests__/Timer.test.ts +145 -0
  94. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +155 -12
  95. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +270 -26
  96. package/src/foundation.tsx +43 -33
  97. package/src/index.tsx +4 -2
  98. package/src/rum/instrumentation/DdRumErrorTracking.tsx +68 -27
  99. package/src/rum/instrumentation/DdRumResourceTracking.tsx +96 -22
  100. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +4 -0
  101. package/src/rum/instrumentation/DdRumXhr.tsx +6 -5
  102. package/src/types.tsx +12 -11
  103. package/src/version.ts +2 -0
  104. package/lib/commonjs/NativeSdkVerbosity.js +0 -26
  105. package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
  106. package/lib/module/NativeSdkVerbosity.js +0 -18
  107. package/lib/module/NativeSdkVerbosity.js.map +0 -1
  108. package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
@@ -0,0 +1,6 @@
1
+ import { SdkVerbosity } from './SdkVerbosity';
2
+ export declare class InternalLog {
3
+ private static levelMap;
4
+ static verbosity: SdkVerbosity | undefined;
5
+ static log(message: string, verbosity: SdkVerbosity): void;
6
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Proxy server configuration.
3
+ */
4
+ declare class ProxyConfiguration {
5
+ /**
6
+ * Proxy type.
7
+ */
8
+ readonly type: ProxyType;
9
+ /**
10
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
11
+ */
12
+ readonly address: string;
13
+ /**
14
+ * Proxy port.
15
+ */
16
+ readonly port: number;
17
+ /**
18
+ * Username for Basic authentication scheme.
19
+ *
20
+ * Note: "SOCKS + authentication" scheme is not supported.
21
+ */
22
+ readonly username?: string | undefined;
23
+ /**
24
+ * Password for Basic authentication scheme.
25
+ */
26
+ readonly password?: string | undefined;
27
+ constructor(
28
+ /**
29
+ * Proxy type.
30
+ */
31
+ type: ProxyType,
32
+ /**
33
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
34
+ */
35
+ address: string,
36
+ /**
37
+ * Proxy port.
38
+ */
39
+ port: number,
40
+ /**
41
+ * Username for Basic authentication scheme.
42
+ *
43
+ * Note: "SOCKS + authentication" scheme is not supported.
44
+ */
45
+ username?: string | undefined,
46
+ /**
47
+ * Password for Basic authentication scheme.
48
+ */
49
+ password?: string | undefined);
50
+ }
51
+ declare enum ProxyType {
52
+ HTTP = "http",
53
+ HTTPS = "https",
54
+ SOCKS = "socks"
55
+ }
56
+ export { ProxyConfiguration, ProxyType };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Enum specifying possible log levels for DD SDK.
3
+ */
4
+ export declare enum SdkVerbosity {
5
+ DEBUG = "debug",
6
+ INFO = "info",
7
+ WARN = "warn",
8
+ ERROR = "error"
9
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Simple timer which records time ticks. Shouldn't be re-used once stopped.
3
+ * All timestamps/durations returned are in milliseconds.
4
+ */
5
+ export default class Timer {
6
+ private times;
7
+ get startTime(): number;
8
+ get stopTime(): number;
9
+ start(): void;
10
+ stop(): void;
11
+ recordTick(label: string): void;
12
+ hasTickFor(label: string): boolean;
13
+ durationBetween(startLabel: string, endLabel: string): number;
14
+ timeAt(label: string): number;
15
+ reset(): void;
16
+ private durationBetweenTicks;
17
+ private performanceNow;
18
+ private canUsePerformanceNow;
19
+ private checkLabelExists;
20
+ }
@@ -1,5 +1,7 @@
1
1
  import { DdLogs, DdTrace, DdRum } from './foundation';
2
2
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import { DdSdkReactNative } from './DdSdkReactNative';
4
+ import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
4
5
  import { TrackingConsent } from './TrackingConsent';
5
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, TrackingConsent };
6
+ import { SdkVerbosity } from './SdkVerbosity';
7
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export declare class DdRumErrorTracking {
5
5
  private static isTracking;
6
+ private static isInDefaultErrorHandler;
6
7
  private static defaultErrorHandler;
7
8
  private static defaultConsoleError;
8
9
  /**
@@ -11,5 +12,6 @@ export declare class DdRumErrorTracking {
11
12
  static startTracking(): void;
12
13
  static onGlobalError(error: any, isFatal?: boolean): void;
13
14
  static onConsoleError(...params: unknown[]): void;
15
+ private static getErrorMessage;
14
16
  private static getErrorStackTrace;
15
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
  */
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react-native" />
2
+ import type Timer from "../../Timer";
2
3
  export interface DdRumXhr extends XMLHttpRequest {
3
4
  _datadog_xhr: DdRumXhrContext;
4
5
  }
5
6
  export interface DdRumXhrContext {
6
7
  method: string;
7
8
  url: string;
8
- startTime: number;
9
- responseStartTime: number;
10
9
  reported: boolean;
10
+ timer: Timer;
11
11
  spanId: string;
12
12
  traceId: string;
13
13
  }
@@ -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-rc5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "1.0.0-rc2",
3
+ "version": "1.0.0-rc5",
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": "^0.63.4"
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": "ed6e0566e2096406ba393ecd03ba8ac964ba8b9b"
71
+ "gitHead": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
72
72
  }
@@ -4,13 +4,17 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type { DdSdkReactNativeConfiguration } from "./DdSdkReactNativeConfiguration"
8
- import { DdSdkConfiguration } from "./types"
9
- import { DdSdk } from "./foundation"
10
- import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking'
11
- import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking'
12
- import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking'
13
- import type { TrackingConsent } from "./TrackingConsent"
7
+ import type {DdSdkReactNativeConfiguration} from "./DdSdkReactNativeConfiguration"
8
+ import {DdSdkConfiguration} from "./types"
9
+ import {DdSdk} from "./foundation"
10
+ import {DdRumUserInteractionTracking} from './rum/instrumentation/DdRumUserInteractionTracking'
11
+ import {DdRumErrorTracking} from './rum/instrumentation/DdRumErrorTracking'
12
+ import {DdRumResourceTracking} from './rum/instrumentation/DdRumResourceTracking'
13
+ import type {TrackingConsent} from "./TrackingConsent"
14
+ import {ProxyType} from "./ProxyConfiguration"
15
+ import {version as sdkVersion} from './version';
16
+ import {InternalLog} from "./InternalLog"
17
+ import {SdkVerbosity} from "./SdkVerbosity";
14
18
 
15
19
  /**
16
20
  * This class initializes the Datadog SDK, and sets up communication with the server.
@@ -18,9 +22,22 @@ import type { TrackingConsent } from "./TrackingConsent"
18
22
  export class DdSdkReactNative {
19
23
 
20
24
  private static readonly DD_SOURCE_KEY = "_dd.source";
25
+ private static readonly DD_SDK_VERSION = "_dd.sdk_version";
26
+ private static readonly DD_SERVICE_NAME = "_dd.service_name";
21
27
  private static readonly DD_SDK_VERBOSITY_KEY = "_dd.sdk_verbosity";
22
28
  private static readonly DD_NATIVE_VIEW_TRACKING_KEY = "_dd.native_view_tracking";
23
29
 
30
+ // Proxy
31
+ private static readonly DD_PROXY_TYPE_KEY = "_dd.proxy.type";
32
+ private static readonly DD_PROXY_ADDRESS_KEY = "_dd.proxy.address";
33
+ private static readonly DD_PROXY_PORT_KEY = "_dd.proxy.port";
34
+ private static readonly DD_PROXY_USERNAME_KEY = "_dd.proxy.username";
35
+ private static readonly DD_PROXY_PASSWORD_KEY = "_dd.proxy.password";
36
+
37
+ private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = "_dd.long_task.threshold"
38
+ private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200
39
+
40
+
24
41
  private static wasInitialized = false
25
42
 
26
43
  /**
@@ -31,16 +48,44 @@ export class DdSdkReactNative {
31
48
  static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void> {
32
49
  return new Promise<void>((resolve, reject) => {
33
50
  if (DdSdkReactNative.wasInitialized) {
51
+ InternalLog.log("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
34
52
  resolve()
35
53
  return
36
54
  }
37
55
 
56
+ InternalLog.verbosity = configuration.verbosity
57
+
38
58
  configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
59
+ configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
39
60
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
40
61
  if (configuration.verbosity != undefined) {
41
- configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity
62
+ configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
63
+ }
64
+
65
+ if (configuration.proxyConfig) {
66
+ const additionalConfig = configuration.additionalConfig;
67
+ const proxyConfig = configuration.proxyConfig;
68
+
69
+ additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
70
+ additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
71
+ additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
72
+ if (proxyConfig.username && proxyConfig.password) {
73
+ if (proxyConfig.type == ProxyType.SOCKS) {
74
+ console.warn("SOCKS proxy configuration doesn't support Basic authentication.")
75
+ } else {
76
+ additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
77
+ additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
78
+ }
79
+ }
42
80
  }
43
81
 
82
+ if (configuration.serviceName) {
83
+ configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
84
+ }
85
+
86
+ configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY]
87
+ = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS
88
+
44
89
  DdSdk.initialize(
45
90
  new DdSdkConfiguration(
46
91
  configuration.clientToken,
@@ -53,6 +98,7 @@ export class DdSdkReactNative {
53
98
  configuration.additionalConfig
54
99
  )
55
100
  ).then(() => {
101
+ InternalLog.log("Datadog SDK was initialized", SdkVerbosity.INFO);
56
102
  DdSdkReactNative.enableFeatures(configuration)
57
103
  DdSdkReactNative.wasInitialized = true
58
104
  resolve()
@@ -69,6 +115,7 @@ export class DdSdkReactNative {
69
115
  */
70
116
  // eslint-disable-next-line @typescript-eslint/ban-types
71
117
  static setAttributes(attributes: object): Promise<void> {
118
+ InternalLog.log("Setting attributes " + JSON.stringify(attributes), SdkVerbosity.DEBUG);
72
119
  return DdSdk.setAttributes(attributes)
73
120
  }
74
121
 
@@ -79,6 +126,7 @@ export class DdSdkReactNative {
79
126
  */
80
127
  // eslint-disable-next-line @typescript-eslint/ban-types
81
128
  static setUser(user: object): Promise<void> {
129
+ InternalLog.log("Setting user " + JSON.stringify(user), SdkVerbosity.DEBUG);
82
130
  return DdSdk.setUser(user)
83
131
  }
84
132
 
@@ -88,6 +136,7 @@ export class DdSdkReactNative {
88
136
  * @returns a Promise.
89
137
  */
90
138
  static setTrackingConsent(consent: TrackingConsent): Promise<void> {
139
+ InternalLog.log("Setting consent " + consent, SdkVerbosity.DEBUG);
91
140
  return DdSdk.setTrackingConsent(consent)
92
141
  }
93
142
 
@@ -5,7 +5,8 @@
5
5
  */
6
6
 
7
7
  import { TrackingConsent } from './TrackingConsent'
8
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity'
8
+ import type { SdkVerbosity } from './SdkVerbosity'
9
+ import type { ProxyConfiguration } from './ProxyConfiguration';
9
10
 
10
11
  /**
11
12
  * The SDK configuration class.
@@ -16,9 +17,11 @@ export class DdSdkReactNativeConfiguration {
16
17
  public nativeCrashReportEnabled: boolean = false;
17
18
  public sampleRate: number = 100.0;
18
19
  public site: string = "US"
19
- public verbosity: NativeSdkVerbosity|undefined = undefined
20
+ public verbosity: SdkVerbosity|undefined = undefined
20
21
  public nativeViewTracking: boolean = false
21
-
22
+ public proxyConfig?: ProxyConfiguration = undefined
23
+ public serviceName?: string = undefined
24
+
22
25
  public additionalConfig: {[k: string]: any} = {};
23
26
 
24
27
  constructor(
@@ -0,0 +1,48 @@
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 {SdkVerbosity} from './SdkVerbosity'
8
+
9
+ export class InternalLog {
10
+
11
+ private static levelMap = new Map<SdkVerbosity, number>([
12
+ [SdkVerbosity.DEBUG, 1],
13
+ [SdkVerbosity.INFO, 2],
14
+ [SdkVerbosity.WARN, 3],
15
+ [SdkVerbosity.ERROR, 4]
16
+ ]);
17
+
18
+ public static verbosity: SdkVerbosity|undefined = undefined
19
+
20
+ public static log (message: string, verbosity: SdkVerbosity): void {
21
+ if (InternalLog.verbosity === undefined) {
22
+ return;
23
+ }
24
+ const requiredLevel = InternalLog.levelMap.get(verbosity);
25
+ const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
26
+ if (allowedLevel === undefined || requiredLevel === undefined) {
27
+ return;
28
+ }
29
+ const prefixedMessage = "DATADOG: " + message
30
+ if (verbosity == SdkVerbosity.ERROR && (requiredLevel >= allowedLevel)) {
31
+ console.error(prefixedMessage)
32
+ }
33
+
34
+ if (verbosity == SdkVerbosity.WARN && (requiredLevel >= allowedLevel)) {
35
+ console.warn(prefixedMessage)
36
+ }
37
+
38
+ if (verbosity == SdkVerbosity.INFO && (requiredLevel >= allowedLevel)) {
39
+ console.info(prefixedMessage)
40
+ }
41
+
42
+ if (verbosity == SdkVerbosity.DEBUG && (requiredLevel >= allowedLevel)) {
43
+ console.debug(prefixedMessage)
44
+ }
45
+ }
46
+
47
+
48
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Proxy server configuration.
3
+ */
4
+ class ProxyConfiguration {
5
+ constructor(
6
+ /**
7
+ * Proxy type.
8
+ */
9
+ readonly type: ProxyType,
10
+ /**
11
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
12
+ */
13
+ readonly address: string,
14
+ /**
15
+ * Proxy port.
16
+ */
17
+ readonly port: number,
18
+ /**
19
+ * Username for Basic authentication scheme.
20
+ *
21
+ * Note: "SOCKS + authentication" scheme is not supported.
22
+ */
23
+ readonly username?: string,
24
+ /**
25
+ * Password for Basic authentication scheme.
26
+ */
27
+ readonly password?: string
28
+ ) { }
29
+ }
30
+
31
+ enum ProxyType {
32
+ HTTP = "http",
33
+ HTTPS = "https",
34
+ SOCKS = "socks"
35
+ }
36
+
37
+ export { ProxyConfiguration, ProxyType }
@@ -5,9 +5,9 @@
5
5
  */
6
6
 
7
7
  /**
8
- * Enum specifying possible consent options for DD SDK.
8
+ * Enum specifying possible log levels for DD SDK.
9
9
  */
10
- export enum NativeSdkVerbosity {
10
+ export enum SdkVerbosity {
11
11
  DEBUG = "debug",
12
12
  INFO = "info",
13
13
  WARN = "warn",
package/src/Timer.ts ADDED
@@ -0,0 +1,96 @@
1
+ type Timestamp = {
2
+ // Result of Date API. Unix timestamp in ms.
3
+ unix: number,
4
+ // Result of performance.now API. Timestamp in ms (with microsecond precision)
5
+ // since JS context start.
6
+ react_native: number | null
7
+ }
8
+
9
+ const START_LABEL = "__start"
10
+ const STOP_LABEL = "__stop"
11
+
12
+ /**
13
+ * Simple timer which records time ticks. Shouldn't be re-used once stopped.
14
+ * All timestamps/durations returned are in milliseconds.
15
+ */
16
+ export default class Timer {
17
+
18
+ private times: Record<string, Timestamp> = {};
19
+
20
+ get startTime(): number {
21
+ return this.times[START_LABEL].unix
22
+ }
23
+
24
+ get stopTime(): number {
25
+ return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL)
26
+ }
27
+
28
+ start(): void {
29
+ this.recordTick(START_LABEL);
30
+ }
31
+
32
+ stop(): void {
33
+ this.recordTick(STOP_LABEL)
34
+ }
35
+
36
+ recordTick(label: string): void {
37
+ this.times[label] = {
38
+ unix: Date.now(),
39
+ react_native: this.performanceNow()
40
+ }
41
+ }
42
+
43
+ hasTickFor(label: string): boolean {
44
+ return label in this.times;
45
+ }
46
+
47
+ durationBetween(startLabel: string, endLabel: string): number {
48
+ this.checkLabelExists(startLabel);
49
+ this.checkLabelExists(endLabel);
50
+
51
+ const startTick = this.times[startLabel];
52
+ const endTick = this.times[endLabel];
53
+
54
+ return this.durationBetweenTicks(startTick, endTick);
55
+ }
56
+
57
+ timeAt(label: string): number {
58
+ this.checkLabelExists(label);
59
+
60
+ return this.startTime + this.durationBetween(START_LABEL, label)
61
+ }
62
+
63
+ reset(): void {
64
+ this.times = {};
65
+ }
66
+
67
+ private durationBetweenTicks(start: Timestamp, end: Timestamp): number {
68
+ if (start.react_native != null && end.react_native != null) {
69
+ return end.react_native - start.react_native;
70
+ }
71
+ return end.unix - start.unix;
72
+ }
73
+
74
+
75
+ private performanceNow(): number | null {
76
+ if (this.canUsePerformanceNow()) {
77
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
78
+ // @ts-ignore
79
+ return performance.now();
80
+ }
81
+ return null;
82
+ }
83
+
84
+ private canUsePerformanceNow(): boolean {
85
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
86
+ // @ts-ignore
87
+ return global.performance && typeof performance.now === 'function';
88
+ }
89
+
90
+ private checkLabelExists(label: string) {
91
+ if (!this.hasTickFor(label)) {
92
+ throw new Error(`Label ${label} is not registered`);
93
+ }
94
+ }
95
+
96
+ }