@datadog/mobile-react-native 2.3.4 → 2.3.6

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 (41) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  2. package/datadog-sourcemaps.gradle +64 -1
  3. package/ios/Sources/SdkVersion.swift +1 -1
  4. package/lib/commonjs/logs/DdLogs.js +10 -8
  5. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  6. package/lib/commonjs/rum/DdRum.js +50 -48
  7. package/lib/commonjs/rum/DdRum.js.map +1 -1
  8. package/lib/commonjs/trace/DdTrace.js +4 -2
  9. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  10. package/lib/commonjs/utils/argsUtils.js +43 -0
  11. package/lib/commonjs/utils/argsUtils.js.map +1 -0
  12. package/lib/commonjs/utils/time-provider/TimeProvider.js +5 -1
  13. package/lib/commonjs/utils/time-provider/TimeProvider.js.map +1 -1
  14. package/lib/commonjs/version.js +1 -1
  15. package/lib/commonjs/version.js.map +1 -1
  16. package/lib/module/logs/DdLogs.js +9 -8
  17. package/lib/module/logs/DdLogs.js.map +1 -1
  18. package/lib/module/rum/DdRum.js +48 -47
  19. package/lib/module/rum/DdRum.js.map +1 -1
  20. package/lib/module/trace/DdTrace.js +3 -2
  21. package/lib/module/trace/DdTrace.js.map +1 -1
  22. package/lib/module/utils/argsUtils.js +30 -0
  23. package/lib/module/utils/argsUtils.js.map +1 -0
  24. package/lib/module/utils/time-provider/TimeProvider.js +5 -1
  25. package/lib/module/utils/time-provider/TimeProvider.js.map +1 -1
  26. package/lib/module/version.js +1 -1
  27. package/lib/module/version.js.map +1 -1
  28. package/lib/typescript/rum/DdRum.d.ts +2 -2
  29. package/lib/typescript/utils/argsUtils.d.ts +1 -0
  30. package/lib/typescript/version.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/src/logs/DdLogs.ts +9 -8
  33. package/src/logs/__tests__/DdLogs.test.ts +543 -0
  34. package/src/rum/DdRum.ts +112 -94
  35. package/src/rum/__tests__/DdRum.test.ts +552 -0
  36. package/src/trace/DdTrace.ts +12 -2
  37. package/src/trace/__tests__/DdTrace.test.ts +146 -0
  38. package/src/utils/__tests__/argsUtils.test.ts +66 -0
  39. package/src/utils/argsUtils.ts +35 -0
  40. package/src/utils/time-provider/TimeProvider.tsx +6 -1
  41. package/src/version.ts +1 -1
