@multiplayer-app/session-recorder-browser 1.3.30 → 1.3.32

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 (43) hide show
  1. package/README.md +3 -3
  2. package/dist/browser/index.js +307 -349
  3. package/dist/config/defaults.d.ts.map +1 -1
  4. package/dist/config/defaults.js +8 -8
  5. package/dist/config/defaults.js.map +1 -1
  6. package/dist/exporters/index.js +1 -1
  7. package/dist/exporters/index.js.map +1 -1
  8. package/dist/index.js +305 -349
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.umd.js +306 -349
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/otel/CrashBufferSpanProcessor.js +2 -2
  13. package/dist/otel/index.d.ts +2 -3
  14. package/dist/otel/index.d.ts.map +1 -1
  15. package/dist/otel/index.js +63 -163
  16. package/dist/otel/index.js.map +1 -1
  17. package/dist/otel/instrumentations/index.d.ts +3 -0
  18. package/dist/otel/instrumentations/index.d.ts.map +1 -0
  19. package/dist/otel/instrumentations/index.js +104 -0
  20. package/dist/otel/instrumentations/index.js.map +1 -0
  21. package/dist/rrweb/index.d.ts.map +1 -1
  22. package/dist/rrweb/index.js +7 -7
  23. package/dist/rrweb/index.js.map +1 -1
  24. package/dist/services/api.service.d.ts +2 -0
  25. package/dist/services/api.service.d.ts.map +1 -1
  26. package/dist/services/api.service.js +5 -5
  27. package/dist/services/api.service.js.map +1 -1
  28. package/dist/services/crashBuffer.service.d.ts +1 -2
  29. package/dist/services/crashBuffer.service.d.ts.map +1 -1
  30. package/dist/services/crashBuffer.service.js +33 -73
  31. package/dist/services/crashBuffer.service.js.map +1 -1
  32. package/dist/services/indexedDb.service.js +2 -2
  33. package/dist/services/indexedDb.service.js.map +1 -1
  34. package/dist/services/socket.service.d.ts +4 -1
  35. package/dist/services/socket.service.d.ts.map +1 -1
  36. package/dist/services/socket.service.js +12 -19
  37. package/dist/services/socket.service.js.map +1 -1
  38. package/dist/session-recorder.d.ts.map +1 -1
  39. package/dist/session-recorder.js +34 -49
  40. package/dist/session-recorder.js.map +1 -1
  41. package/dist/types/session-recorder.d.ts +3 -3
  42. package/dist/types/session-recorder.d.ts.map +1 -1
  43. package/package.json +2 -2
package/dist/index.umd.js CHANGED
@@ -24326,7 +24326,7 @@ const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
24326
24326
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
24327
24327
  const REMOTE_SESSION_RECORDING_START = 'remote-session-recording:start';
24328
24328
  const REMOTE_SESSION_RECORDING_STOP = 'remote-session-recording:stop';
24329
- const PACKAGE_VERSION_EXPORT = "1.3.30" || 0;
24329
+ const PACKAGE_VERSION_EXPORT = "1.3.32" || 0;
24330
24330
  // Regex patterns for OpenTelemetry ignore URLs
24331
24331
  const OTEL_IGNORE_URLS = [
24332
24332
  // Traces endpoint
@@ -24375,7 +24375,7 @@ const DEFAULT_MASKING_CONFIG = {
24375
24375
  maskBodyFieldsList: sensitiveFields,
24376
24376
  maskHeadersList: sensitiveHeaders,
24377
24377
  headersToInclude: [],
24378
- headersToExclude: [],
24378
+ headersToExclude: []
24379
24379
  };
24380
24380
  const DEFAULT_WIDGET_TEXT_CONFIG = {
24381
24381
  initialTitleWithContinuous: 'Encountered an issue?',
@@ -24397,7 +24397,7 @@ const DEFAULT_WIDGET_TEXT_CONFIG = {
24397
24397
  submitDialogCommentLabel: 'You can also add context, comments, or notes.',
24398
24398
  submitDialogCommentPlaceholder: 'Add a message...',
24399
24399
  submitDialogSubmitText: 'Save',
24400
- submitDialogCancelText: 'Cancel',
24400
+ submitDialogCancelText: 'Cancel'
24401
24401
  };
24402
24402
  const BASE_CONFIG = {
24403
24403
  apiKey: '',
@@ -24424,9 +24424,9 @@ const BASE_CONFIG = {
24424
24424
  useWebsocket: true,
24425
24425
  buffering: {
24426
24426
  enabled: true,
24427
- windowMinutes: 1,
24428
- snapshotIntervalMs: 30000,
24429
- },
24427
+ windowMinutes: 0.5,
24428
+ snapshotIntervalMs: 20000
24429
+ }
24430
24430
  };
24431
24431
 
24432
24432
 
@@ -25024,8 +25024,8 @@ class CrashBufferSpanProcessor {
25024
25024
  this._crashBuffer.appendSpans([
25025
25025
  {
25026
25026
  ts: span.startTime[0] * 1000 + span.startTime[1] / 1000000,
25027
- span: this._serializeSpan(span),
25028
- },
25027
+ span: this._serializeSpan(span)
25028
+ }
25029
25029
  ]);
25030
25030
  }
25031
25031
  return;
@@ -25277,18 +25277,16 @@ const getElementTextContent = (element) => {
25277
25277
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
25278
25278
  /* harmony export */ TracerBrowserSDK: () => (/* binding */ TracerBrowserSDK)
25279
25279
  /* harmony export */ });
25280
- /* harmony import */ var _opentelemetry_resources__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @opentelemetry/resources */ "../../node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js");
25281
- /* harmony import */ var _opentelemetry_core__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @opentelemetry/core */ "../../node_modules/@opentelemetry/core/build/esm/trace/W3CTraceContextPropagator.js");
25282
- /* harmony import */ var _opentelemetry_sdk_trace_web__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @opentelemetry/sdk-trace-web */ "../../node_modules/@opentelemetry/sdk-trace-web/build/esm/WebTracerProvider.js");
25283
- /* harmony import */ var _opentelemetry_sdk_trace_base__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @opentelemetry/sdk-trace-base */ "../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/browser/export/BatchSpanProcessor.js");
25284
- /* harmony import */ var _opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @opentelemetry/semantic-conventions */ "../../node_modules/@opentelemetry/semantic-conventions/build/esm/resource/SemanticResourceAttributes.js");
25285
- /* harmony import */ var _opentelemetry_instrumentation__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! @opentelemetry/instrumentation */ "../../node_modules/@opentelemetry/instrumentation/build/esm/autoLoader.js");
25286
- /* harmony import */ var _opentelemetry_auto_instrumentations_web__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @opentelemetry/auto-instrumentations-web */ "../../node_modules/@opentelemetry/auto-instrumentations-web/build/esm/index.js");
25287
- /* harmony import */ var _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @multiplayer-app/session-recorder-common */ "../session-recorder-common/dist/esm/index-browser.js");
25288
- /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../config */ "./src/config/index.ts");
25289
- /* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers */ "./src/otel/helpers.ts");
25290
- /* harmony import */ var _CrashBufferSpanProcessor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CrashBufferSpanProcessor */ "./src/otel/CrashBufferSpanProcessor.ts");
25291
-
25280
+ /* harmony import */ var _opentelemetry_resources__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @opentelemetry/resources */ "../../node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js");
25281
+ /* harmony import */ var _opentelemetry_core__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @opentelemetry/core */ "../../node_modules/@opentelemetry/core/build/esm/trace/W3CTraceContextPropagator.js");
25282
+ /* harmony import */ var _opentelemetry_sdk_trace_web__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @opentelemetry/sdk-trace-web */ "../../node_modules/@opentelemetry/sdk-trace-web/build/esm/WebTracerProvider.js");
25283
+ /* harmony import */ var _opentelemetry_sdk_trace_base__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @opentelemetry/sdk-trace-base */ "../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/browser/export/BatchSpanProcessor.js");
25284
+ /* harmony import */ var _opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @opentelemetry/semantic-conventions */ "../../node_modules/@opentelemetry/semantic-conventions/build/esm/resource/SemanticResourceAttributes.js");
25285
+ /* harmony import */ var _opentelemetry_instrumentation__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @opentelemetry/instrumentation */ "../../node_modules/@opentelemetry/instrumentation/build/esm/autoLoader.js");
25286
+ /* harmony import */ var _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @multiplayer-app/session-recorder-common */ "../session-recorder-common/dist/esm/index-browser.js");
25287
+ /* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers */ "./src/otel/helpers.ts");
25288
+ /* harmony import */ var _instrumentations__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./instrumentations */ "./src/otel/instrumentations/index.ts");
25289
+ /* harmony import */ var _CrashBufferSpanProcessor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./CrashBufferSpanProcessor */ "./src/otel/CrashBufferSpanProcessor.ts");
25292
25290
 
