@datadog/mobile-react-native 1.0.0-rc4 → 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 (77) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +4 -2
  3. package/android/build.gradle +1 -1
  4. package/lib/commonjs/DdSdkReactNative.js +15 -0
  5. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  6. package/lib/commonjs/DdSdkReactNativeConfiguration.js +5 -1
  7. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  8. package/lib/commonjs/InternalLog.js +51 -0
  9. package/lib/commonjs/InternalLog.js.map +1 -0
  10. package/lib/commonjs/SdkVerbosity.js +26 -0
  11. package/lib/commonjs/SdkVerbosity.js.map +1 -0
  12. package/lib/commonjs/foundation.js +91 -16
  13. package/lib/commonjs/foundation.js.map +1 -1
  14. package/lib/commonjs/index.js +14 -6
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +6 -2
  17. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  18. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +29 -14
  19. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  20. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +9 -1
  21. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  22. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -4
  23. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +4 -0
  25. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  26. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  27. package/lib/commonjs/version.js +1 -1
  28. package/lib/commonjs/version.js.map +1 -1
  29. package/lib/module/DdSdkReactNative.js +8 -0
  30. package/lib/module/DdSdkReactNative.js.map +1 -1
  31. package/lib/module/DdSdkReactNativeConfiguration.js +5 -1
  32. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  33. package/lib/module/InternalLog.js +46 -0
  34. package/lib/module/InternalLog.js.map +1 -0
  35. package/lib/module/SdkVerbosity.js +18 -0
  36. package/lib/module/SdkVerbosity.js.map +1 -0
  37. package/lib/module/foundation.js +58 -15
  38. package/lib/module/foundation.js.map +1 -1
  39. package/lib/module/index.js +2 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +5 -1
  42. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  43. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +25 -14
  44. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  45. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +4 -0
  46. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  47. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +12 -4
  48. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  49. package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
  50. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  51. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  52. package/lib/module/version.js +1 -1
  53. package/lib/module/version.js.map +1 -1
  54. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +2 -2
  55. package/lib/typescript/InternalLog.d.ts +6 -0
  56. package/lib/typescript/SdkVerbosity.d.ts +9 -0
  57. package/lib/typescript/index.d.ts +2 -1
  58. package/lib/typescript/version.d.ts +1 -1
  59. package/package.json +2 -2
  60. package/src/DdSdkReactNative.tsx +18 -10
  61. package/src/DdSdkReactNativeConfiguration.tsx +3 -3
  62. package/src/InternalLog.tsx +48 -0
  63. package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +2 -2
  64. package/src/__tests__/DdSdkReactNative.test.tsx +3 -3
  65. package/src/__tests__/InternalLog.test.tsx +382 -0
  66. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +21 -0
  67. package/src/foundation.tsx +77 -61
  68. package/src/index.tsx +2 -1
  69. package/src/rum/instrumentation/DdRumErrorTracking.tsx +20 -13
  70. package/src/rum/instrumentation/DdRumResourceTracking.tsx +6 -2
  71. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +4 -0
  72. package/src/version.ts +1 -1
  73. package/lib/commonjs/NativeSdkVerbosity.js +0 -26
  74. package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
  75. package/lib/module/NativeSdkVerbosity.js +0 -18
  76. package/lib/module/NativeSdkVerbosity.js.map +0 -1
  77. package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
@@ -1,5 +1,5 @@
1
1
  import { TrackingConsent } from './TrackingConsent';
2
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
2
+ import type { SdkVerbosity } from './SdkVerbosity';
3
3
  import type { ProxyConfiguration } from './ProxyConfiguration';