@@ -0,0 +1,146 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ /*
3
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
4
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
5
+ * Copyright 2016-Present Datadog, Inc.
6
+ */
7
+
8
+ import { NativeModules } from 'react-native';
9
+
10
+ import { InternalLog } from '../../InternalLog';
11
+ import { SdkVerbosity } from '../../SdkVerbosity';
12
+ import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
13
+ import { DdTrace } from '../DdTrace';
14
+
15
+ jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
16
+ return {
17
+ DefaultTimeProvider: jest.fn().mockImplementation(() => {
18
+ return { now: jest.fn().mockReturnValue(456) };
19
+ })
20
+ };
21
+ });
22
+
23
+ jest.mock('../../InternalLog', () => {
24
+ return {
25
+ InternalLog: {
26
+ log: jest.fn()
27
+ },
28
+ DATADOG_MESSAGE_PREFIX: 'DATADOG:'
29
+ };
30
+ });
31
+
32
+ describe('DdTrace', () => {
33
+ beforeEach(() => {
34
+ jest.clearAllMocks();
35
+ BufferSingleton.onInitialization();
36
+ });
37
+
38
+ describe('Context validation', () => {
39
+ describe('DdTrace.startSpan', () => {
40
+ test('uses given context when context is valid', async () => {
41
+ const context = {
42
+ testA: 123,
43
+ testB: 'ok'
44
+ };
45
+ await DdTrace.startSpan('operation', context);
46
+
47
+ expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
48
+ 'operation',
49
+ context,
50
+ expect.anything()
51
+ );
52
+ });
53
+
54
+ test('uses empty context with error when context is invalid or null', async () => {
55
+ const context: any = 123;
56
+ await DdTrace.startSpan('operation', context);
57
+
58
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
59
+ 1,
60
+ expect.anything(),
61
+ SdkVerbosity.ERROR
62
+ );
63
+
64
+ expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
65
+ 'operation',
66
+ {},
67
+ expect.anything()
68
+ );
69
+ });
70
+
71
+ test('nests given context in new object when context is array', async () => {
72
+ const context: any = [123, '456'];
73
+ await DdTrace.startSpan('operation', context);
74
+
75
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
76
+ 1,
77
+ expect.anything(),
78
+ SdkVerbosity.WARN
79
+ );
80
+
81
+ expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledWith(
82
+ 'operation',
83
+ { context },
84
+ expect.anything()
85
+ );
86
+ });
87
+ });
88
+
89
+ describe('DdTrace.finishSpan', () => {
90
+ test('uses given context when context is valid', async () => {
91
+ const context = {
92
+ testA: 123,
93
+ testB: 'ok'
94
+ };
95
+
96
+ const spanId = await DdTrace.startSpan('operation', {});
97
+ await DdTrace.finishSpan(spanId, context);
98
+
99
+ expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
100
+ spanId,
101
+ context,
102
+ expect.anything()
103
+ );
104
+ });
105
+
106
+ test('uses empty context with error when context is invalid or null', async () => {
107
+ const context: any = 123;
108
+ await DdTrace.startSpan('operation', context);
109
+
110
+ const spanId = await DdTrace.startSpan('operation', {});
111
+ await DdTrace.finishSpan(spanId, context);
112
+
113
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
114
+ 1,
115
+ expect.anything(),
116
+ SdkVerbosity.ERROR
117
+ );
118
+
119
+ expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
120
+ spanId,
121
+ {},
122
+ expect.anything()
123
+ );
124
+ });
125
+
126
+ test('nests given context in new object when context is array', async () => {
127
+ const context: any = [123, '456'];
128
+
129
+ const spanId = await DdTrace.startSpan('operation', {});
130
+ await DdTrace.finishSpan(spanId, context);
131
+
132
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
133
+ 3,
134
+ expect.anything(),
135
+ SdkVerbosity.WARN
136
+ );
137
+
138
+ expect(NativeModules.DdTrace.finishSpan).toHaveBeenCalledWith(
139
+ spanId,
140
+ { context },
141
+ expect.anything()
142
+ );
143
+ });
144
+ });
145
+ });
146
+ });
@@ -0,0 +1,66 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ /*
3
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
4
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
5
+ * Copyright 2016-Present Datadog, Inc.
6
+ */
7
+
8
+ import { InternalLog } from '../../InternalLog';
9
+ import { SdkVerbosity } from '../../SdkVerbosity';
10
+ import { validateContext } from '../argsUtils';
11
+
12
+ jest.mock('../../InternalLog', () => {
13
+ return {
14
+ InternalLog: {
15
+ log: jest.fn()
16
+ },
17
+ DATADOG_MESSAGE_PREFIX: 'DATADOG:'
18
+ };
19
+ });
20
+
21
+ describe('argsUtils', () => {
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+
26
+ describe('validateContext', () => {
27
+ it('returns empty object if context is null', () => {
28
+ expect(validateContext(null)).toEqual({});
29
+ expect(validateContext(undefined)).toEqual({});
30
+ });
31
+
32
+ it('returns empty object with error if context is raw type', () => {
33
+ expect(validateContext('raw-type')).toEqual({});
34
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
35
+ 1,
36
+ expect.anything(),
37
+ SdkVerbosity.ERROR
38
+ );
39
+ });
40
+
41
+ it('nests array inside of new object if context is an array', () => {
42
+ const context = [{ a: 1, b: 2 }, 1, true];
43
+ const validatedContext = validateContext(context);
44
+
45
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
46
+ 1,
47
+ expect.anything(),
48
+ SdkVerbosity.WARN
49
+ );
50
+
51
+ expect(validatedContext).toEqual({
52
+ context
53
+ });
54
+ });
55
+
56
+ it('returns unmodified context if it is a valid object', () => {
57
+ const context = {
58
+ testA: 1,
59
+ testB: {}
60
+ };
61
+ const validatedContext = validateContext(context);
62
+
63
+ expect(validatedContext).toEqual(context);
64
+ });
65
+ });
66
+ });
@@ -0,0 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ /*
3
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
4
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
5
+ * Copyright 2016-Present Datadog, Inc.
6
+ */
7
+
8
+ import { InternalLog } from '../InternalLog';
9
+ import { SdkVerbosity } from '../SdkVerbosity';
10
+
11
+ export const validateContext = (context: any) => {
12
+ if (!context) {
13
+ return {};
14
+ }
15
+
16
+ // eslint-disable-next-line eqeqeq
17
+ if (context.constructor == Object) {
18
+ return context;
19
+ }
20
+
21
+ if (Array.isArray(context)) {
22
+ InternalLog.log(
23
+ "The given context is an array, it will be nested in 'context' property inside a new object.",
24
+ SdkVerbosity.WARN
25
+ );
26
+ return { context };
27
+ }
28
+
29
+ InternalLog.log(
30
+ `The given context (${context}) is invalid - it must be an object. Context will be empty.`,
31
+ SdkVerbosity.ERROR
32
+ );
33
+
34
+ return {};
35
+ };
@@ -36,7 +36,12 @@ export abstract class TimeProvider {
36
36
 
37
37
  now(): number {
38
38
  const timestamp = this.getTimestamp();
39
- if (timestamp.reactNative == null) {
39
+
40
+ if (timestamp.reactNative != null && this.baseOffset === 0) {
41
+ this.baseOffset = timestamp.unix - timestamp.reactNative;
42
+ }
43
+
44
+ if (timestamp.reactNative == null || this.baseOffset === 0) {
40
45
  return timestamp.unix;
41
46
  } else {
42
47
  return this.baseOffset + timestamp.reactNative;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.3.4';
2
+ export const version = '2.3.6';