@dreamhorizonorg/pulse-react-native 0.0.1 → 0.0.2

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 (135) hide show
  1. package/PulseReactNativeOtel.podspec +1 -1
  2. package/README.md +34 -879
  3. package/android/build.gradle +10 -15
  4. package/android/proguard-rules.pro +3 -99
  5. package/android/src/main/java/com/pulsereactnativeotel/Pulse.kt +87 -0
  6. package/android/src/main/java/com/pulsereactnativeotel/PulseOtelConstants.kt +1 -1
  7. package/android/src/main/java/com/pulsereactnativeotel/PulseReactNativeOtelLogger.kt +3 -1
  8. package/android/src/main/java/com/pulsereactnativeotel/PulseReactNativeOtelModule.kt +53 -3
  9. package/android/src/main/java/com/pulsereactnativeotel/PulseReactNativeOtelPackage.kt +1 -1
  10. package/android/src/main/java/com/pulsereactnativeotel/PulseReactNativeOtelTracer.kt +24 -8
  11. package/android/src/main/java/com/pulsereactnativeotel/ReactNativeScreenAttributesLogRecordProcessor.kt +21 -0
  12. package/android/src/main/java/com/pulsereactnativeotel/ReactNativeScreenAttributesSpanProcessor.kt +30 -0
  13. package/android/src/main/java/com/pulsereactnativeotel/ReactNativeScreenNameTracker.kt +17 -0
  14. package/app.plugin.js +1 -0
  15. package/ios/PulseReactNativeOtel.mm +7 -1
  16. package/lib/module/NativePulseReactNativeOtel.js.map +1 -1
  17. package/lib/module/config.js +29 -9
  18. package/lib/module/config.js.map +1 -1
  19. package/lib/module/errorBoundary.js.map +1 -1
  20. package/lib/module/events.js +6 -0
  21. package/lib/module/events.js.map +1 -1
  22. package/lib/module/index.js +4 -2
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/navigation/index.js +172 -0
  25. package/lib/module/navigation/index.js.map +1 -0
  26. package/lib/module/navigation/navigation.interface.js +2 -0
  27. package/lib/module/navigation/navigation.interface.js.map +1 -0
  28. package/lib/module/navigation/screen-interactive.js +101 -0
  29. package/lib/module/navigation/screen-interactive.js.map +1 -0
  30. package/lib/module/navigation/screen-load.js +68 -0
  31. package/lib/module/navigation/screen-load.js.map +1 -0
  32. package/lib/module/navigation/screen-session.js +60 -0
  33. package/lib/module/navigation/screen-session.js.map +1 -0
  34. package/lib/module/navigation/useNavigationTracking.js +33 -0
  35. package/lib/module/navigation/useNavigationTracking.js.map +1 -0
  36. package/lib/module/navigation/utils.js +17 -0
  37. package/lib/module/navigation/utils.js.map +1 -0
  38. package/lib/module/network-interceptor/graphql-helper.js +92 -0
  39. package/lib/module/network-interceptor/graphql-helper.js.map +1 -0
  40. package/lib/module/network-interceptor/request-tracker-xhr.js +2 -1
  41. package/lib/module/network-interceptor/request-tracker-xhr.js.map +1 -1
  42. package/lib/module/network-interceptor/span-helpers.js +24 -16
  43. package/lib/module/network-interceptor/span-helpers.js.map +1 -1
  44. package/lib/module/network-interceptor/url-helper.js +58 -2
  45. package/lib/module/network-interceptor/url-helper.js.map +1 -1
  46. package/lib/module/pulse.constants.js +42 -0
  47. package/lib/module/pulse.constants.js.map +1 -0
  48. package/lib/module/trace.js +17 -2
  49. package/lib/module/trace.js.map +1 -1
  50. package/lib/typescript/plugin/src/index.d.ts +5 -0
  51. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  52. package/lib/typescript/plugin/src/types.d.ts +27 -0
  53. package/lib/typescript/plugin/src/types.d.ts.map +1 -0
  54. package/lib/typescript/plugin/src/utils.d.ts +10 -0
  55. package/lib/typescript/plugin/src/utils.d.ts.map +1 -0
  56. package/lib/typescript/plugin/src/withAndroidPulse.d.ts +4 -0
  57. package/lib/typescript/plugin/src/withAndroidPulse.d.ts.map +1 -0
  58. package/lib/typescript/src/NativePulseReactNativeOtel.d.ts +8 -2
  59. package/lib/typescript/src/NativePulseReactNativeOtel.d.ts.map +1 -1
  60. package/lib/typescript/src/config.d.ts +8 -2
  61. package/lib/typescript/src/config.d.ts.map +1 -1
  62. package/lib/typescript/src/errorBoundary.d.ts.map +1 -1
  63. package/lib/typescript/src/events.d.ts.map +1 -1
  64. package/lib/typescript/src/index.d.ts +5 -3
  65. package/lib/typescript/src/index.d.ts.map +1 -1
  66. package/lib/typescript/src/navigation/index.d.ts +12 -0
  67. package/lib/typescript/src/navigation/index.d.ts.map +1 -0
  68. package/lib/typescript/src/navigation/navigation.interface.d.ts +17 -0
  69. package/lib/typescript/src/navigation/navigation.interface.d.ts.map +1 -0
  70. package/lib/typescript/src/navigation/screen-interactive.d.ts +16 -0
  71. package/lib/typescript/src/navigation/screen-interactive.d.ts.map +1 -0
  72. package/lib/typescript/src/navigation/screen-load.d.ts +13 -0
  73. package/lib/typescript/src/navigation/screen-load.d.ts.map +1 -0
  74. package/lib/typescript/src/navigation/screen-session.d.ts +15 -0
  75. package/lib/typescript/src/navigation/screen-session.d.ts.map +1 -0
  76. package/lib/typescript/src/navigation/useNavigationTracking.d.ts +5 -0
  77. package/lib/typescript/src/navigation/useNavigationTracking.d.ts.map +1 -0
  78. package/lib/typescript/src/navigation/utils.d.ts +8 -0
  79. package/lib/typescript/src/navigation/utils.d.ts.map +1 -0
  80. package/lib/typescript/src/network-interceptor/graphql-helper.d.ts +8 -0
  81. package/lib/typescript/src/network-interceptor/graphql-helper.d.ts.map +1 -0
  82. package/lib/typescript/src/network-interceptor/request-tracker-xhr.d.ts.map +1 -1
  83. package/lib/typescript/src/network-interceptor/span-helpers.d.ts +1 -1
  84. package/lib/typescript/src/network-interceptor/span-helpers.d.ts.map +1 -1
  85. package/lib/typescript/src/network-interceptor/url-helper.d.ts +9 -0
  86. package/lib/typescript/src/network-interceptor/url-helper.d.ts.map +1 -1
  87. package/lib/typescript/src/pulse.constants.d.ts +35 -0
  88. package/lib/typescript/src/pulse.constants.d.ts.map +1 -0
  89. package/lib/typescript/src/pulse.interface.d.ts +2 -1
  90. package/lib/typescript/src/pulse.interface.d.ts.map +1 -1
  91. package/lib/typescript/src/trace.d.ts +7 -0
  92. package/lib/typescript/src/trace.d.ts.map +1 -1
  93. package/package.json +29 -9
  94. package/plugin/build/index.d.ts +4 -0
  95. package/plugin/build/index.js +10 -0
  96. package/plugin/build/types.d.ts +26 -0
  97. package/plugin/build/types.js +2 -0
  98. package/plugin/build/utils.d.ts +9 -0
  99. package/plugin/build/utils.js +102 -0
  100. package/plugin/build/withAndroidPulse.d.ts +3 -0
  101. package/plugin/build/withAndroidPulse.js +53 -0
  102. package/scripts/pulse-cli.js +82 -0
  103. package/scripts/uploadService.js +122 -0
  104. package/scripts/utils.js +125 -0
  105. package/src/NativePulseReactNativeOtel.ts +11 -2
  106. package/src/config.ts +37 -8
  107. package/src/errorBoundary.tsx +11 -5
  108. package/src/events.ts +7 -0
  109. package/src/global.d.ts +0 -1
  110. package/src/index.tsx +6 -3
  111. package/src/navigation/index.ts +306 -0
  112. package/src/navigation/navigation.interface.ts +19 -0
  113. package/src/navigation/screen-interactive.ts +149 -0
  114. package/src/navigation/screen-load.ts +103 -0
  115. package/src/navigation/screen-session.ts +87 -0
  116. package/src/navigation/useNavigationTracking.ts +50 -0
  117. package/src/navigation/utils.ts +19 -0
  118. package/src/network-interceptor/graphql-helper.ts +110 -0
  119. package/src/network-interceptor/request-tracker-xhr.ts +3 -1
  120. package/src/network-interceptor/span-helpers.ts +27 -18
  121. package/src/network-interceptor/url-helper.ts +67 -1
  122. package/src/pulse.constants.ts +38 -0
  123. package/src/pulse.interface.ts +6 -1
  124. package/src/trace.ts +25 -2
  125. package/LICENSE +0 -20
  126. package/lib/module/network-interceptor/request-tracker-fetch.js +0 -72
  127. package/lib/module/network-interceptor/request-tracker-fetch.js.map +0 -1
  128. package/lib/module/reactNavigation.js +0 -100
  129. package/lib/module/reactNavigation.js.map +0 -1
  130. package/lib/typescript/src/network-interceptor/request-tracker-fetch.d.ts +0 -7
  131. package/lib/typescript/src/network-interceptor/request-tracker-fetch.d.ts.map +0 -1
  132. package/lib/typescript/src/reactNavigation.d.ts +0 -10
  133. package/lib/typescript/src/reactNavigation.d.ts.map +0 -1
  134. package/src/network-interceptor/request-tracker-fetch.ts +0 -96
  135. package/src/reactNavigation.tsx +0 -146