4
4
  /**
5
5
  * The SDK configuration class.
@@ -16,7 +16,7 @@ export declare class DdSdkReactNativeConfiguration {
16
16
  nativeCrashReportEnabled: boolean;
17
17
  sampleRate: number;
18
18
  site: string;
19
- verbosity: NativeSdkVerbosity | undefined;
19
+ verbosity: SdkVerbosity | undefined;
20
20
  nativeViewTracking: boolean;
21
21
  proxyConfig?: ProxyConfiguration;
22
22
  serviceName?: string;
@@ -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,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
+ }
@@ -3,4 +3,5 @@ import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import { DdSdkReactNative } from './DdSdkReactNative';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
5
5
  import { TrackingConsent } from './TrackingConsent';
6
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent };
6
+ import { SdkVerbosity } from './SdkVerbosity';
7
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc4";
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-rc4",
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",
@@ -68,5 +68,5 @@
68
68
  ]
69
69
  ]
70
70
  },
71
- "gitHead": "c1bd4e6ded0b84298ca011eba679027ae7fe7841"
71
+ "gitHead": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
72
72
  }
@@ -4,16 +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"
14
- import { ProxyType } from "./ProxyConfiguration"
15
-
16
- import {version as sdkVersion } from './version';
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";
17
18
 
18
19
  /**
19
20
  * This class initializes the Datadog SDK, and sets up communication with the server.
@@ -47,10 +48,13 @@ export class DdSdkReactNative {
47
48
  static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void> {
48
49
  return new Promise<void>((resolve, reject) => {
49
50
  if (DdSdkReactNative.wasInitialized) {
51
+ InternalLog.log("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
50
52
  resolve()
51
53
  return
52
54
  }
53
55
 
56
+ InternalLog.verbosity = configuration.verbosity
57
+
54
58
  configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
55
59
  configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
56
60
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
@@ -94,6 +98,7 @@ export class DdSdkReactNative {
94
98
  configuration.additionalConfig
95
99
  )
96
100
  ).then(() => {
101
+ InternalLog.log("Datadog SDK was initialized", SdkVerbosity.INFO);
97
102
  DdSdkReactNative.enableFeatures(configuration)
98
103
  DdSdkReactNative.wasInitialized = true
99
104
  resolve()
@@ -110,6 +115,7 @@ export class DdSdkReactNative {
110
115
  */
111
116
  // eslint-disable-next-line @typescript-eslint/ban-types
112
117
  static setAttributes(attributes: object): Promise<void> {
118
+ InternalLog.log("Setting attributes " + JSON.stringify(attributes), SdkVerbosity.DEBUG);
113
119
  return DdSdk.setAttributes(attributes)
114
120
  }
115
121
 