25293
25291
 
25294
25292
 
@@ -25299,14 +25297,14 @@ const getElementTextContent = (element) => {
25299
25297
 
25300
25298
 
25301
25299
 
25302
- const clientIdGenerator = _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderSdk.getIdGenerator(_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.MULTIPLAYER_TRACE_CLIENT_ID_LENGTH);
25300
+ const clientIdGenerator = _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderSdk.getIdGenerator(_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.MULTIPLAYER_TRACE_CLIENT_ID_LENGTH);
25303
25301
  class TracerBrowserSDK {
25304
25302
  constructor() {
25305
25303
  this.clientId = '';
25306
25304
  this.sessionId = '';
25307
25305
  this.globalErrorListenersRegistered = false;
25308
25306
  }
25309
- _setSessionId(sessionId, sessionType = _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionType.MANUAL) {
25307
+ _setSessionId(sessionId, sessionType = _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionType.MANUAL) {
25310
25308
  this.sessionId = sessionId;
25311
25309
  if (!this.idGenerator) {
25312
25310
  throw new Error('Id generator not initialized');
@@ -25317,133 +25315,35 @@ class TracerBrowserSDK {
25317
25315
  this.config = options;
25318
25316
  this.clientId = clientIdGenerator();
25319
25317
  const { application, version, environment } = this.config;
25320
- this.idGenerator = new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderIdGenerator();
25321
- this._setSessionId('', _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionType.SESSION_CACHE);
25322
- this.exporter = new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderBrowserTraceExporter({
25318
+ this.idGenerator = new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderIdGenerator();
25319
+ this._setSessionId('', _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionType.SESSION_CACHE);
25320
+ this.exporter = new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderBrowserTraceExporter({
25323
25321
  apiKey: options.apiKey,
25324
- url: (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.getExporterEndpoint)(options.exporterEndpoint),
25325
- usePostMessageFallback: options.usePostMessageFallback,
25322
+ url: (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getExporterEndpoint)(options.exporterEndpoint),
25323
+ usePostMessageFallback: options.usePostMessageFallback
25326
25324
  });
25327
- const resourceAttributes = (0,_opentelemetry_resources__WEBPACK_IMPORTED_MODULE_5__.resourceFromAttributes)({
25328
- [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_6__.SEMRESATTRS_SERVICE_NAME]: application,
25329
- [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_6__.SEMRESATTRS_SERVICE_VERSION]: version,
25330
- [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_6__.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: environment,
25325
+ const resourceAttributes = (0,_opentelemetry_resources__WEBPACK_IMPORTED_MODULE_4__.resourceFromAttributes)({
25326
+ [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_5__.SEMRESATTRS_SERVICE_NAME]: application,
25327
+ [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_5__.SEMRESATTRS_SERVICE_VERSION]: version,
25328
+ [_opentelemetry_semantic_conventions__WEBPACK_IMPORTED_MODULE_5__.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: environment
25331
25329
  });
25332
- _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderSdk.setResourceAttributes(resourceAttributes.attributes);
25333
- this.tracerProvider = new _opentelemetry_sdk_trace_web__WEBPACK_IMPORTED_MODULE_7__.WebTracerProvider({
25330
+ _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderSdk.setResourceAttributes(resourceAttributes.attributes);
25331
+ this.tracerProvider = new _opentelemetry_sdk_trace_web__WEBPACK_IMPORTED_MODULE_6__.WebTracerProvider({
25334
25332
  resource: resourceAttributes,
25335
25333
  idGenerator: this.idGenerator,
25336
- sampler: new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderTraceIdRatioBasedSampler(this.config.sampleTraceRatio),
25334
+ sampler: new _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderTraceIdRatioBasedSampler(this.config.sampleTraceRatio),
25337
25335
  spanProcessors: [
25338
25336
  this._getSpanSessionIdProcessor(),
25339
- new _opentelemetry_sdk_trace_base__WEBPACK_IMPORTED_MODULE_8__.BatchSpanProcessor(this.exporter),
25340
- new _CrashBufferSpanProcessor__WEBPACK_IMPORTED_MODULE_4__.CrashBufferSpanProcessor(this.crashBuffer, this.exporter.serializeSpan),
25341
- ],
25337
+ new _opentelemetry_sdk_trace_base__WEBPACK_IMPORTED_MODULE_7__.BatchSpanProcessor(this.exporter),
25338
+ new _CrashBufferSpanProcessor__WEBPACK_IMPORTED_MODULE_3__.CrashBufferSpanProcessor(this.crashBuffer, this.exporter.serializeSpan)
25339
+ ]
25342
25340
  });
25343
25341
  this.tracerProvider.register({
25344
- // contextManager: new ZoneContextManager(),
25345
- propagator: new _opentelemetry_core__WEBPACK_IMPORTED_MODULE_9__.W3CTraceContextPropagator(),
25342
+ propagator: new _opentelemetry_core__WEBPACK_IMPORTED_MODULE_8__.W3CTraceContextPropagator()
25346
25343
  });
25347
- (0,_opentelemetry_instrumentation__WEBPACK_IMPORTED_MODULE_10__.registerInstrumentations)({
25344
+ (0,_opentelemetry_instrumentation__WEBPACK_IMPORTED_MODULE_9__.registerInstrumentations)({
25348
25345
  tracerProvider: this.tracerProvider,
25349
- instrumentations: [
25350
- (0,_opentelemetry_auto_instrumentations_web__WEBPACK_IMPORTED_MODULE_0__.getWebAutoInstrumentations)({
25351
- '@opentelemetry/instrumentation-xml-http-request': {
25352
- clearTimingResources: true,
25353
- ignoreUrls: [..._config__WEBPACK_IMPORTED_MODULE_2__.OTEL_IGNORE_URLS, ...(this.config.ignoreUrls || [])],
25354
- propagateTraceHeaderCorsUrls: options.propagateTraceHeaderCorsUrls,
25355
- applyCustomAttributesOnSpan: (span, xhr) => {
25356
- if (!this.config)
25357
- return;
25358
- const { captureBody, captureHeaders } = this.config;
25359
- try {
25360
- if (!captureBody && !captureHeaders) {
25361
- return;
25362
- }
25363
- // @ts-ignore
25364
- const networkRequest = xhr.networkRequest;
25365
- const requestBody = networkRequest.requestBody;
25366
- const responseBody = networkRequest.responseBody;
25367
- const requestHeaders = networkRequest.requestHeaders || {};
25368
- const responseHeaders = networkRequest.responseHeaders || {};
25369
- const payload = {
25370
- requestBody,
25371
- responseBody,
25372
- requestHeaders,
25373
- responseHeaders,
25374
- };
25375
- (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.processHttpPayload)(payload, this.config, span);
25376
- }
25377
- catch (error) {
25378
- // eslint-disable-next-line
25379
- console.error('[MULTIPLAYER_SESSION_RECORDER] Failed to capture xml-http payload', error);
25380
- }
25381
- },
25382
- },
25383
- '@opentelemetry/instrumentation-fetch': {
25384
- clearTimingResources: true,
25385
- ignoreUrls: [..._config__WEBPACK_IMPORTED_MODULE_2__.OTEL_IGNORE_URLS, ...(this.config.ignoreUrls || [])],
25386
- propagateTraceHeaderCorsUrls: options.propagateTraceHeaderCorsUrls,
25387
- applyCustomAttributesOnSpan: async (span, request, response) => {
25388
- if (!this.config)
25389
- return;
25390
- const { captureBody, captureHeaders } = this.config;
25391
- try {
25392
- if (!captureBody && !captureHeaders) {
25393
- return;
25394
- }
25395
- // Try to get data from our fetch wrapper first
25396
- // @ts-ignore
25397
- const networkRequest = response === null || response === void 0 ? void 0 : response.networkRequest;
25398
- let requestBody = null;
25399
- let responseBody = null;
25400
- let requestHeaders = {};
25401
- let responseHeaders = {};
25402
- if (networkRequest) {
25403
- // Use data captured by our fetch wrapper
25404
- requestBody = networkRequest.requestBody;
25405
- responseBody = networkRequest.responseBody;
25406
- requestHeaders = networkRequest.requestHeaders || {};
25407
- responseHeaders = networkRequest.responseHeaders || {};
25408
- }
25409
- else {
25410
- // Fallback to original OpenTelemetry approach
25411
- requestBody = request.body;
25412
- requestHeaders = (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.headersToObject)(request.headers);
25413
- responseHeaders = (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.headersToObject)(response instanceof Response ? response.headers : undefined);
25414
- if (response instanceof Response && response.body) {
25415
- responseBody = await (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.extractResponseBody)(response);
25416
- }
25417
- }
25418
- const payload = {
25419
- requestBody,
25420
- responseBody,
25421
- requestHeaders,
25422
- responseHeaders,
25423
- };
25424
- (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.processHttpPayload)(payload, this.config, span);
25425
- }
25426
- catch (error) {
25427
- // eslint-disable-next-line
25428
- console.error('[MULTIPLAYER_SESSION_RECORDER] Failed to capture fetch payload', error);
25429
- }
25430
- },
25431
- },
25432
- '@opentelemetry/instrumentation-user-interaction': {
25433
- shouldPreventSpanCreation: (_event, element, span) => {
25434
- if (span['parentSpanContext']) {
25435
- return true;
25436
- }
25437
- span.setAttribute('target.innerText', (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.getElementInnerText)(element));
25438
- span.setAttribute('target.textContent', (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.getElementTextContent)(element));
25439
- Array.from(element.attributes).forEach((attribute) => {
25440
- span.setAttribute(`target.attribute.${attribute.name}`, attribute.value);
25441
- });
25442
- return false;
25443
- },
25444
- },
25445
- }),
25446
- ],
25346
+ instrumentations: (0,_instrumentations__WEBPACK_IMPORTED_MODULE_2__.getInstrumentations)(this.config)
25447
25347
  });
25448
25348
  this._registerGlobalErrorListeners();
25449
25349
  }
@@ -25460,7 +25360,7 @@ class TracerBrowserSDK {
25460
25360
  if (!this.tracerProvider) {
25461
25361
  throw new Error('Configuration not initialized. Call init() before start().');
25462
25362
  }
25463
- this._setSessionId('', _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionType.SESSION_CACHE);
25363
+ this._setSessionId('', _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionType.SESSION_CACHE);
25464
25364
  }
25465
25365
  setApiKey(apiKey) {
25466
25366
  if (!this.exporter) {
@@ -25468,56 +25368,6 @@ class TracerBrowserSDK {
25468
25368
  }
25469
25369
  this.exporter.setApiKey(apiKey);
25470
25370
  }
25471
- static _toReadableSpanLike(span) {
25472
- var _a;
25473
- if (span && typeof span.spanContext === 'function' && span.instrumentationScope) {
25474
- return span;
25475
- }
25476
- const spanContext = typeof (span === null || span === void 0 ? void 0 : span.spanContext) === 'function' ? span.spanContext() : span === null || span === void 0 ? void 0 : span._spanContext;
25477
- const normalizedCtx = spanContext ||
25478
- {
25479
- traceId: span === null || span === void 0 ? void 0 : span.traceId,
25480
- spanId: span === null || span === void 0 ? void 0 : span.spanId,
25481
- traceFlags: span === null || span === void 0 ? void 0 : span.traceFlags,
25482
- traceState: span === null || span === void 0 ? void 0 : span.traceState,
25483
- };
25484
- const instrumentationScope = (span === null || span === void 0 ? void 0 : span.instrumentationScope) ||
25485
- (span === null || span === void 0 ? void 0 : span.instrumentationLibrary) ||
25486
- { name: 'multiplayer-buffer', version: undefined, schemaUrl: undefined };
25487
- const normalizedScope = {
25488
- name: (instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.name) || 'multiplayer-buffer',
25489
- version: instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.version,
25490
- schemaUrl: instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.schemaUrl,
25491
- };
25492
- const resource = (span === null || span === void 0 ? void 0 : span.resource) || { attributes: {}, asyncAttributesPending: false };
25493
- const parentSpanId = span === null || span === void 0 ? void 0 : span.parentSpanId;
25494
- return {
25495
- name: (span === null || span === void 0 ? void 0 : span.name) || '',
25496
- kind: span === null || span === void 0 ? void 0 : span.kind,
25497
- spanContext: () => normalizedCtx,
25498
- parentSpanContext: parentSpanId
25499
- ? {
25500
- traceId: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceId,
25501
- spanId: parentSpanId,
25502
- traceFlags: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceFlags,
25503
- traceState: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceState,
25504
- }
25505
- : undefined,
25506
- startTime: span === null || span === void 0 ? void 0 : span.startTime,
25507
- endTime: (_a = span === null || span === void 0 ? void 0 : span.endTime) !== null && _a !== void 0 ? _a : span === null || span === void 0 ? void 0 : span.startTime,
25508
- duration: span === null || span === void 0 ? void 0 : span.duration,
25509
- status: span === null || span === void 0 ? void 0 : span.status,
25510
- attributes: (span === null || span === void 0 ? void 0 : span.attributes) || {},
25511
- links: (span === null || span === void 0 ? void 0 : span.links) || [],
25512
- events: (span === null || span === void 0 ? void 0 : span.events) || [],
25513
- ended: typeof (span === null || span === void 0 ? void 0 : span.ended) === 'boolean' ? span.ended : true,
25514
- droppedAttributesCount: (span === null || span === void 0 ? void 0 : span.droppedAttributesCount) || 0,
25515
- droppedEventsCount: (span === null || span === void 0 ? void 0 : span.droppedEventsCount) || 0,
25516
- droppedLinksCount: (span === null || span === void 0 ? void 0 : span.droppedLinksCount) || 0,
25517
- resource,
25518
- instrumentationScope: normalizedScope,
25519
- };
25520
- }
25521
25371
  async exportTraces(spans) {
25522
25372
  if (!this.exporter) {
25523
25373
  throw new Error('Trace exporter not initialized');
@@ -25539,19 +25389,18 @@ class TracerBrowserSDK {
25539
25389
  * Otherwise, a short-lived span will be created to hold the exception event.
25540
25390
  */
25541
25391
  captureException(error, errorInfo) {
25542
- _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.SessionRecorderSdk.captureException(error, errorInfo);
25392
+ _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionRecorderSdk.captureException(error, errorInfo);
25543
25393
  }
25544
25394
  _getSpanSessionIdProcessor() {
25545
25395
  return {
25546
- forceFlush: () => Promise.resolve(),
25547
- onEnd: () => Promise.resolve(),
25548
- shutdown: () => Promise.resolve(),
25549
25396
  onStart: (span) => {
25550
- var _a;
25551
- if ((_a = this.sessionId) === null || _a === void 0 ? void 0 : _a.length) {
25552
- span.setAttribute(_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_1__.ATTR_MULTIPLAYER_SESSION_ID, this.sessionId);
25397
+ if (this.sessionId) {
25398
+ span.setAttribute(_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.ATTR_MULTIPLAYER_SESSION_ID, this.sessionId);
25553
25399
  }
25554
25400
  },
25401
+ onEnd: () => { },
25402
+ shutdown: () => Promise.resolve(),
25403
+ forceFlush: () => Promise.resolve()
25555
25404
  };
25556
25405
  }
25557
25406
  _registerGlobalErrorListeners() {
@@ -25576,9 +25425,179 @@ class TracerBrowserSDK {
25576
25425
  window.addEventListener('unhandledrejection', rejectionHandler);
25577
25426
  this.globalErrorListenersRegistered = true;
25578
25427
  }
25428
+ static _toReadableSpanLike(span) {
25429
+ var _a;
25430
+ if (span && typeof span.spanContext === 'function' && span.instrumentationScope) {
25431
+ return span;
25432
+ }
25433
+ const spanContext = typeof (span === null || span === void 0 ? void 0 : span.spanContext) === 'function' ? span.spanContext() : span === null || span === void 0 ? void 0 : span._spanContext;
25434
+ const normalizedCtx = spanContext ||
25435
+ {
25436
+ traceId: span === null || span === void 0 ? void 0 : span.traceId,
25437
+ spanId: span === null || span === void 0 ? void 0 : span.spanId,
25438
+ traceFlags: span === null || span === void 0 ? void 0 : span.traceFlags,
25439
+ traceState: span === null || span === void 0 ? void 0 : span.traceState
25440
+ };
25441
+ const instrumentationScope = (span === null || span === void 0 ? void 0 : span.instrumentationScope) ||
25442
+ (span === null || span === void 0 ? void 0 : span.instrumentationLibrary) ||
25443
+ { name: 'multiplayer-buffer', version: undefined, schemaUrl: undefined };
25444
+ const normalizedScope = {
25445
+ name: (instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.name) || 'multiplayer-buffer',
25446
+ version: instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.version,
25447
+ schemaUrl: instrumentationScope === null || instrumentationScope === void 0 ? void 0 : instrumentationScope.schemaUrl
25448
+ };
25449
+ const resource = (span === null || span === void 0 ? void 0 : span.resource) || { attributes: {}, asyncAttributesPending: false };
25450
+ const parentSpanId = span === null || span === void 0 ? void 0 : span.parentSpanId;
25451
+ return {
25452
+ name: (span === null || span === void 0 ? void 0 : span.name) || '',
25453
+ kind: span === null || span === void 0 ? void 0 : span.kind,
25454
+ spanContext: () => normalizedCtx,
25455
+ parentSpanContext: parentSpanId
25456
+ ? {
25457
+ traceId: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceId,
25458
+ spanId: parentSpanId,
25459
+ traceFlags: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceFlags,
25460
+ traceState: normalizedCtx === null || normalizedCtx === void 0 ? void 0 : normalizedCtx.traceState
25461
+ }
25462
+ : undefined,
25463
+ startTime: span === null || span === void 0 ? void 0 : span.startTime,
25464
+ endTime: (_a = span === null || span === void 0 ? void 0 : span.endTime) !== null && _a !== void 0 ? _a : span === null || span === void 0 ? void 0 : span.startTime,
25465
+ duration: span === null || span === void 0 ? void 0 : span.duration,
25466
+ status: span === null || span === void 0 ? void 0 : span.status,
25467
+ attributes: (span === null || span === void 0 ? void 0 : span.attributes) || {},
25468
+ links: (span === null || span === void 0 ? void 0 : span.links) || [],
25469
+ events: (span === null || span === void 0 ? void 0 : span.events) || [],
25470
+ ended: typeof (span === null || span === void 0 ? void 0 : span.ended) === 'boolean' ? span.ended : true,
25471
+ droppedAttributesCount: (span === null || span === void 0 ? void 0 : span.droppedAttributesCount) || 0,
25472
+ droppedEventsCount: (span === null || span === void 0 ? void 0 : span.droppedEventsCount) || 0,
25473
+ droppedLinksCount: (span === null || span === void 0 ? void 0 : span.droppedLinksCount) || 0,
25474
+ resource,
25475
+ instrumentationScope: normalizedScope
25476
+ };
25477
+ }
25579
25478
  }
25580
25479
 
25581
25480
 
25481
+ /***/ }),
25482
+
25483
+ /***/ "./src/otel/instrumentations/index.ts":
25484
+ /*!********************************************!*\
25485
+ !*** ./src/otel/instrumentations/index.ts ***!
25486
+ \********************************************/
25487
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25488
+
25489
+ "use strict";
25490
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
25491
+ /* harmony export */ getInstrumentations: () => (/* binding */ getInstrumentations)
25492
+ /* harmony export */ });
25493
+ /* harmony import */ var _opentelemetry_auto_instrumentations_web__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @opentelemetry/auto-instrumentations-web */ "../../node_modules/@opentelemetry/auto-instrumentations-web/build/esm/index.js");
25494
+ /* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../helpers */ "./src/otel/helpers.ts");
25495
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../config */ "./src/config/index.ts");
25496
+
25497
+
25498
+
25499
+ const getInstrumentations = (config) => {
25500
+ return [
25501
+ (0,_opentelemetry_auto_instrumentations_web__WEBPACK_IMPORTED_MODULE_0__.getWebAutoInstrumentations)({
25502
+ '@opentelemetry/instrumentation-xml-http-request': {
25503
+ clearTimingResources: true,
25504
+ ignoreUrls: [..._config__WEBPACK_IMPORTED_MODULE_2__.OTEL_IGNORE_URLS, ...(config.ignoreUrls || [])],
25505
+ propagateTraceHeaderCorsUrls: config.propagateTraceHeaderCorsUrls,
25506
+ applyCustomAttributesOnSpan: (span, xhr) => {
25507
+ if (!config)
25508
+ return;
25509
+ const { captureBody, captureHeaders } = config;
25510
+ try {
25511
+ if (!captureBody && !captureHeaders) {
25512
+ return;
25513
+ }
25514
+ // @ts-ignore
25515
+ const networkRequest = xhr.networkRequest;
25516
+ const requestBody = networkRequest.requestBody;
25517
+ const responseBody = networkRequest.responseBody;
25518
+ const requestHeaders = networkRequest.requestHeaders || {};
25519
+ const responseHeaders = networkRequest.responseHeaders || {};
25520
+ const payload = {
25521
+ requestBody,
25522
+ responseBody,
25523
+ requestHeaders,
25524
+ responseHeaders
25525
+ };
25526
+ (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.processHttpPayload)(payload, config, span);
25527
+ }
25528
+ catch (error) {
25529
+ // eslint-disable-next-line
25530
+ console.error('[MULTIPLAYER_SESSION_RECORDER] Failed to capture xml-http payload', error);
25531
+ }
25532
+ }
25533
+ },
25534
+ '@opentelemetry/instrumentation-fetch': {
25535
+ clearTimingResources: true,
25536
+ ignoreUrls: [..._config__WEBPACK_IMPORTED_MODULE_2__.OTEL_IGNORE_URLS, ...(config.ignoreUrls || [])],
25537
+ propagateTraceHeaderCorsUrls: config.propagateTraceHeaderCorsUrls,
25538
+ applyCustomAttributesOnSpan: async (span, request, response) => {
25539
+ if (!config)
25540
+ return;
25541
+ const { captureBody, captureHeaders } = config;
25542
+ try {
25543
+ if (!captureBody && !captureHeaders) {
25544
+ return;
25545
+ }
25546
+ // Try to get data from our fetch wrapper first
25547
+ // @ts-ignore
25548
+ const networkRequest = response === null || response === void 0 ? void 0 : response.networkRequest;
25549
+ let requestBody = null;
25550
+ let responseBody = null;
25551
+ let requestHeaders = {};
25552
+ let responseHeaders = {};
25553
+ if (networkRequest) {
25554
+ // Use data captured by our fetch wrapper
25555
+ requestBody = networkRequest.requestBody;
25556
+ responseBody = networkRequest.responseBody;
25557
+ requestHeaders = networkRequest.requestHeaders || {};
25558
+ responseHeaders = networkRequest.responseHeaders || {};
25559
+ }
25560
+ else {
25561
+ // Fallback to original OpenTelemetry approach
25562
+ requestBody = request.body;
25563
+ requestHeaders = (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.headersToObject)(request.headers);
25564
+ responseHeaders = (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.headersToObject)(response instanceof Response ? response.headers : undefined);
25565
+ if (response instanceof Response && response.body) {
25566
+ responseBody = await (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.extractResponseBody)(response);
25567
+ }
25568
+ }
25569
+ const payload = {
25570
+ requestBody,
25571
+ responseBody,
25572
+ requestHeaders,
25573
+ responseHeaders
25574
+ };
25575
+ (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.processHttpPayload)(payload, config, span);
25576
+ }
25577
+ catch (error) {
25578
+ // eslint-disable-next-line
25579
+ console.error('[MULTIPLAYER_SESSION_RECORDER] Failed to capture fetch payload', error);
25580
+ }
25581
+ }
25582
+ },
25583
+ '@opentelemetry/instrumentation-user-interaction': {
25584
+ shouldPreventSpanCreation: (_event, element, span) => {
25585
+ if (span['parentSpanContext']) {
25586
+ return true;
25587
+ }
25588
+ span.setAttribute('target.innerText', (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getElementInnerText)(element));
25589
+ span.setAttribute('target.textContent', (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getElementTextContent)(element));
25590
+ Array.from(element.attributes).forEach((attribute) => {
25591
+ span.setAttribute(`target.attribute.${attribute.name}`, attribute.value);
25592
+ });
25593
+ return false;
25594
+ }
25595
+ }
25596
+ })
25597
+ ];
25598
+ };
25599
+
25600
+
25582
25601
  /***/ }),
25583
25602
 
25584
25603
  /***/ "./src/patch/configs.ts":
@@ -26014,7 +26033,7 @@ class RecorderBrowserSDK {
26014
26033
  constructor() {
26015
26034
  this.intervals = {
26016
26035
  restart: null,
26017
- bufferSnapshot: null,
26036
+ bufferSnapshot: null
26018
26037
  };
26019
26038
  this.startedAt = '';
26020
26039
  this.stoppedAt = '';
@@ -26056,7 +26075,7 @@ class RecorderBrowserSDK {
26056
26075
  return;
26057
26076
  }
26058
26077
  this._handleLiveSessionEvent(event, ts, sessionId, sessionType);
26059
- },
26078
+ }
26060
26079
  });
26061
26080
  this.takeFullSnapshot();
26062
26081
  this._setupPeriodicSnapshots(sessionId, sessionType);
@@ -26133,8 +26152,8 @@ class RecorderBrowserSDK {
26133
26152
  event: {
26134
26153
  event: packedEvent,
26135
26154
  eventType: event.type,
26136
- timestamp: ts,
26137
- },
26155
+ timestamp: ts
26156
+ }
26138
26157
  });
26139
26158
  }
26140
26159
  catch (error) {
@@ -26159,7 +26178,7 @@ class RecorderBrowserSDK {
26159
26178
  eventType: event.type,
26160
26179
  timestamp: ts,
26161
26180
  debugSessionId: sessionId,
26162
- debugSessionType: sessionType,
26181
+ debugSessionType: sessionType
26163
26182
  });
26164
26183
  }
26165
26184
  /**
@@ -26173,7 +26192,7 @@ class RecorderBrowserSDK {
26173
26192
  sampling: { canvas: 5 },
26174
26193
  recordCanvas: (_c = this.config) === null || _c === void 0 ? void 0 : _c.recordCanvas,
26175
26194
  dataURLOptions: { type: 'image/webp', quality: 0.1 },
26176
- plugins: [(0,_rrweb_rrweb_plugin_console_record__WEBPACK_IMPORTED_MODULE_3__.getRecordConsolePlugin)({ level: ['log', 'error'] })],
26195
+ plugins: [(0,_rrweb_rrweb_plugin_console_record__WEBPACK_IMPORTED_MODULE_3__.getRecordConsolePlugin)({ level: ['log', 'error'] })]
26177
26196
  };
26178
26197
  if (maskingConfig.maskInputOptions) {
26179
26198
  options.maskInputOptions = maskingConfig.maskInputOptions;
@@ -26206,7 +26225,7 @@ class RecorderBrowserSDK {
26206
26225
  }, _config__WEBPACK_IMPORTED_MODULE_5__.CONTINUOUS_DEBUGGING_TIMEOUT);
26207
26226
  }
26208
26227
  if (!sessionId && ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.buffering) === null || _b === void 0 ? void 0 : _b.enabled)) {
26209
- const interval = this.config.buffering.snapshotIntervalMs || 30000;
26228
+ const interval = this.config.buffering.snapshotIntervalMs || 20000;
26210
26229
  this.intervals.bufferSnapshot = setInterval(() => {
26211
26230
  this.takeFullSnapshot();
26212
26231
  }, interval);
@@ -26234,7 +26253,7 @@ class ApiService {
26234
26253
  this.config = {
26235
26254
  apiKey: '',
26236
26255
  apiBaseUrl: '',
26237
- exporterEndpoint: '',
26256
+ exporterEndpoint: ''
26238
26257
  };
26239
26258
  }
26240
26259
  /**
@@ -26244,7 +26263,7 @@ class ApiService {
26244
26263
  init(config) {
26245
26264
  this.config = {
26246
26265
  ...this.config,
26247
- ...config,
26266
+ ...config
26248
26267
  };
26249
26268
  }
26250
26269
  /**
@@ -26338,14 +26357,14 @@ class ApiService {
26338
26357
  body: body ? JSON.stringify(body) : null,
26339
26358
  headers: {
26340
26359
  'Content-Type': 'application/json',
26341
- ...(this.config.apiKey && { 'X-Api-Key': this.config.apiKey }),
26342
- },
26360
+ ...(this.config.apiKey && { 'X-Api-Key': this.config.apiKey })
26361
+ }
26343
26362
  };
26344
26363
  try {
26345
26364
  const response = await fetch(url, {
26346
26365
  ...params,
26347
26366
  credentials: 'include',
26348
- signal,
26367
+ signal
26349
26368
  });
26350
26369
  if (!response.ok) {
26351
26370
  throw new Error('Network response was not ok: ' + response.statusText);
@@ -26417,14 +26436,6 @@ class CrashBufferService {
26417
26436
  return fallback;
26418
26437
  }
26419
26438
  }
26420
- async setAttrs(attrs) {
26421
- await this._safe(async () => {
26422
- await this.db.setAttrs({
26423
- tabId: this.tabId,
26424
- ...attrs,
26425
- });
26426
- }, undefined);
26427
- }
26428
26439
  async appendEvent(payload, _windowMs) {
26429
26440
  var _a;
26430
26441
  this.lastSeenEventTs = Math.max(this.lastSeenEventTs, payload.ts || 0);
@@ -26433,26 +26444,15 @@ class CrashBufferService {
26433
26444
  const isFullSnapshot = Boolean(payload.isFullSnapshot);
26434
26445
  const eventType = (_a = payload === null || payload === void 0 ? void 0 : payload.event) === null || _a === void 0 ? void 0 : _a.eventType;
26435
26446
  const isMeta = eventType === _rrweb_types__WEBPACK_IMPORTED_MODULE_0__.EventType.Meta;
26436
- if (this.requiresFullSnapshot && !isFullSnapshot && !isMeta) {
26437
- // rrweb replayable prefix is Meta -> FullSnapshot.
26438
- // While waiting for the first FullSnapshot, we still keep the Meta event (but drop incrementals).
26439
- return;
26440
- }
26441
26447
  await this._safe(async () => {
26442
26448
  await this.db.appendEvent({
26443
26449
  tabId: this.tabId,
26444
26450
  ts: payload.ts,
26445
26451
  isFullSnapshot: payload.isFullSnapshot,
26446
- event: payload.event,
26452
+ event: payload.event
26447
26453
  });
26448
26454
  }, undefined);
26449
- if (isFullSnapshot && this.requiresFullSnapshot) {
26450
- // Ensure this snapshot becomes the first replayable event.
26451
- // Keep Meta + FullSnapshot (if present) and prune everything older.
26452
- await this._safe(() => this.db.pruneOlderThanWithRrwebSnapshotAnchor(this.tabId, payload.ts), undefined);
26453
- this.requiresFullSnapshot = false;
26454
- }
26455
- else if (isFullSnapshot) {
26455
+ if (isFullSnapshot) {
26456
26456
  this.requiresFullSnapshot = false;
26457
26457
  }
26458
26458
  this.pruneSoon();
@@ -26473,7 +26473,7 @@ class CrashBufferService {
26473
26473
  return {
26474
26474
  tabId: this.tabId,
26475
26475
  ts: p.ts,
26476
- span: p.span,
26476
+ span: p.span
26477
26477
  };
26478
26478
  });
26479
26479
  await this.db.appendSpans(records);
@@ -26513,71 +26513,50 @@ class CrashBufferService {
26513
26513
  }
26514
26514
  async snapshot(_windowMs, now = Date.now()) {
26515
26515
  var _a, _b;
26516
- const toTs = now;
26517
- const fromTs = Math.max(0, toTs - this.windowMs);
26516
+ const stoppedAt = now;
26517
+ let startedAt = Math.max(0, stoppedAt - this.windowMs);
26518
26518
  // Always include a full snapshot "anchor" if one exists at/before the window start.
26519
- const rrwebFromTs = await this._safe(async () => {
26520
- const anchor = await this.db.getLastRrwebFullSnapshotBefore(this.tabId, fromTs);
26521
- return typeof (anchor === null || anchor === void 0 ? void 0 : anchor.ts) === 'number' ? anchor.ts : fromTs;
26522
- }, fromTs);
26523
- const [rrweb, spans, attrs] = await Promise.all([
26524
- this._safe(() => this.db.getRrwebEventsWindow(this.tabId, rrwebFromTs, toTs), []),
26525
- this._safe(() => this.db.getOtelSpansWindow(this.tabId, fromTs, toTs), []),
26526
- this._safe(() => this.db.getAttrs(this.tabId), null),
26519
+ const firstSnapshotAt = await this._safe(async () => {
26520
+ const anchor = await this.db.getLastRrwebFullSnapshotBefore(this.tabId, startedAt);
26521
+ return typeof (anchor === null || anchor === void 0 ? void 0 : anchor.ts) === 'number' ? anchor.ts : startedAt;
26522
+ }, startedAt);
26523
+ const [allEvents, allSpans] = await Promise.all([
26524
+ this._safe(() => this.db.getRrwebEventsWindow(this.tabId, firstSnapshotAt, stoppedAt), []),
26525
+ this._safe(() => this.db.getOtelSpansWindow(this.tabId, startedAt, stoppedAt), [])
26527
26526
  ]);
26528
- const rrwebSorted = rrweb
26527
+ const eventsSorted = allEvents
26529
26528
  .sort((a, b) => a.ts - b.ts)
26530
26529
  .map((r) => ({ ts: r.ts, isFullSnapshot: r.isFullSnapshot, event: r.event }));
26530
+ const payload = {
26531
+ startedAt,
26532
+ stoppedAt,
26533
+ spans: [],
26534
+ events: []
26535
+ };
26531
26536
  // Hard guarantee: snapshot payload starts with Meta -> FullSnapshot (or is empty).
26532
- const firstFullSnapshotIdx = rrwebSorted.findIndex((e) => Boolean(e.isFullSnapshot));
26533
- if (firstFullSnapshotIdx < 0) {
26534
- return {
26535
- rrwebEvents: [],
26536
- otelSpans: [],
26537
- attrs: attrs
26538
- ? {
26539
- sessionAttributes: attrs.sessionAttributes,
26540
- resourceAttributes: attrs.resourceAttributes,
26541
- userAttributes: attrs.userAttributes,
26542
- }
26543
- : null,
26544
- windowMs: this.windowMs,
26545
- fromTs,
26546
- toTs,
26547
- };
26537
+ const firstSnapshotIdx = eventsSorted.findIndex((e) => Boolean(e.isFullSnapshot));
26538
+ if (firstSnapshotIdx < 0) {
26539
+ return payload;
26548
26540
  }
26549
26541
  // Prefer including the Meta event immediately preceding the first FullSnapshot.
26550
- let startIdx = firstFullSnapshotIdx;
26551
- for (let i = firstFullSnapshotIdx - 1; i >= 0; i--) {
26552
- const t = (_b = (_a = rrwebSorted[i]) === null || _a === void 0 ? void 0 : _a.event) === null || _b === void 0 ? void 0 : _b.eventType;
26542
+ let startIdx = firstSnapshotIdx;
26543
+ for (let i = firstSnapshotIdx - 1; i >= 0; i--) {
26544
+ const t = (_b = (_a = eventsSorted[i]) === null || _a === void 0 ? void 0 : _a.event) === null || _b === void 0 ? void 0 : _b.eventType;
26553
26545
  if (t === _rrweb_types__WEBPACK_IMPORTED_MODULE_0__.EventType.Meta) {
26554
26546
  startIdx = i;
26555
26547
  break;
26556
26548
  }
26557
26549
  }
26558
- const rrwebEvents = rrwebSorted.slice(startIdx);
26559
- // Align spans with the rrweb replay start (Meta if present, otherwise FullSnapshot).
26560
- // Important: we return `fromTs` to consumers and many UIs compute relative offsets from it,
26561
- // so `fromTs` must match the first rrweb event timestamp we return.
26562
- const replayStartTs = rrwebEvents.length > 0 ? rrwebEvents[0].ts : fromTs;
26563
- const otelSpans = spans
26564
- .filter((s) => typeof (s === null || s === void 0 ? void 0 : s.ts) === 'number' && s.ts >= replayStartTs)
26550
+ const events = eventsSorted.slice(startIdx);
26551
+ const replayStartedAt = events.length > 0 ? events[0].ts : startedAt;
26552
+ const spans = allSpans
26553
+ .filter((s) => typeof (s === null || s === void 0 ? void 0 : s.ts) === 'number' && s.ts >= replayStartedAt)
26565
26554
  .sort((a, b) => a.ts - b.ts)
26566
26555
  .map((r) => ({ ts: r.ts, span: r.span }));
26567
- return {
26568
- rrwebEvents,
26569
- otelSpans,
26570
- attrs: attrs
26571
- ? {
26572
- sessionAttributes: attrs.sessionAttributes,
26573
- resourceAttributes: attrs.resourceAttributes,
26574
- userAttributes: attrs.userAttributes,
26575
- }
26576
- : null,
26577
- windowMs: this.windowMs,
26578
- fromTs: replayStartTs,
26579
- toTs,
26580
- };
26556
+ payload.events = events;
26557
+ payload.spans = spans;
26558
+ payload.startedAt = replayStartedAt;
26559
+ return payload;
26581
26560
  }
26582
26561
  async clear() {
26583
26562
  await this._safe(() => this.db.clearTab(this.tabId), undefined);
@@ -26731,7 +26710,7 @@ class IndexedDBService {
26731
26710
  const db = await this.dbPromise;
26732
26711
  const payload = {
26733
26712
  ...attrs,
26734
- updatedAt: (_a = attrs.updatedAt) !== null && _a !== void 0 ? _a : Date.now(),
26713
+ updatedAt: (_a = attrs.updatedAt) !== null && _a !== void 0 ? _a : Date.now()
26735
26714
  };
26736
26715
  return new Promise((resolve, reject) => {
26737
26716
  const tx = db.transaction(attrsStore, 'readwrite');
@@ -27017,7 +26996,7 @@ class IndexedDBService {
27017
26996
  const r = attr.delete(tabId);
27018
26997
  r.onsuccess = () => res();
27019
26998
  r.onerror = () => rej(r.error);
27020
- }),
26999
+ })
27021
27000
  ])
27022
27001
  .then(() => {
27023
27002
  // noop
@@ -27174,7 +27153,7 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27174
27153
  apiKey: '',
27175
27154
  socketUrl: '',
27176
27155
  keepAlive: false,
27177
- usePostMessageFallback: false,
27156
+ usePostMessageFallback: false
27178
27157
  };
27179
27158
  }
27180
27159
  /**
@@ -27184,11 +27163,9 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27184
27163
  init(config) {
27185
27164
  this.options = {
27186
27165
  ...this.options,
27187
- ...config,
27166
+ ...config
27188
27167
  };
27189
- if (this.options.keepAlive &&
27190
- this.options.socketUrl &&
27191
- this.options.apiKey) {
27168
+ if (this.options.keepAlive && this.options.socketUrl && this.options.apiKey) {
27192
27169
  this._initConnection();
27193
27170
  }
27194
27171
  }
@@ -27201,16 +27178,13 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27201
27178
  // If any config changed, reconnect if connected
27202
27179
  const hasChanges = Object.keys(config).some((key) => {
27203
27180
  const typedKey = key;
27204
- return (config[typedKey] !== undefined &&
27205
- config[typedKey] !== this.options[typedKey]);
27181
+ return config[typedKey] !== undefined && config[typedKey] !== this.options[typedKey];
27206
27182
  });
27207
27183
  if (hasChanges) {
27208
27184
  this.options = { ...this.options, ...config };
27209
27185
  if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
27210
27186
  this.close().then(() => {
27211
- if (this.options.keepAlive &&
27212
- this.options.socketUrl &&
27213
- this.options.apiKey) {
27187
+ if (this.options.keepAlive && this.options.socketUrl && this.options.apiKey) {
27214
27188
  this._initConnection();
27215
27189
  }
27216
27190
  });
@@ -27227,12 +27201,10 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27227
27201
  path: '/v0/radar/ws',
27228
27202
  auth: {
27229
27203
  'x-api-key': this.options.apiKey,
27230
- ...this.options.clientId
27231
- ? { [_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_3__.ATTR_MULTIPLAYER_SESSION_CLIENT_ID]: this.options.clientId }
27232
- : {},
27204
+ ...(this.options.clientId ? { [_multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_3__.ATTR_MULTIPLAYER_SESSION_CLIENT_ID]: this.options.clientId } : {})
27233
27205
  },
27234
27206
  reconnectionAttempts: 2,
27235
- transports: ['websocket'],
27207
+ transports: ['websocket']
27236
27208
  });
27237
27209
  this.socket.on('ready', () => {
27238
27210
  this.isConnecting = false;
@@ -27309,7 +27281,7 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27309
27281
  projectId: session.project,
27310
27282
  workspaceId: session.workspace,
27311
27283
  debugSessionId: this.sessionId,
27312
- sessionType: session.creationType,
27284
+ sessionType: session.creationType
27313
27285
  };
27314
27286
  this.emitSocketEvent(_config__WEBPACK_IMPORTED_MODULE_2__.SESSION_SUBSCRIBE_EVENT, payload);
27315
27287
  // use long id instead of short id
@@ -27323,8 +27295,8 @@ class SocketService extends lib0_observable__WEBPACK_IMPORTED_MODULE_4__.Observa
27323
27295
  }
27324
27296
  }
27325
27297
  }
27326
- setUser(userAttributes) {
27327
- this.emitSocketEvent(_config__WEBPACK_IMPORTED_MODULE_2__.SOCKET_SET_USER_EVENT, userAttributes);
27298
+ setUser(data) {
27299
+ this.emitSocketEvent(_config__WEBPACK_IMPORTED_MODULE_2__.SOCKET_SET_USER_EVENT, data);
27328
27300
  }
27329
27301
  close() {
27330
27302
  return new Promise((resolve) => {
@@ -27539,7 +27511,7 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
27539
27511
  this._checkOperation('init');
27540
27512
  // GC: remove orphaned crash buffers from old tabs.
27541
27513
  // Keep TTL large to avoid any accidental data loss.
27542
- void this._bufferDb.sweepStaleTabs(24 * 60 * 60 * 1000);
27514
+ void this._bufferDb.sweepStaleTabs(10 * 60 * 60 * 1000);
27543
27515
  (0,_patch__WEBPACK_IMPORTED_MODULE_6__.setMaxCapturingHttpPayloadSize)(this._configs.maxCapturingHttpPayloadSize || _config__WEBPACK_IMPORTED_MODULE_5__.DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE);
27544
27516
  (0,_patch__WEBPACK_IMPORTED_MODULE_6__.setShouldRecordHttpData)(this._configs.captureBody, this._configs.captureHeaders);
27545
27517
  this._setupCrashBuffer();
@@ -27578,22 +27550,16 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
27578
27550
  _setupCrashBuffer() {
27579
27551
  var _a;
27580
27552
  if ((_a = this._configs.buffering) === null || _a === void 0 ? void 0 : _a.enabled) {
27581
- const windowMinutes = this._configs.buffering.windowMinutes || 1;
27553
+ const windowMinutes = this._configs.buffering.windowMinutes || 0.5;
27582
27554
  const windowMs = Math.max(10000, windowMinutes * 60 * 1000);
27583
27555
  this._crashBuffer = new _services_crashBuffer_service__WEBPACK_IMPORTED_MODULE_13__.CrashBufferService(this._bufferDb, this._tabId, windowMs);
27584
27556
  this._recorder.setCrashBuffer(this._crashBuffer);
27585
27557
  this._tracer.setCrashBuffer(this._crashBuffer);
27586
- this._crashBuffer.setAttrs({
27587
- sessionAttributes: this.sessionAttributes,
27588
- resourceAttributes: (0,_utils__WEBPACK_IMPORTED_MODULE_3__.getNavigatorInfo)(),
27589
- userAttributes: this._userAttributes
27590
- });
27591
27558
  this._crashBuffer.on('error-span-appended', (payload) => {
27592
27559
  if (this.sessionState !== _types__WEBPACK_IMPORTED_MODULE_4__.SessionState.stopped || this.sessionId)
27593
27560
  return;
27594
27561
  if (!payload.span)
27595
27562
  return;
27596
- console.log('error-span-appended', payload);
27597
27563
  this._createExceptionSession(payload.span);
27598
27564
  });
27599
27565
  this._registerCrashBufferLifecycleHandlers();
@@ -27638,13 +27604,12 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
27638
27604
  }
27639
27605
  _startBufferOnlyRecording() {
27640
27606
  var _a, _b;
27641
- if (!((_b = (_a = this._configs) === null || _a === void 0 ? void 0 : _a.buffering) === null || _b === void 0 ? void 0 : _b.enabled))
27642
- return;
27643
- if (!this._crashBuffer)
27644
- return;
27645
- // Don’t start if a session is active.
27646
- if (this.sessionState !== _types__WEBPACK_IMPORTED_MODULE_4__.SessionState.stopped || this.sessionId)
27607
+ if (this.sessionId ||
27608
+ !this._crashBuffer ||
27609
+ !((_b = (_a = this._configs) === null || _a === void 0 ? void 0 : _a.buffering) === null || _b === void 0 ? void 0 : _b.enabled) ||
27610
+ this.sessionState !== _types__WEBPACK_IMPORTED_MODULE_4__.SessionState.stopped) {
27647
27611
  return;
27612
+ }
27648
27613
  void this._recorder.restart(null, _multiplayer_app_session_recorder_common__WEBPACK_IMPORTED_MODULE_0__.SessionType.MANUAL);
27649
27614
  }
27650
27615
  /**
@@ -27791,7 +27756,11 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
27791
27756
  return;
27792
27757
  }
27793
27758
  this._userAttributes = userAttributes;
27794
- this._socketService.setUser(this._userAttributes);
27759
+ const data = {
27760
+ userAttributes: this._userAttributes,
27761
+ clientId: this._tracer.clientId
27762
+ };
27763
+ this._socketService.setUser(data);
27795
27764
  }
27796
27765
  /**
27797
27766
  * Updates the button click handler in the library.
@@ -27818,37 +27787,30 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
27818
27787
  }
27819
27788
  async _flushBuffer(sessionId) {
27820
27789
  var _a, _b;
27821
- if (!((_b = (_a = this._configs) === null || _a === void 0 ? void 0 : _a.buffering) === null || _b === void 0 ? void 0 : _b.enabled))
27822
- return null;
27823
- if (!this._crashBuffer)
27824
- return null;
27825
- if (this._isFlushingBuffer)
27826
- return null;
27827
- // Don’t flush while a live recording is active.
27828
- if (this.sessionState !== _types__WEBPACK_IMPORTED_MODULE_4__.SessionState.stopped)
27790
+ if (!sessionId ||
27791
+ !this._crashBuffer ||
27792
+ this._isFlushingBuffer ||
27793
+ !((_b = (_a = this._configs) === null || _a === void 0 ? void 0 : _a.buffering) === null || _b === void 0 ? void 0 : _b.enabled) ||
27794
+ this.sessionState !== _types__WEBPACK_IMPORTED_MODULE_4__.SessionState.stopped) {
27829
27795
  return null;
27796
+ }
27830
27797
  this._isFlushingBuffer = true;
27831
27798
  try {
27832
- const snapshot = await this._crashBuffer.snapshot();
27833
- if (snapshot.rrwebEvents.length === 0 && snapshot.otelSpans.length === 0) {
27799
+ const { events, spans, startedAt, stoppedAt } = await this._crashBuffer.snapshot();
27800
+ if (events.length === 0 && spans.length === 0) {
27834
27801
  return null;
27835
27802
  }
27836
- if (sessionId) {
27837
- const spans = snapshot.otelSpans.map((s) => s.span);
27838
- const events = snapshot.rrwebEvents.map((e) => e.event);
27839
- await Promise.all([
27840
- this._tracer.exportTraces(spans),
27841
- this._apiService.exportEvents(sessionId, { events }),
27842
- this._apiService.updateSessionAttributes(sessionId, {
27843
- name: this._getSessionName(),
27844
- // startedAt: new Date(snapshot.rrwebEvents[0].ts).toISOString(),
27845
- // stoppedAt: new Date().toISOString(),
27846
- sessionAttributes: this.sessionAttributes,
27847
- resourceAttributes: (0,_utils__WEBPACK_IMPORTED_MODULE_3__.getNavigatorInfo)(),
27848
- userAttributes: this._userAttributes || undefined
27849
- })
27850
- ]);
27851
- }
27803
+ await Promise.all([
27804
+ this._tracer.exportTraces(spans.map((s) => s.span)),
27805
+ this._apiService.exportEvents(sessionId, { events: events.map((e) => e.event) }),
27806
+ this._apiService.updateSessionAttributes(sessionId, {
27807
+ startedAt: new Date(startedAt).toISOString(),
27808
+ stoppedAt: new Date(stoppedAt).toISOString(),
27809
+ sessionAttributes: this.sessionAttributes,
27810
+ resourceAttributes: (0,_utils__WEBPACK_IMPORTED_MODULE_3__.getNavigatorInfo)(),
27811
+ userAttributes: this._userAttributes || undefined
27812
+ })
27813
+ ]);
27852
27814
  }
27853
27815
  catch (_e) {
27854
27816
  // swallow: flush is best-effort; never throw into app code
@@ -28019,19 +27981,14 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
28019
27981
  });
28020
27982
  this._socketService.on(_config__WEBPACK_IMPORTED_MODULE_5__.SESSION_SAVE_BUFFER_EVENT, (payload) => {
28021
27983
  var _a;
28022
- if (!((_a = payload === null || payload === void 0 ? void 0 : payload.debugSession) === null || _a === void 0 ? void 0 : _a._id))
28023
- return;
28024
- void this._flushBuffer(payload.debugSession._id);
27984
+ this._flushBuffer((_a = payload === null || payload === void 0 ? void 0 : payload.debugSession) === null || _a === void 0 ? void 0 : _a._id);
28025
27985
  });
28026
27986
  }
28027
27987
  async _createExceptionSession(span) {
28028
27988
  try {
28029
27989
  const session = await this._apiService.createErrorSession({ span });
28030
- console.log('====================================');
28031
- console.log(span);
28032
- console.log('====================================');
28033
- if (session) {
28034
- void this._flushBuffer(session._id);
27990
+ if (session === null || session === void 0 ? void 0 : session._id) {
27991
+ this._flushBuffer(session._id);
28035
27992
  }
28036
27993
  }
28037
27994
  catch (_ignored) { }