@@ -1,96 +0,0 @@
1
- import type {
2
- RequestStartContext,
3
- RequestEndContext,
4
- } from './network.interface';
5
- import { RequestTracker } from './request-tracker';
6
- import { getAbsoluteUrl } from '../utility';
7
- import { createNetworkSpan, completeNetworkSpan } from './span-helpers';
8
-
9
- interface GlobalWithFetch {
10
- fetch: typeof fetch;
11
- }
12
-
13
- function createStartContext(
14
- input: unknown,
15
- init?: unknown
16
- ): RequestStartContext {
17
- const inputIsRequest = isRequest(input);
18
- const url = inputIsRequest ? input.url : String(input);
19
- const method =
20
- (!!init && (init as RequestInit).method) ||
21
- (inputIsRequest && input.method) ||
22
- 'GET';
23
- return { url: getAbsoluteUrl(url), method, type: 'fetch' };
24
- }
25
-
26
- function isRequest(input: unknown): input is Request {
27
- return !!input && typeof input === 'object' && !(input instanceof URL);
28
- }
29
-
30
- let isFetchIntercepted = false;
31
- let originalFetch: typeof fetch | null = null;
32
-
33
- function createFetchRequestTracker(global: GlobalWithFetch): RequestTracker {
34
- if (isFetchIntercepted) {
35
- console.warn('[Pulse] Fetch already intercepted');
36
- return new RequestTracker();
37
- }
38
-
39
- if (originalFetch && global.fetch !== originalFetch) {
40
- console.warn('[Pulse] Fetch already wrapped by another interceptor');
41
- isFetchIntercepted = true;
42
- return new RequestTracker();
43
- }
44
-
45
- if ((global.fetch as any)?._pulseIntercepted) {
46
- console.warn('[Pulse] Fetch already wrapped by Pulse');
47
- isFetchIntercepted = true;
48
- return new RequestTracker();
49
- }
50
-
51
- const requestTracker = new RequestTracker();
52
- originalFetch = global.fetch;
53
- isFetchIntercepted = true;
54
-
55
- const fetchWrapper = function fetch(input: unknown, init?: unknown) {
56
- const startContext = createStartContext(input, init);
57
-
58
- const span = createNetworkSpan(startContext, 'fetch');
59
- const { onRequestEnd } = requestTracker.start(startContext);
60
-
61
- const fetchToCall = originalFetch!;
62
- return fetchToCall
63
- .call(global, input as RequestInfo, init as RequestInit)
64
- .then((response) => {
65
- // Determine if response is successful based on status code
66
- // 2xx and 3xx are successful, 4xx and 5xx are errors
67
- const isSuccess = response.status >= 200 && response.status < 400;
68
-
69
- const endContext: RequestEndContext = {
70
- status: response.status,
71
- state: isSuccess ? 'success' : 'error',
72
- };
73
-
74
- completeNetworkSpan(span, startContext, endContext, !isSuccess);
75
- onRequestEnd(endContext);
76
- return response;
77
- })
78
- .catch((error) => {
79
- const endContext: RequestEndContext = {
80
- error,
81
- state: 'error',
82
- };
83
-
84
- completeNetworkSpan(span, startContext, endContext, true);
85
- onRequestEnd(endContext);
86
- throw error;
87
- });
88
- };
89
-
90
- (fetchWrapper as any)._pulseIntercepted = true;
91
- global.fetch = fetchWrapper;
92
-
93
- return requestTracker;
94
- }
95
-
96
- export default createFetchRequestTracker;
@@ -1,146 +0,0 @@
1
- import { Pulse, type Span } from './index';
2
-
3
- const NAVIGATION_HISTORY_MAX_SIZE = 200;
4
-
5
- export interface NavigationRoute {
6
- name: string;
7
- key: string;
8
- params?: Record<string, any>;
9
- }
10
-
11
- interface NavigationContainer {
12
- addListener: (type: string, listener: (event?: unknown) => void) => void;
13
- getCurrentRoute: () => NavigationRoute | undefined;
14
- }
15
-
16
- export function createReactNavigationIntegration() {
17
- let navigationContainer: NavigationContainer | undefined;
18
- let latestRoute: NavigationRoute | undefined;
19
- let recentRouteKeys: string[] = [];
20
- let isInitialized = false;
21
- let span: Span | undefined;
22
-
23
- const onNavigationDispatch = (): void => {
24
- try {
25
- span = Pulse.startSpan('Navigated', {
26
- attributes: {
27
- 'pulse.type': 'screen_load',
28
- 'phase': 'start',
29
- },
30
- });
31
-
32
- console.log('[Pulse Navigation] Navigation dispatch span started', span);
33
- } catch (error) {
34
- console.warn('[Pulse Navigation] Error in onNavigationDispatch:', error);
35
- }
36
- };
37
-
38
- const onStateChange = (): void => {
39
- try {
40
- if (!navigationContainer) {
41
- console.warn('[Pulse Navigation] Navigation container not registered');
42
- return;
43
- }
44
-
45
- const currentRoute = navigationContainer.getCurrentRoute();
46
- if (!currentRoute) {
47
- return;
48
- }
49
-
50
- if (!span) {
51
- latestRoute = currentRoute;
52
- pushRecentRouteKey(currentRoute.key);
53
- return;
54
- }
55
-
56
- const previousRoute = latestRoute;
57
-
58
- if (previousRoute && previousRoute.key === currentRoute.key) {
59
- return;
60
- }
61
-
62
- latestRoute = currentRoute;
63
-
64
- const routeHasBeenSeen = recentRouteKeys.includes(currentRoute.key);
65
- pushRecentRouteKey(currentRoute.key);
66
-
67
- span?.setAttributes({
68
- 'screen.name': currentRoute.name,
69
- 'last.screen.name': previousRoute?.name || undefined,
70
- 'routeHasBeenSeen': routeHasBeenSeen,
71
- 'routeKey': currentRoute.key,
72
- });
73
-
74
- span?.end();
75
- console.log('[Pulse Navigation] Navigation dispatch span ended', span);
76
- span = undefined;
77
- } catch (error) {
78
- console.warn('[Pulse Navigation] Error in onStateChange:', error);
79
- span = undefined;
80
- }
81
- };
82
-
83
- const registerNavigationContainer = (
84
- maybeNavigationContainer: unknown
85
- ): void => {
86
- try {
87
- let container: NavigationContainer | undefined;
88
- if (
89
- typeof maybeNavigationContainer === 'object' &&
90
- maybeNavigationContainer !== null &&
91
- 'current' in maybeNavigationContainer
92
- ) {
93
- container = maybeNavigationContainer.current as NavigationContainer;
94
- } else {
95
- container = maybeNavigationContainer as NavigationContainer;
96
- }
97
-
98
- if (!container) {
99
- console.warn('[Pulse Navigation] Invalid navigation container ref');
100
- return;
101
- }
102
-
103
- if (isInitialized && navigationContainer === container) {
104
- console.log('[Pulse Navigation] Container already registered');
105
- return;
106
- }
107
-
108
- navigationContainer = container;
109
-
110
- navigationContainer.addListener(
111
- '__unsafe_action__',
112
- onNavigationDispatch
113
- );
114
- navigationContainer.addListener('state', onStateChange);
115
-
116
- const currentRoute = navigationContainer.getCurrentRoute();
117
- if (currentRoute) {
118
- latestRoute = currentRoute;
119
- pushRecentRouteKey(currentRoute.key);
120
- }
121
-
122
- isInitialized = true;
123
- console.log('[Pulse Navigation] Integration initialized successfully');
124
- } catch (error) {
125
- console.error('[Pulse Navigation] Error registering container:', error);
126
- }
127
- };
128
-
129
- const pushRecentRouteKey = (key: string): void => {
130
- recentRouteKeys.push(key);
131
-
132
- if (recentRouteKeys.length > NAVIGATION_HISTORY_MAX_SIZE) {
133
- recentRouteKeys = recentRouteKeys.slice(
134
- recentRouteKeys.length - NAVIGATION_HISTORY_MAX_SIZE
135
- );
136
- }
137
- };
138
-
139
- return {
140
- registerNavigationContainer,
141
- };
142
- }
143
-
144
- export type ReactNavigationIntegration = ReturnType<
145
- typeof createReactNavigationIntegration
146
- >;