@datadog/mobile-react-navigation 1.0.0-rc5 → 1.0.0-rc9

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 (46) hide show
  1. package/lib/commonjs/index.js.map +1 -1
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +77 -51
  3. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  4. package/lib/commonjs/rum/instrumentation/react-navigation.js +2 -0
  5. package/lib/commonjs/rum/instrumentation/react-navigation.js.map +1 -0
  6. package/lib/module/index.js.map +1 -1
  7. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +74 -52
  8. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  9. package/lib/module/rum/instrumentation/react-navigation.js +2 -0
  10. package/lib/module/rum/instrumentation/react-navigation.js.map +1 -0
  11. package/lib/typescript/core/src/DdSdkReactNative.d.ts +6 -6
  12. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +15 -3
  13. package/lib/typescript/core/src/InternalLog.d.ts +5 -0
  14. package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
  15. package/lib/typescript/core/src/Timer.d.ts +3 -2
  16. package/lib/typescript/core/src/index.d.ts +4 -3
  17. package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  18. package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  19. package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  20. package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  21. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  22. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  23. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  24. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  25. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
  26. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  27. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  28. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  29. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  30. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  31. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  32. package/lib/typescript/core/src/version.d.ts +1 -1
  33. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +9 -3
  34. package/lib/typescript/react-navigation/src/rum/instrumentation/react-navigation.d.ts +116 -0
  35. package/package.json +11 -6
  36. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +481 -385
  37. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +75 -0
  38. package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
  39. package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV5.tsx +105 -0
  40. package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV6.tsx +105 -0
  41. package/src/index.tsx +4 -1
  42. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +145 -64
  43. package/src/rum/instrumentation/react-navigation.ts +158 -0
  44. package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +0 -30
  45. package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +0 -13
  46. package/lib/typescript/core/src/rum/instrumentation/TraceIdentifier.d.ts +0 -1
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A Timestamp structure holding the
3
+ */
4
+ export declare type Timestamp = {
5
+ unix: number;
6
+ react_native: number | null;
7
+ };
8
+ /**
9
+ * Simple class providing timestamps in milliseconds.
10
+ * If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
11
+ */
12
+ export declare class TimeProvider {
13
+ private canUsePerformanceNow;
14
+ /** Keeps an average offset between the unix time and the provided timestamp. */
15
+ private baseOffset;
16
+ constructor();
17
+ getTimestamp(): Timestamp;
18
+ now(): number;
19
+ private performanceNow;
20
+ }
@@ -1,9 +1,12 @@
1
+ import { TimeProvider } from './TimeProvider';
1
2
  /**
2
3
  * Simple timer which records time ticks. Shouldn't be re-used once stopped.
3
4
  * All timestamps/durations returned are in milliseconds.
4
5
  */
