@kush_hemant/react-api-monitor 1.0.21 → 1.0.22
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.
- package/dist/index.js +47 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,13 +69,12 @@ function monitorFetch() {
|
|
|
69
69
|
// src/utils/metadata.js
|
|
70
70
|
function getMetadata2() {
|
|
71
71
|
return {
|
|
72
|
-
pageUrl:
|
|
72
|
+
pageUrl: location.href,
|
|
73
73
|
userAgent: navigator.userAgent,
|
|
74
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
75
|
-
// Useful extras
|
|
76
74
|
language: navigator.language,
|
|
77
75
|
platform: navigator.platform,
|
|
78
|
-
screen: `${screen.width}x${screen.height}
|
|
76
|
+
screen: `${screen.width}x${screen.height}`,
|
|
77
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
80
|
|
|
@@ -121,31 +120,58 @@ function monitorXHR() {
|
|
|
121
120
|
// src/network/resourceMonitor.js
|
|
122
121
|
function monitorResources() {
|
|
123
122
|
if (!window.PerformanceObserver) return;
|
|
124
|
-
const observer = new PerformanceObserver(
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
const observer = new PerformanceObserver((list) => {
|
|
124
|
+
list.getEntries().forEach((entry) => {
|
|
125
|
+
if (entry.initiatorType === "fetch" || entry.initiatorType === "xmlhttprequest" || entry.initiatorType === "beacon") {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (LOG_ENDPOINT2 && entry.name.includes(LOG_ENDPOINT2)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
sendLog2({
|
|
132
|
+
type: "resource",
|
|
133
|
+
transport: "resource",
|
|
134
|
+
url: entry.name,
|
|
135
|
+
method: "GET",
|
|
136
|
+
duration: Math.round(entry.duration),
|
|
137
|
+
statusCode: 0,
|
|
138
|
+
...getMetadata2()
|
|
137
139
|
});
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
observer.observe({
|
|
141
|
-
entryTypes: ["resource"]
|
|
140
|
+
});
|
|
142
141
|
});
|
|
142
|
+
observer.observe({ entryTypes: ["resource"] });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/network/monitorAxios.js
|
|
146
|
+
function monitorAxios() {
|
|
147
|
+
if (!window.axios) return;
|
|
148
|
+
window.axios.interceptors.request.use((config) => {
|
|
149
|
+
config.__startTime = Date.now();
|
|
150
|
+
return config;
|
|
151
|
+
});
|
|
152
|
+
window.axios.interceptors.response.use(
|
|
153
|
+
(response) => {
|
|
154
|
+
var _a;
|
|
155
|
+
sendLog2({
|
|
156
|
+
type: "api_call",
|
|
157
|
+
transport: "axios",
|
|
158
|
+
url: response.config.url,
|
|
159
|
+
method: (_a = response.config.method) == null ? void 0 : _a.toUpperCase(),
|
|
160
|
+
statusCode: response.status,
|
|
161
|
+
duration: Date.now() - response.config.__startTime,
|
|
162
|
+
...getMetadata2()
|
|
163
|
+
});
|
|
164
|
+
return response;
|
|
165
|
+
},
|
|
166
|
+
(error) => Promise.reject(error)
|
|
167
|
+
);
|
|
143
168
|
}
|
|
144
169
|
|
|
145
170
|
// src/network/auto.js
|
|
146
171
|
function startNetworkMonitoring() {
|
|
147
172
|
monitorFetch();
|
|
148
173
|
monitorXHR();
|
|
174
|
+
monitorAxios();
|
|
149
175
|
monitorResources();
|
|
150
176
|
}
|
|
151
177
|
|