@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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
1
+ import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
2
2
  export { MushiApiCascadeConfig, MushiConfig, MushiConsoleEntry, MushiDiagnosticsResult, MushiEnvironment, MushiEventHandler, MushiEventType, MushiNetworkEntry, MushiPerformanceMetrics, MushiReport, MushiReportCategory, MushiSDKInstance, MushiTimelineEntry, MushiTimelineKind, MushiUrlMatcher, MushiWidgetConfig } from '@mushi-mushi/core';
3
3
 
4
4
  declare class Mushi {
@@ -349,6 +349,8 @@ interface NetworkCapture {
349
349
  interface NetworkCaptureOptions {
350
350
  apiEndpoint?: string;
351
351
  ignoreUrls?: MushiUrlMatcher[];
352
+ tracePropagation?: MushiTracePropagationConfig;
353
+ sessionId?: string;
352
354
  }
353
355
  declare function createNetworkCapture(options?: NetworkCaptureOptions): NetworkCapture;
354
356
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
1
+ import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
2
2
  export { MushiApiCascadeConfig, MushiConfig, MushiConsoleEntry, MushiDiagnosticsResult, MushiEnvironment, MushiEventHandler, MushiEventType, MushiNetworkEntry, MushiPerformanceMetrics, MushiReport, MushiReportCategory, MushiSDKInstance, MushiTimelineEntry, MushiTimelineKind, MushiUrlMatcher, MushiWidgetConfig } from '@mushi-mushi/core';
3
3
 
4
4
  declare class Mushi {
@@ -349,6 +349,8 @@ interface NetworkCapture {
349
349
  interface NetworkCaptureOptions {
350
350
  apiEndpoint?: string;
351
351
  ignoreUrls?: MushiUrlMatcher[];
352
+ tracePropagation?: MushiTracePropagationConfig;
353
+ sessionId?: string;
352
354
  }
353
355
  declare function createNetworkCapture(options?: NetworkCaptureOptions): NetworkCapture;
354
356
 
package/dist/index.js CHANGED
@@ -3727,6 +3727,29 @@ function readHeader(headers, name) {
3727
3727
 
3728
3728
  // src/capture/network.ts
3729
3729
  var MAX_ENTRIES2 = 30;
3730
+ var TRACEPARENT_VERSION = "00";
3731
+ function generateTraceparent() {
3732
+ const traceBytes = crypto.getRandomValues(new Uint8Array(16));
3733
+ const spanBytes = crypto.getRandomValues(new Uint8Array(8));
3734
+ const toHex = (bytes) => Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
3735
+ const traceId = toHex(traceBytes);
3736
+ const spanId = toHex(spanBytes);
3737
+ return {
3738
+ traceparent: `${TRACEPARENT_VERSION}-${traceId}-${spanId}-01`,
3739
+ traceId,
3740
+ spanId
3741
+ };
3742
+ }
3743
+ function matchesCorsUrls(url, corsUrls) {
3744
+ for (const pattern of corsUrls) {
3745
+ if (typeof pattern === "string") {
3746
+ if (url.includes(pattern)) return true;
3747
+ } else {
3748
+ if (pattern.test(url)) return true;
3749
+ }
3750
+ }
3751
+ return false;
3752
+ }
3730
3753
  function createNetworkCapture(options = {}) {
3731
3754
  const entries = [];
3732
3755
  const originalFetch = globalThis.fetch;
@@ -3737,15 +3760,29 @@ function createNetworkCapture(options = {}) {
3737
3760
  const url = getRequestUrl(input);
3738
3761
  const internalKind = getInternalRequestKind(input, init);
3739
3762
  const shouldRecord = !internalKind && !shouldIgnoreMushiUrl(url, activeOptions);
3763
+ let traceId;
3764
+ let patchedInit = init;
3765
+ const tp = activeOptions.tracePropagation;
3766
+ if (shouldRecord && tp?.enabled && tp.corsUrls?.length && matchesCorsUrls(url, tp.corsUrls)) {
3767
+ const { traceparent, traceId: tid } = generateTraceparent();
3768
+ traceId = tid;
3769
+ const existingHeaders = init?.headers ? new Headers(init.headers) : new Headers();
3770
+ existingHeaders.set("traceparent", traceparent);
3771
+ if (activeOptions.sessionId) {
3772
+ existingHeaders.set("x-mushi-session", activeOptions.sessionId);
3773
+ }
3774
+ patchedInit = { ...init, headers: existingHeaders };
3775
+ }
3740
3776
  try {
3741
- const response = await originalFetch.call(globalThis, input, init);
3777
+ const response = await originalFetch.call(globalThis, input, patchedInit);
3742
3778
  if (shouldRecord) {
3743
3779
  addEntry({
3744
3780
  method,
3745
3781
  url: truncateUrl(url),
3746
3782
  status: response.status,
3747
3783
  duration: Date.now() - startTime,
3748
- timestamp: startTime
3784
+ timestamp: startTime,
3785
+ ...traceId ? { traceId } : {}
3749
3786
  });
3750
3787
  }
3751
3788
  return response;
@@ -3757,7 +3794,8 @@ function createNetworkCapture(options = {}) {
3757
3794
  status: 0,
3758
3795
  duration: Date.now() - startTime,
3759
3796
  timestamp: startTime,
3760
- error: error instanceof Error ? error.message : "Network error"
3797
+ error: error instanceof Error ? error.message : "Network error",
3798
+ ...traceId ? { traceId } : {}
3761
3799
  });
3762
3800
  }
3763
3801
  throw error;
@@ -4990,7 +5028,7 @@ function createProactiveManager(config = {}) {
4990
5028
 
4991
5029
  // src/version.ts
4992
5030
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
4993
- var MUSHI_SDK_VERSION = "1.8.0" ;
5031
+ var MUSHI_SDK_VERSION = "1.9.0" ;
4994
5032
 
4995
5033
  // src/mushi.ts
4996
5034
  var instance = null;
@@ -5080,7 +5118,9 @@ function createInstance(config) {
5080
5118
  if (activeConfig.capture?.network !== false) {
5081
5119
  const networkOptions = {
5082
5120
  apiEndpoint: resolveApiEndpoint(activeConfig),
5083
- ignoreUrls: activeConfig.capture?.ignoreUrls
5121
+ ignoreUrls: activeConfig.capture?.ignoreUrls,
5122
+ tracePropagation: activeConfig.capture?.tracePropagation,
5123
+ sessionId: getSessionId()
5084
5124
  };
5085
5125
  if (networkCap) {
5086
5126
  networkCap.updateOptions(networkOptions);