5
6
  export default class Timer {
7
+ private timeProvider;
6
8
  private times;
9
+ constructor(timeProvider?: TimeProvider);
7
10
  get startTime(): number;
8
11
  get stopTime(): number;
9
12
  start(): void;
@@ -14,7 +17,5 @@ export default class Timer {
14
17
  timeAt(label: string): number;
15
18
  reset(): void;
16
19
  private durationBetweenTicks;
17
- private performanceNow;
18
- private canUsePerformanceNow;
19
20
  private checkLabelExists;
20
21
  }
@@ -1,7 +1,8 @@
1
- import { DdLogs, DdTrace, DdRum } from './foundation';
2
1
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
2
  import { DdSdkReactNative } from './DdSdkReactNative';
3
+ import { InternalLog } from './InternalLog';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
5
- import { TrackingConsent } from './TrackingConsent';
6
5
  import { SdkVerbosity } from './SdkVerbosity';
7
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
6
+ import { TrackingConsent } from './TrackingConsent';
7
+ import { DdLogs, DdTrace, DdRum } from './foundation';
8
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -1,6 +1,7 @@
1
1
  import type EventsInterceptor from './EventsInterceptor';
2
2
  export declare const UNKNOWN_TARGET_NAME = "unknown_target";
3
3
  export declare class DdEventsInterceptor implements EventsInterceptor {
4
+ static ACTION_EVENT_DROPPED_WARN_MESSAGE: string;
4
5
  private debouncingStartedTimestamp;
5
6
  interceptOnPress(...args: any[]): void;
6
7
  private handleTargetEvent;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Provides RUM auto-instrumentation feature to track errors as RUM events.
3
- */
2
+ * Provides RUM auto-instrumentation feature to track errors as RUM events.
3
+ */
4
4
  export declare class DdRumErrorTracking {
5
5
  private static isTracking;
6
6
  private static isInDefaultErrorHandler;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Provides RUM auto-instrumentation feature to track user interaction as RUM events.
3
- * For now we are only covering the "onPress" events.
4
- */
2
+ * Provides RUM auto-instrumentation feature to track user interaction as RUM events.
3
+ * For now we are only covering the "onPress" events.
4
+ */
5
5
  export declare class DdRumUserInteractionTracking {
6
6
  private static isTracking;
7
7
  private static eventsInterceptor;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Does a shallow comparison between 2 objects
3
+ */
4
+ export declare const areObjectShallowEqual: (objectA: Record<string, unknown>, objectB: Record<string, unknown>) => boolean;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
3
+ */
4
+ export declare class DdRumResourceTracking {
5
+ private static isTracking;
6
+ private static requestProxy;
7
+ /**
8
+ * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
9
+ */
10
+ static startTracking({ tracingSamplingRate, firstPartyHosts }: {
11
+ tracingSamplingRate: number;
12
+ firstPartyHosts: string[];
13
+ }): void;
14
+ static stopTracking(): void;
15
+ }
@@ -0,0 +1,18 @@
1
+ import type { Hostname } from './firstPartyHosts';
2
+ export declare type DdRumResourceTracingAttributes = {
3
+ tracingStrategy: 'KEEP';
4
+ traceId: string;
5
+ spanId: string;
6
+ samplingPriorityHeader: '1';
7
+ } | {
8
+ tracingStrategy: 'DISCARD';
9
+ traceId?: void;
10
+ spanId?: void;
11
+ samplingPriorityHeader: '0';
12
+ };
13
+ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
14
+ hostname: Hostname | null;
15
+ firstPartyHostsRegex: RegExp;
16
+ tracingSamplingRate: number;
17
+ }) => DdRumResourceTracingAttributes;
18
+ export declare function generateTraceId(): string;
@@ -0,0 +1,6 @@
1
+ export declare type Hostname = {
2
+ _type: 'Hostname';
3
+ } & string;
4
+ export declare const NO_MATCH_REGEX: RegExp;
5
+ export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
6
+ export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
@@ -0,0 +1,8 @@
1
+ export interface RequestProxyOptions {
2
+ tracingSamplingRate: number;
3
+ firstPartyHostsRegex: RegExp;
4
+ }
5
+ export declare abstract class RequestProxy {
6
+ abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
+ abstract onTrackingStop: () => void;
8
+ }
@@ -0,0 +1,19 @@
1
+ import type { DdRumResourceTracingAttributes } from '../distributedTracing';
2
+ export interface RUMResource {
3
+ key: string;
4
+ request: {
5
+ method: string;
6
+ url: string;
7
+ kind: string;
8
+ };
9
+ tracingAttributes: DdRumResourceTracingAttributes;
10
+ response: {
11
+ statusCode: number;
12
+ size: number;
13
+ };
14
+ timings: {
15
+ startTime: number;
16
+ stopTime: number;
17
+ responseStartTime?: number;
18
+ };
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ declare type ResourceMapper = (resource: RUMResource) => RUMResource | null;
3
+ export declare class ResourceReporter {
4
+ private mappers;
5
+ constructor(resourceMappers: ResourceMapper[]);
6
+ reportResource: (resource: RUMResource) => void;
7
+ }
8
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ /**
3
+ * Filters RN symbolicate calls and Expo logs calls that happen only in dev.
4
+ * @param resource RUMResource
5
+ */
6
+ export declare const filterDevResource: (resource: RUMResource) => RUMResource | null;
@@ -0,0 +1,17 @@
1
+ interface Timing {
2
+ /**
3
+ * Time relative (absolute in case of iOS) to some point, in ns.
4
+ */
5
+ startTime: number;
6
+ /**
7
+ * Duration in ns.
8
+ */
9
+ duration: number;
10
+ }
11
+ interface ResourceTimings {
12
+ firstByte: Timing;
13
+ download: Timing;
14
+ fetch: Timing;
15
+ }
16
+ export declare function createTimings(startTime: number, responseStartTime: number, responseEndTime: number): ResourceTimings;
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Hostname } from '../domain/firstPartyHosts';
2
+ /**
3
+ * Returns the host from an URL.
4
+ * @returns the host (without the port) or null if could not cast the URL as host
5
+ */
6
+ export declare const URLHostParser: (url: string) => Hostname | null;
@@ -0,0 +1,25 @@
1
+ /// <reference types="react-native" />
2
+ import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
3
+ import { RequestProxy } from '../domain/interfaces/RequestProxy';
4
+ import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
5
+ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
6
+ export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
7
+ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
8
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
9
+ export declare const ORIGIN_RUM = "rum";
10
+ interface XHRProxyProviders {
11
+ xhrType: typeof XMLHttpRequest;
12
+ resourceReporter: ResourceReporter;
13
+ }
14
+ /**
15
+ * Proxies XMLHTTPRequest to track resources.
16
+ */
17
+ export declare class XHRProxy extends RequestProxy {
18
+ private providers;
19
+ private static originalXhrOpen;
20
+ private static originalXhrSend;
21
+ constructor(providers: XHRProxyProviders);
22
+ onTrackingStart: (context: RequestProxyOptions) => void;
23
+ onTrackingStop: () => void;
24
+ }
25
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react-native" />
2
+ export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
3
+ export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc5";
1
+ export declare const version = "1.0.0-rc9";
@@ -1,4 +1,4 @@
1
- import type { NavigationContainerRef, Route } from "@react-navigation/native";
1
+ import type { NavigationContainerRef, Route } from './react-navigation';
2
2
  export declare type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string;
3
3
  /**
4
4
  * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
@@ -6,8 +6,14 @@ export declare type ViewNamePredicate = (route: Route<string, any | undefined>,
6
6
  export declare class DdRumReactNavigationTracking {
7
7
  private static registeredContainer;
8
8
  private static navigationStateChangeListener;
9
- private static appStateListener;
10
9
  private static viewNamePredicate;
10
+ private static backHandler;
11
+ private static appStateSubscription?;
12
+ static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE: string;
13
+ static NULL_NAVIGATION_REF_ERROR_MESSAGE: string;
14
+ static NAVIGATION_REF_IN_USE_ERROR_MESSAGE: string;
15
+ static isAppExitingOnBackPress: () => boolean;
16
+ static onBackPress: () => boolean;
11
17
  /**
12
18
  * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
13
19
  * @param navigationRef the reference to the real NavigationContainer.
@@ -20,5 +26,5 @@ export declare class DdRumReactNavigationTracking {
20
26
  static stopTrackingViews(navigationRef: NavigationContainerRef | null): void;
21
27
  private static handleRouteNavigation;
22
28
  private static resolveNavigationStateChangeListener;
23
- private static registerAppStateListenerIfNeeded;
29
+ private static appStateListener;
24
30
  }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * This file contains copy/pastes from react-navigation types. The types have been simplified to be able to work with
3
+ * both v5 and v6.
4
+ * This is needed because NavigationContainerRef became NavigationContainerRef<T> in v6, and so we cannot keep compatibility
5
+ * between the 2 types. Also this way we never import '@react-navigation/native-vX' in our code.
6
+ */
7
+ /**
8
+ * Route
9
+ */
10
+ export declare type Route<RouteName extends string, Params extends object | undefined = object | undefined> = Readonly<{
11
+ /**
12
+ * Unique key for the route.
13
+ */
14
+ key: string;
15
+ /**
16
+ * User-provided name for the route.
17
+ */
18
+ name: RouteName;
19
+ }> & (undefined extends Params ? Readonly<{
20
+ /**
21
+ * Params for this route
22
+ */
23
+ params?: Readonly<Params>;
24
+ }> : Readonly<{
25
+ /**
26
+ * Params for this route
27
+ */
28
+ params: Readonly<Params>;
29
+ }>);
30
+ /**
31
+ * Navigation Container
32
+ */
33
+ export declare type NavigationContainerRef = EventConsumer<NavigationContainerEventMap> & {
34
+ canGoBack(): boolean;
35
+ getCurrentRoute(): Route<string> | undefined;
36
+ };
37
+ export declare type NavigationContainerEventMap = {
38
+ /**
39
+ * Event which fires when the navigation state changes.
40
+ */
41
+ state: {
42
+ data: {
43
+ /**
44
+ * The updated state object after the state change.
45
+ */
46
+ state: any;
47
+ };
48
+ };
49
+ /**
50
+ * Event which fires when current options changes.
51
+ */
52
+ options: {
53
+ data: {
54
+ options: object;
55
+ };
56
+ };
57
+ /**
58
+ * Event which fires when an action is dispatched.
59
+ * Only intended for debugging purposes, don't use it for app logic.
60
+ * This event will be emitted before state changes have been applied.
61
+ */
62
+ __unsafe_action__: {
63
+ data: {
64
+ /**
65
+ * The action object which was dispatched.
66
+ */
67
+ action: any;
68
+ /**
69
+ * Whether the action was a no-op, i.e. resulted any state changes.
70
+ */
71
+ noop: boolean;
72
+ /**
73
+ * Stack trace of the action, this will only be available during development.
74
+ */
75
+ stack: string | undefined;
76
+ };
77
+ };
78
+ };
79
+ export declare type EventConsumer<EventMap extends EventMapBase> = {
80
+ /**
81
+ * Subscribe to events from the parent navigator.
82
+ *
83
+ * @param type Type of the event (e.g. `focus`, `blur`)
84
+ * @param callback Callback listener which is executed upon receiving the event.
85
+ */
86
+ addListener<EventName extends Extract<keyof EventMap, string>>(type: EventName, callback: (...args: any[]) => any): () => void;
87
+ removeListener<EventName extends Extract<keyof EventMap, string>>(type: EventName, callback: (...args: any[]) => any): void;
88
+ };
89
+ export declare type EventMapBase = Record<string, {
90
+ data?: any;
91
+ canPreventDefault?: boolean;
92
+ }>;
93
+ /**
94
+ * NavigationListener
95
+ */
96
+ export declare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null;
97
+ export declare type EventArg<EventName extends string, CanPreventDefault extends boolean | undefined = false, Data = undefined> = {
98
+ /**
99
+ * Type of the event (e.g. `focus`, `blur`)
100
+ */
101
+ readonly type: EventName;
102
+ readonly target?: string;
103
+ } & (CanPreventDefault extends true ? {
104
+ /**
105
+ * Whether `event.preventDefault()` was called on this event object.
106
+ */
107
+ readonly defaultPrevented: boolean;
108
+ /**
109
+ * Prevent the default action which happens on this event.
110
+ */
111
+ preventDefault(): void;
112
+ } : any) & (undefined extends Data ? {
113
+ readonly data?: Readonly<Data>;
114
+ } : {
115
+ readonly data: Readonly<Data>;
116
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.0.0-rc5",
3
+ "version": "1.0.0-rc9",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -36,15 +36,17 @@
36
36
  "prepare": "bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.0.0-rc5",
40
- "@react-navigation/native": "5.9.2",
41
- "@react-navigation/stack": "5.14.2",
39
+ "@datadog/mobile-react-native": "^1.0.0-rc9",
40
+ "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.2",
41
+ "@react-navigation/native-v6": "npm:@react-navigation/native@6.0.9",
42
+ "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2",
43
+ "@react-navigation/stack-v6": "npm:@react-navigation/stack@6.2.1",
44
+ "@testing-library/react-native": "7.0.2",
42
45
  "react-native-gesture-handler": "1.10.3",
43
46
  "react-native-safe-area-context": "3.1.9"
44
47
  },
45
48
  "peerDependencies": {
46
49
  "@datadog/mobile-react-native": "^1.0.0-beta4",
47
- "@react-navigation/native": "^5.6.0",
48
50
  "react": ">=16.13.1",
49
51
  "react-native": ">=0.63.4 <1.0"
50
52
  },
@@ -56,6 +58,9 @@
56
58
  "setupFiles": [
57
59
  "./../../node_modules/react-native-gesture-handler/jestSetup.js"
58
60
  ],
61
+ "testPathIgnorePatterns": [
62
+ "/__utils__/"
63
+ ],
59
64
  "transformIgnorePatterns": []
60
65
  },
61
66
  "react-native-builder-bob": {
@@ -72,5 +77,5 @@
72
77
  ]
73
78
  ]
74
79
  },
75
- "gitHead": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
80
+ "gitHead": "552457ced3fc826cb42120402eb9e98f80228890"
76
81
  }