@mushi-mushi/web 1.8.0 → 1.9.0
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.cjs +45 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +45 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -3729,6 +3729,29 @@ function readHeader(headers, name) {
|
|
|
3729
3729
|
|
|
3730
3730
|
// src/capture/network.ts
|
|
3731
3731
|
var MAX_ENTRIES2 = 30;
|
|
3732
|
+
var TRACEPARENT_VERSION = "00";
|
|
3733
|
+
function generateTraceparent() {
|
|
3734
|
+
const traceBytes = crypto.getRandomValues(new Uint8Array(16));
|
|
3735
|
+
const spanBytes = crypto.getRandomValues(new Uint8Array(8));
|
|
3736
|
+
const toHex = (bytes) => Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3737
|
+
const traceId = toHex(traceBytes);
|
|
3738
|
+
const spanId = toHex(spanBytes);
|
|
3739
|
+
return {
|
|
3740
|
+
traceparent: `${TRACEPARENT_VERSION}-${traceId}-${spanId}-01`,
|
|
3741
|
+
traceId,
|
|
3742
|
+
spanId
|
|
3743
|
+
};
|
|
3744
|
+
}
|
|
3745
|
+
function matchesCorsUrls(url, corsUrls) {
|
|
3746
|
+
for (const pattern of corsUrls) {
|
|
3747
|
+
if (typeof pattern === "string") {
|
|
3748
|
+
if (url.includes(pattern)) return true;
|
|
3749
|
+
} else {
|
|
3750
|
+
if (pattern.test(url)) return true;
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
return false;
|
|
3754
|
+
}
|
|
3732
3755
|
function createNetworkCapture(options = {}) {
|
|
3733
3756
|
const entries = [];
|
|
3734
3757
|
const originalFetch = globalThis.fetch;
|
|
@@ -3739,15 +3762,29 @@ function createNetworkCapture(options = {}) {
|
|
|
3739
3762
|
const url = getRequestUrl(input);
|
|
3740
3763
|
const internalKind = getInternalRequestKind(input, init);
|
|
3741
3764
|
const shouldRecord = !internalKind && !shouldIgnoreMushiUrl(url, activeOptions);
|
|
3765
|
+
let traceId;
|
|
3766
|
+
let patchedInit = init;
|
|
3767
|
+
const tp = activeOptions.tracePropagation;
|
|
3768
|
+
if (shouldRecord && tp?.enabled && tp.corsUrls?.length && matchesCorsUrls(url, tp.corsUrls)) {
|
|
3769
|
+
const { traceparent, traceId: tid } = generateTraceparent();
|
|
3770
|
+
traceId = tid;
|
|
3771
|
+
const existingHeaders = init?.headers ? new Headers(init.headers) : new Headers();
|
|
3772
|
+
existingHeaders.set("traceparent", traceparent);
|
|
3773
|
+
if (activeOptions.sessionId) {
|
|
3774
|
+
existingHeaders.set("x-mushi-session", activeOptions.sessionId);
|
|
3775
|
+
}
|
|
3776
|
+
patchedInit = { ...init, headers: existingHeaders };
|
|
3777
|
+
}
|
|
3742
3778
|
try {
|
|
3743
|
-
const response = await originalFetch.call(globalThis, input,
|
|
3779
|
+
const response = await originalFetch.call(globalThis, input, patchedInit);
|
|
3744
3780
|
if (shouldRecord) {
|
|
3745
3781
|
addEntry({
|
|
3746
3782
|
method,
|
|
3747
3783
|
url: truncateUrl(url),
|
|
3748
3784
|
status: response.status,
|
|
3749
3785
|
duration: Date.now() - startTime,
|
|
3750
|
-
timestamp: startTime
|
|
3786
|
+
timestamp: startTime,
|
|
3787
|
+
...traceId ? { traceId } : {}
|
|
3751
3788
|
});
|
|
3752
3789
|
}
|
|
3753
3790
|
return response;
|
|
@@ -3759,7 +3796,8 @@ function createNetworkCapture(options = {}) {
|
|
|
3759
3796
|
status: 0,
|
|
3760
3797
|
duration: Date.now() - startTime,
|
|
3761
3798
|
timestamp: startTime,
|
|
3762
|
-
error: error instanceof Error ? error.message : "Network error"
|
|
3799
|
+
error: error instanceof Error ? error.message : "Network error",
|
|
3800
|
+
...traceId ? { traceId } : {}
|
|
3763
3801
|
});
|
|
3764
3802
|
}
|
|
3765
3803
|
throw error;
|
|
@@ -4992,7 +5030,7 @@ function createProactiveManager(config = {}) {
|
|
|
4992
5030
|
|
|
4993
5031
|
// src/version.ts
|
|
4994
5032
|
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
4995
|
-
var MUSHI_SDK_VERSION = "1.
|
|
5033
|
+
var MUSHI_SDK_VERSION = "1.9.0" ;
|
|
4996
5034
|
|
|
4997
5035
|
// src/mushi.ts
|
|
4998
5036
|
var instance = null;
|
|
@@ -5082,7 +5120,9 @@ function createInstance(config) {
|
|
|
5082
5120
|
if (activeConfig.capture?.network !== false) {
|
|
5083
5121
|
const networkOptions = {
|
|
5084
5122
|
apiEndpoint: resolveApiEndpoint(activeConfig),
|
|
5085
|
-
ignoreUrls: activeConfig.capture?.ignoreUrls
|
|
5123
|
+
ignoreUrls: activeConfig.capture?.ignoreUrls,
|
|
5124
|
+
tracePropagation: activeConfig.capture?.tracePropagation,
|
|
5125
|
+
sessionId: core.getSessionId()
|
|
5086
5126
|
};
|
|
5087
5127
|
if (networkCap) {
|
|
5088
5128
|
networkCap.updateOptions(networkOptions);
|