@djangocfg/monitor 2.1.230 → 2.1.232
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/README.md +16 -1
- package/dist/client.cjs +62 -44
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -1
- package/dist/client.d.ts +3 -1
- package/dist/client.mjs +62 -44
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +36 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +36 -32
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +36 -32
- package/dist/server.cjs.map +1 -1
- package/dist/server.mjs +36 -32
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/cfg_monitor/client.ts +39 -42
- package/src/client/hooks/useDebugMode.ts +21 -7
- package/src/client/index.ts +1 -1
- package/src/client/store/index.ts +2 -0
- package/src/client/utils/env.ts +3 -0
- package/src/client/window.ts +3 -0
package/dist/client.d.cts
CHANGED
|
@@ -163,6 +163,8 @@ declare function useDebugMode(): boolean;
|
|
|
163
163
|
declare const isDevelopment: boolean;
|
|
164
164
|
/** True in production builds and test environments */
|
|
165
165
|
declare const isProduction: boolean;
|
|
166
|
+
/** Package version — injected at build time via tsup define, falls back to package.json value */
|
|
167
|
+
declare const MONITOR_VERSION: string;
|
|
166
168
|
|
|
167
169
|
/**
|
|
168
170
|
* @djangocfg/monitor/client
|
|
@@ -192,4 +194,4 @@ declare const FrontendMonitor: {
|
|
|
192
194
|
destroy(): void;
|
|
193
195
|
};
|
|
194
196
|
|
|
195
|
-
export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
|
|
197
|
+
export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, MONITOR_VERSION, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
|
package/dist/client.d.ts
CHANGED
|
@@ -163,6 +163,8 @@ declare function useDebugMode(): boolean;
|
|
|
163
163
|
declare const isDevelopment: boolean;
|
|
164
164
|
/** True in production builds and test environments */
|
|
165
165
|
declare const isProduction: boolean;
|
|
166
|
+
/** Package version — injected at build time via tsup define, falls back to package.json value */
|
|
167
|
+
declare const MONITOR_VERSION: string;
|
|
166
168
|
|
|
167
169
|
/**
|
|
168
170
|
* @djangocfg/monitor/client
|
|
@@ -192,4 +194,4 @@ declare const FrontendMonitor: {
|
|
|
192
194
|
destroy(): void;
|
|
193
195
|
};
|
|
194
196
|
|
|
195
|
-
export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
|
|
197
|
+
export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, MONITOR_VERSION, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
|
package/dist/client.mjs
CHANGED
|
@@ -972,43 +972,47 @@ var _APIClient = class _APIClient {
|
|
|
972
972
|
if (error instanceof APIError) {
|
|
973
973
|
throw error;
|
|
974
974
|
}
|
|
975
|
-
|
|
975
|
+
let possiblyCors = false;
|
|
976
|
+
if (error instanceof TypeError && typeof window !== "undefined") {
|
|
977
|
+
try {
|
|
978
|
+
const isCrossOrigin = (() => {
|
|
979
|
+
try {
|
|
980
|
+
return new URL(url).origin !== window.location.origin;
|
|
981
|
+
} catch {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
})();
|
|
985
|
+
if (isCrossOrigin) {
|
|
986
|
+
const entries = performance.getEntriesByName(url, "resource");
|
|
987
|
+
if (entries.length > 0) {
|
|
988
|
+
const last = entries[entries.length - 1];
|
|
989
|
+
possiblyCors = "responseStatus" in last && last.responseStatus === 0;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
} catch {
|
|
993
|
+
}
|
|
994
|
+
}
|
|
976
995
|
if (this.logger) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
this.logger.error(` \u2192
|
|
981
|
-
} else {
|
|
982
|
-
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
983
|
-
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
996
|
+
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
997
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
998
|
+
if (possiblyCors) {
|
|
999
|
+
this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
|
|
984
1000
|
}
|
|
985
1001
|
}
|
|
986
1002
|
if (typeof window !== "undefined") {
|
|
987
1003
|
try {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
window.dispatchEvent(new CustomEvent("network-error", {
|
|
1001
|
-
detail: {
|
|
1002
|
-
url,
|
|
1003
|
-
method,
|
|
1004
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1005
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
1006
|
-
},
|
|
1007
|
-
bubbles: true,
|
|
1008
|
-
cancelable: false
|
|
1009
|
-
}));
|
|
1010
|
-
}
|
|
1011
|
-
} catch (eventError) {
|
|
1004
|
+
window.dispatchEvent(new CustomEvent("network-error", {
|
|
1005
|
+
detail: {
|
|
1006
|
+
url,
|
|
1007
|
+
method,
|
|
1008
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1009
|
+
possibly_cors: possiblyCors,
|
|
1010
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1011
|
+
},
|
|
1012
|
+
bubbles: true,
|
|
1013
|
+
cancelable: false
|
|
1014
|
+
}));
|
|
1015
|
+
} catch {
|
|
1012
1016
|
}
|
|
1013
1017
|
}
|
|
1014
1018
|
const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
|
|
@@ -1334,6 +1338,11 @@ async function sendBatch(batch, useBeacon = false) {
|
|
|
1334
1338
|
}
|
|
1335
1339
|
__name(sendBatch, "sendBatch");
|
|
1336
1340
|
|
|
1341
|
+
// src/client/utils/env.ts
|
|
1342
|
+
var isDevelopment = true;
|
|
1343
|
+
var isProduction = false;
|
|
1344
|
+
var MONITOR_VERSION = "2.1.232";
|
|
1345
|
+
|
|
1337
1346
|
// src/client/store/index.ts
|
|
1338
1347
|
var CIRCUIT_BREAKER_THRESHOLD = 3;
|
|
1339
1348
|
var CIRCUIT_BREAKER_COOLDOWN_MS = 6e4;
|
|
@@ -1347,6 +1356,7 @@ var monitorStore = createStore((set, get) => ({
|
|
|
1347
1356
|
const { config, buffer } = get();
|
|
1348
1357
|
const maxSize = config.maxBufferSize ?? 20;
|
|
1349
1358
|
const sanitized = {
|
|
1359
|
+
build_id: event.build_id ?? config.buildId ?? `sdk:${MONITOR_VERSION}`,
|
|
1350
1360
|
...event,
|
|
1351
1361
|
// Enforce field size limits before buffering (last-resort backstop)
|
|
1352
1362
|
message: event.message && event.message.length > 4997 ? event.message.slice(0, 4997) + "..." : event.message,
|
|
@@ -1708,6 +1718,8 @@ function initWindowMonitor() {
|
|
|
1708
1718
|
status() {
|
|
1709
1719
|
const state = monitorStore.getState();
|
|
1710
1720
|
console.group("[monitor] status");
|
|
1721
|
+
console.log("sdk version:", MONITOR_VERSION);
|
|
1722
|
+
console.log("build_id:", state.config.buildId ?? `sdk:${MONITOR_VERSION}`);
|
|
1711
1723
|
console.log("config:", state.config);
|
|
1712
1724
|
console.log("buffer size:", state.buffer.length);
|
|
1713
1725
|
console.log("initialized:", state.initialized);
|
|
@@ -1732,12 +1744,6 @@ __name(MonitorProvider, "MonitorProvider");
|
|
|
1732
1744
|
|
|
1733
1745
|
// src/client/hooks/useDebugMode.ts
|
|
1734
1746
|
import { useEffect as useEffect2, useState } from "react";
|
|
1735
|
-
|
|
1736
|
-
// src/client/utils/env.ts
|
|
1737
|
-
var isDevelopment = true;
|
|
1738
|
-
var isProduction = false;
|
|
1739
|
-
|
|
1740
|
-
// src/client/hooks/useDebugMode.ts
|
|
1741
1747
|
var LS_KEY = "__debug_mode__";
|
|
1742
1748
|
function readFromStorage() {
|
|
1743
1749
|
try {
|
|
@@ -1754,16 +1760,27 @@ function persistToStorage() {
|
|
|
1754
1760
|
}
|
|
1755
1761
|
}
|
|
1756
1762
|
__name(persistToStorage, "persistToStorage");
|
|
1763
|
+
function clearFromStorage() {
|
|
1764
|
+
try {
|
|
1765
|
+
localStorage.removeItem(LS_KEY);
|
|
1766
|
+
} catch {
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
__name(clearFromStorage, "clearFromStorage");
|
|
1757
1770
|
function consumeDebugParam() {
|
|
1758
|
-
if (typeof window === "undefined") return
|
|
1771
|
+
if (typeof window === "undefined") return null;
|
|
1759
1772
|
const params = new URLSearchParams(window.location.search);
|
|
1760
1773
|
const value = params.get("debug");
|
|
1761
|
-
if (
|
|
1762
|
-
|
|
1774
|
+
if (value === null) return null;
|
|
1775
|
+
if (value === "1") {
|
|
1776
|
+
persistToStorage();
|
|
1777
|
+
} else {
|
|
1778
|
+
clearFromStorage();
|
|
1779
|
+
}
|
|
1763
1780
|
params.delete("debug");
|
|
1764
1781
|
const newUrl = `${window.location.pathname}${params.toString() ? `?${params.toString()}` : ""}${window.location.hash}`;
|
|
1765
1782
|
window.history.replaceState(null, "", newUrl);
|
|
1766
|
-
return
|
|
1783
|
+
return value === "1";
|
|
1767
1784
|
}
|
|
1768
1785
|
__name(consumeDebugParam, "consumeDebugParam");
|
|
1769
1786
|
function useDebugMode() {
|
|
@@ -1771,8 +1788,8 @@ function useDebugMode() {
|
|
|
1771
1788
|
const [isDebug, setIsDebug] = useState(false);
|
|
1772
1789
|
useEffect2(() => {
|
|
1773
1790
|
const fromUrl = consumeDebugParam();
|
|
1774
|
-
if (fromUrl) {
|
|
1775
|
-
setIsDebug(
|
|
1791
|
+
if (fromUrl !== null) {
|
|
1792
|
+
setIsDebug(fromUrl);
|
|
1776
1793
|
return;
|
|
1777
1794
|
}
|
|
1778
1795
|
setIsDebug(readFromStorage());
|
|
@@ -1822,6 +1839,7 @@ export {
|
|
|
1822
1839
|
FrontendEventIngestRequestLevel as EventLevel,
|
|
1823
1840
|
FrontendEventIngestRequestEventType as EventType,
|
|
1824
1841
|
FrontendMonitor,
|
|
1842
|
+
MONITOR_VERSION,
|
|
1825
1843
|
MonitorProvider,
|
|
1826
1844
|
getSessionId,
|
|
1827
1845
|
initWindowMonitor,
|