@@ -120,6 +126,7 @@ export class DdSdkReactNative {
120
126
  */
121
127
  // eslint-disable-next-line @typescript-eslint/ban-types
122
128
  static setUser(user: object): Promise<void> {
129
+ InternalLog.log("Setting user " + JSON.stringify(user), SdkVerbosity.DEBUG);
123
130
  return DdSdk.setUser(user)
124
131
  }
125
132
 
@@ -129,6 +136,7 @@ export class DdSdkReactNative {
129
136
  * @returns a Promise.
130
137
  */
131
138
  static setTrackingConsent(consent: TrackingConsent): Promise<void> {
139
+ InternalLog.log("Setting consent " + consent, SdkVerbosity.DEBUG);
132
140
  return DdSdk.setTrackingConsent(consent)
133
141
  }
134
142
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { TrackingConsent } from './TrackingConsent'
8
- import type { NativeSdkVerbosity } from './NativeSdkVerbosity'
8
+ import type { SdkVerbosity } from './SdkVerbosity'
9
9
  import type { ProxyConfiguration } from './ProxyConfiguration';
10
10
 
11
11
  /**
@@ -17,11 +17,11 @@ export class DdSdkReactNativeConfiguration {
17
17
  public nativeCrashReportEnabled: boolean = false;
18
18
  public sampleRate: number = 100.0;
19
19
  public site: string = "US"
20
- public verbosity: NativeSdkVerbosity|undefined = undefined
20
+ public verbosity: SdkVerbosity|undefined = undefined
21
21
  public nativeViewTracking: boolean = false
22
22
  public proxyConfig?: ProxyConfiguration = undefined
23
23
  public serviceName?: string = undefined
24
-
24
+
25
25
  public additionalConfig: {[k: string]: any} = {};
26
26
 
27
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
+ }
@@ -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",
@@ -13,7 +13,7 @@ import { DdRumUserInteractionTracking } from '../rum/instrumentation/DdRumUserIn
13
13
  import { DdRumResourceTracking } from '../rum/instrumentation/DdRumResourceTracking'
14
14
  import { DdRumErrorTracking } from '../rum/instrumentation/DdRumErrorTracking'
15
15
  import { TrackingConsent } from '../TrackingConsent'
16
- import { NativeSdkVerbosity } from '../NativeSdkVerbosity'
16
+ import { SdkVerbosity } from '../SdkVerbosity'
17
17
  import { ProxyType } from '../ProxyConfiguration'
18
18
 
19
19
  import { version as sdkVersion } from '../version';
@@ -301,7 +301,7 @@ it('M enable sdk verbosity W initialize { sdk verbosity }', async () => {
301
301
  const fakeClientToken = "2"
302
302
  const fakeEnvName = "env"
303
303
  const configuration = new DdSdkReactNativeConfiguration(fakeClientToken, fakeEnvName, fakeAppId, false, false, true)
304
- configuration.verbosity = NativeSdkVerbosity.DEBUG
304
+ configuration.verbosity = SdkVerbosity.DEBUG
305
305
 
306
306
  NativeModules.DdSdk.initialize.mockResolvedValue(null)
307
307
 
@@ -317,7 +317,7 @@ it('M enable sdk verbosity W initialize { sdk verbosity }', async () => {
317
317
  expect(ddSdkConfiguration.additionalConfig).toStrictEqual({
318
318
  '_dd.source': 'react-native',
319
319
  '_dd.sdk_version': sdkVersion,
320
- '_dd.sdk_verbosity': NativeSdkVerbosity.DEBUG,
320
+ '_dd.sdk_verbosity': SdkVerbosity.DEBUG,
321
321
  '_dd.native_view_tracking': false,
322
322
  '_dd.long_task.threshold': 200
323
323
  })
@@ -0,0 +1,382 @@
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
+ import {SdkVerbosity} from '../SdkVerbosity'
9
+ import {InternalLog} from '../InternalLog'
10
+
11
+ let baseConsoleDebugCalled = false;
12
+ let baseConsoleDebugArg = undefined;
13
+ let baseConsoleDebug = (...params: unknown) => {
14
+ baseConsoleDebugCalled = true;
15
+ baseConsoleDebugArg = params;
16
+ }
17
+ let originalConsoleDebug = undefined
18
+
19
+ let baseConsoleInfoCalled = false;
20
+ let baseConsoleInfoArg = undefined;
21
+ let baseConsoleInfo = (...params: unknown) => {
22
+ baseConsoleInfoCalled = true;
23
+ baseConsoleInfoArg = params;
24
+ }
25
+ let originalConsoleInfo = undefined
26
+
27
+ let baseConsoleWarnCalled = false;
28
+ let baseConsoleWarnArg = undefined;
29
+ let baseConsoleWarn = (...params: unknown) => {
30
+ baseConsoleWarnCalled = true;
31
+ baseConsoleWarnArg = params;
32
+ }
33
+ let originalConsoleWarn = undefined
34
+
35
+ let baseConsoleErrorCalled = false;
36
+ let baseConsoleErrorArg = undefined;
37
+ let baseConsoleError = (...params: unknown) => {
38
+ baseConsoleErrorCalled = true;
39
+ baseConsoleErrorArg = params;
40
+ }
41
+ let originalConsoleError = undefined
42
+
43
+
44
+ beforeEach(() => {
45
+ baseConsoleDebugCalled = false;
46
+ baseConsoleInfoCalled = false;
47
+ baseConsoleWarnCalled = false;
48
+ baseConsoleErrorCalled = false;
49
+
50
+ baseConsoleDebugArg = undefined;
51
+ baseConsoleInfoArg = undefined;
52
+ baseConsoleWarnArg = undefined;
53
+ baseConsoleErrorArg = undefined;
54
+
55
+ originalConsoleDebug = console.debug;
56
+ originalConsoleInfo = console.info;
57
+ originalConsoleWarn = console.warn;
58
+ originalConsoleError = console.error;
59
+
60
+ console.debug = baseConsoleDebug;
61
+ console.info = baseConsoleInfo;
62
+ console.warn = baseConsoleWarn;
63
+ console.error = baseConsoleError;
64
+ })
65
+
66
+ afterEach(() => {
67
+ console.debug = originalConsoleDebug
68
+ console.info = originalConsoleInfo
69
+ console.warn = originalConsoleWarn
70
+ console.error = originalConsoleError
71
+ })
72
+
73
+ it('M output debug W log(debug) (DEBUG+ allowed)', async () => {
74
+ // GIVEN
75
+ const message = "log(debug) (DEBUG+ allowed)"
76
+ InternalLog.verbosity = SdkVerbosity.DEBUG
77
+
78
+ // WHEN
79
+ InternalLog.log(message, SdkVerbosity.DEBUG)
80
+
81
+ // THEN
82
+ expect(baseConsoleDebugCalled).toStrictEqual(true);
83
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
84
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
85
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
86
+ expect(baseConsoleDebugArg).toStrictEqual(["DATADOG: " + message]);
87
+ })
88
+
89
+ it('M output info W log(info) (DEBUG+ allowed)', async () => {
90
+ // GIVEN
91
+ const message = "log(info) (DEBUG+ allowed)"
92
+ InternalLog.verbosity = SdkVerbosity.DEBUG
93
+
94
+ // WHEN
95
+ InternalLog.log(message, SdkVerbosity.INFO)
96
+
97
+ // THEN
98
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
99
+ expect(baseConsoleInfoCalled).toStrictEqual(true);
100
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
101
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
102
+ expect(baseConsoleInfoArg).toStrictEqual(["DATADOG: " + message]);
103
+ })
104
+
105
+ it('M output warn W log(warn) (DEBUG+ allowed)', async () => {
106
+ // GIVEN
107
+ const message = "log(warn) (DEBUG+ allowed)"
108
+ InternalLog.verbosity = SdkVerbosity.DEBUG
109
+
110
+ // WHEN
111
+ InternalLog.log(message, SdkVerbosity.WARN)
112
+
113
+ // THEN
114
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
115
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
116
+ expect(baseConsoleWarnCalled).toStrictEqual(true);
117
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
118
+ expect(baseConsoleWarnArg).toStrictEqual(["DATADOG: " + message]);
119
+ })
120
+
121
+ it('M output error W log(error) (DEBUG+ allowed)', async () => {
122
+ // GIVEN
123
+ const message = "log(error) (DEBUG+ allowed)"
124
+ InternalLog.verbosity = SdkVerbosity.DEBUG
125
+
126
+ // WHEN
127
+ InternalLog.log(message, SdkVerbosity.ERROR)
128
+
129
+ // THEN
130
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
131
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
132
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
133
+ expect(baseConsoleErrorCalled).toStrictEqual(true);
134
+ expect(baseConsoleErrorArg).toStrictEqual(["DATADOG: " + message]);
135
+ })
136
+
137
+ it('M not output debug W log(debug) (INFO+ allowed)', async () => {
138
+ // GIVEN
139
+ const message = "log(debug) (INFO+ allowed)"
140
+ InternalLog.verbosity = SdkVerbosity.INFO
141
+
142
+ // WHEN
143
+ InternalLog.log(message, SdkVerbosity.DEBUG)
144
+
145
+ // THEN
146
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
147
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
148
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
149
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
150
+ })
151
+
152
+ it('M output info W log(info) (INFO+ allowed)', async () => {
153
+ // GIVEN
154
+ const message = "log(info) (INFO+ allowed)"
155
+ InternalLog.verbosity = SdkVerbosity.INFO
156
+
157
+ // WHEN
158
+ InternalLog.log(message, SdkVerbosity.INFO)
159
+
160
+ // THEN
161
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
162
+ expect(baseConsoleInfoCalled).toStrictEqual(true);
163
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
164
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
165
+ expect(baseConsoleInfoArg).toStrictEqual(["DATADOG: " + message]);
166
+ })
167
+
168
+ it('M output warn W log(warn) (INFO+ allowed)', async () => {
169
+ // GIVEN
170
+ const message = "log(warn) (INFO+ allowed)"
171
+ InternalLog.verbosity = SdkVerbosity.INFO
172
+
173
+ // WHEN
174
+ InternalLog.log(message, SdkVerbosity.WARN)
175
+
176
+ // THEN
177
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
178
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
179
+ expect(baseConsoleWarnCalled).toStrictEqual(true);
180
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
181
+ expect(baseConsoleWarnArg).toStrictEqual(["DATADOG: " + message]);
182
+ })
183
+
184
+ it('M output error W log(error) (INFO+ allowed)', async () => {
185
+ // GIVEN
186
+ const message = "log(error) (INFO+ allowed)"
187
+ InternalLog.verbosity = SdkVerbosity.INFO
188
+
189
+ // WHEN
190
+ InternalLog.log(message, SdkVerbosity.ERROR)
191
+
192
+ // THEN
193
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
194
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
195
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
196
+ expect(baseConsoleErrorCalled).toStrictEqual(true);
197
+ expect(baseConsoleErrorArg).toStrictEqual(["DATADOG: " + message]);
198
+ })
199
+
200
+ it('M not output debug W log(debug) (WARN+ allowed)', async () => {
201
+ // GIVEN
202
+ const message = "log(debug) (WARN+ allowed)"
203
+ InternalLog.verbosity = SdkVerbosity.WARN
204
+
205
+ // WHEN
206
+ InternalLog.log(message, SdkVerbosity.DEBUG)
207
+
208
+ // THEN
209
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
210
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
211
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
212
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
213
+ })
214
+
215
+ it('M not output info W log(info) (WARN+ allowed)', async () => {
216
+ // GIVEN
217
+ const message = "log(info) (WARN+ allowed)"
218
+ InternalLog.verbosity = SdkVerbosity.WARN
219
+
220
+ // WHEN
221
+ InternalLog.log(message, SdkVerbosity.INFO)
222
+
223
+ // THEN
224
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
225
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
226
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
227
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
228
+ })
229
+
230
+ it('M output warn W log(warn) (WARN+ allowed)', async () => {
231
+ // GIVEN
232
+ const message = "log(warn) (WARN+ allowed)"
233
+ InternalLog.verbosity = SdkVerbosity.WARN
234
+
235
+
236
+ // WHEN
237
+ InternalLog.log(message, SdkVerbosity.WARN)
238
+
239
+ // THEN
240
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
241
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
242
+ expect(baseConsoleWarnCalled).toStrictEqual(true);
243
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
244
+ expect(baseConsoleWarnArg).toStrictEqual(["DATADOG: " + message]);
245
+ })
246
+
247
+ it('M output error W log(error) (WARN+ allowed)', async () => {
248
+ // GIVEN
249
+ const message = "log(error) (WARN+ allowed)"
250
+ InternalLog.verbosity = SdkVerbosity.WARN
251
+
252
+ // WHEN
253
+ InternalLog.log(message, SdkVerbosity.ERROR)
254
+
255
+ // THEN
256
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
257
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
258
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
259
+ expect(baseConsoleErrorCalled).toStrictEqual(true);
260
+ expect(baseConsoleErrorArg).toStrictEqual(["DATADOG: " + message]);
261
+ })
262
+
263
+ it('M not output debug W log(debug) (ERROR+ allowed)', async () => {
264
+ // GIVEN
265
+ const message = "log(debug) (ERROR+ allowed)"
266
+ InternalLog.verbosity = SdkVerbosity.ERROR
267
+
268
+ // WHEN
269
+ InternalLog.log(message, SdkVerbosity.DEBUG)
270
+
271
+ // THEN
272
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
273
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
274
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
275
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
276
+ })
277
+
278
+ it('M not output info W log(info) (ERROR+ allowed)', async () => {
279
+ // GIVEN
280
+ const message = "log(info) (ERROR+ allowed)"
281
+ InternalLog.verbosity = SdkVerbosity.ERROR
282
+
283
+ // WHEN
284
+ InternalLog.log(message, SdkVerbosity.INFO)
285
+
286
+ // THEN
287
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
288
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
289
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
290
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
291
+ })
292
+
293
+ it('M not output warn W log(warn) (ERROR+ allowed)', async () => {
294
+ // GIVEN
295
+ const message = "log(warn) (ERROR+ allowed)"
296
+ InternalLog.verbosity = SdkVerbosity.ERROR
297
+
298
+ // WHEN
299
+ InternalLog.log(message, SdkVerbosity.WARN)
300
+
301
+ // THEN
302
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
303
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
304
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
305
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
306
+ })
307
+
308
+ it('M output error W log(error) (ERROR+ allowed)', async () => {
309
+ // GIVEN
310
+ const message = "log(error) (ERROR+ allowed)"
311
+ InternalLog.verbosity = SdkVerbosity.ERROR
312
+
313
+ // WHEN
314
+ InternalLog.log(message, SdkVerbosity.ERROR)
315
+
316
+ // THEN
317
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
318
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
319
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
320
+ expect(baseConsoleErrorCalled).toStrictEqual(true);
321
+ expect(baseConsoleErrorArg).toStrictEqual(["DATADOG: " + message]);
322
+ })
323
+
324
+ it('M not output debug W log(debug) (none allowed)', async () => {
325
+ // GIVEN
326
+ const message = "log(debug) (none allowed)"
327
+ InternalLog.verbosity = undefined
328
+
329
+ // WHEN
330
+ InternalLog.log(message, SdkVerbosity.DEBUG)
331
+
332
+ // THEN
333
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
334
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
335
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
336
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
337
+ })
338
+
339
+ it('M not output info W log(info) (none allowed)', async () => {
340
+ // GIVEN
341
+ const message = "log(info) (none allowed)"
342
+ InternalLog.verbosity = undefined
343
+
344
+ // WHEN
345
+ InternalLog.log(message, SdkVerbosity.INFO)
346
+
347
+ // THEN
348
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
349
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
350
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
351
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
352
+ })
353
+
354
+ it('M not output warn W log(warn) (none allowed)', async () => {
355
+ // GIVEN
356
+ const message = "log(warn) (none allowed)"
357
+ InternalLog.verbosity = undefined
358
+
359
+ // WHEN
360
+ InternalLog.log(message, SdkVerbosity.WARN)
361
+
362
+ // THEN
363
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
364
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
365
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
366
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
367
+ })
368
+
369
+ it('M not output error W log(error) (none allowed)', async () => {
370
+ // GIVEN
371
+ const message = "log(error) (none allowed)"
372
+ InternalLog.verbosity = undefined
373
+
374
+ // WHEN
375
+ InternalLog.log(message, SdkVerbosity.ERROR)
376
+
377
+ // THEN
378
+ expect(baseConsoleDebugCalled).toStrictEqual(false);
379
+ expect(baseConsoleInfoCalled).toStrictEqual(false);
380
+ expect(baseConsoleWarnCalled).toStrictEqual(false);
381
+ expect(baseConsoleErrorCalled).toStrictEqual(false);
382
+ })
@@ -312,3 +312,24 @@ it('M intercept and send a RUM event W onConsole() {message only}', async () =>
312
312
  expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
313
313
  expect(baseConsoleErrorCalled).toStrictEqual(true);
314
314
  })
315
+
316
+ describe.each(
317
+ [[undefined], [null], [true], [1], ['message'], [() => { }], [{}], [['a']]]
318
+ )('console calls with different message types', (message) => {
319
+ it(`M intercept and send a RUM event W onConsole() { message has ${typeof (message)} type }`, async () => {
320
+ // GIVEN
321
+ DdRumErrorTracking.startTracking();
322
+
323
+ // WHEN
324
+ DdRumErrorTracking.onConsoleError(message);
325
+ await flushPromises();
326
+
327
+ // THEN
328
+ expect(DdRum.addError.mock.calls.length).toBe(1);
329
+ expect(DdRum.addError.mock.calls[0][0]).toBe(message == undefined ? "Unknown Error" : String(message));
330
+ expect(DdRum.addError.mock.calls[0][1]).toBe("CONSOLE");
331
+ expect(DdRum.addError.mock.calls[0][2]).toBe("");
332
+ expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
333
+ expect(baseConsoleErrorCalled).toStrictEqual(true);
334
+ })
335
+ })