@amplitude/session-replay-browser 1.47.0-sr-trc-debug-log.0 → 1.47.0-sr-trc-debug-log.2
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/lib/cjs/config/joined-config.d.ts.map +1 -1
- package/lib/cjs/config/joined-config.js +23 -19
- package/lib/cjs/config/joined-config.js.map +1 -1
- package/lib/cjs/diagnostics.d.ts +5 -0
- package/lib/cjs/diagnostics.d.ts.map +1 -1
- package/lib/cjs/diagnostics.js +11 -1
- package/lib/cjs/diagnostics.js.map +1 -1
- package/lib/cjs/plugins/url-tracking-plugin.d.ts +6 -0
- package/lib/cjs/plugins/url-tracking-plugin.d.ts.map +1 -1
- package/lib/cjs/plugins/url-tracking-plugin.js +3 -1
- package/lib/cjs/plugins/url-tracking-plugin.js.map +1 -1
- package/lib/cjs/session-replay.d.ts +7 -0
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +123 -26
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/cjs/targeting/targeting-manager.d.ts.map +1 -1
- package/lib/cjs/targeting/targeting-manager.js +28 -15
- package/lib/cjs/targeting/targeting-manager.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/config/joined-config.d.ts.map +1 -1
- package/lib/esm/config/joined-config.js +23 -19
- package/lib/esm/config/joined-config.js.map +1 -1
- package/lib/esm/diagnostics.d.ts +5 -0
- package/lib/esm/diagnostics.d.ts.map +1 -1
- package/lib/esm/diagnostics.js +11 -1
- package/lib/esm/diagnostics.js.map +1 -1
- package/lib/esm/plugins/url-tracking-plugin.d.ts +6 -0
- package/lib/esm/plugins/url-tracking-plugin.d.ts.map +1 -1
- package/lib/esm/plugins/url-tracking-plugin.js +3 -1
- package/lib/esm/plugins/url-tracking-plugin.js.map +1 -1
- package/lib/esm/session-replay.d.ts +7 -0
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +123 -26
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/esm/targeting/targeting-manager.d.ts.map +1 -1
- package/lib/esm/targeting/targeting-manager.js +28 -15
- package/lib/esm/targeting/targeting-manager.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/index-min.js +1 -1
- package/lib/scripts/index-min.js.gz +0 -0
- package/lib/scripts/index-min.js.map +1 -1
- package/lib/scripts/session-replay-browser-min.js +1 -1
- package/lib/scripts/session-replay-browser-min.js.gz +0 -0
- package/lib/scripts/session-replay-browser-min.js.map +1 -1
- package/package.json +3 -3
|
@@ -172,6 +172,17 @@ var SessionReplay = /** @class */ (function () {
|
|
|
172
172
|
}
|
|
173
173
|
pageUrl = (_f = (_c = (_b = targetingParams.page) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : (_e = (_d = (0, analytics_core_1.getGlobalScope)()) === null || _d === void 0 ? void 0 : _d.location) === null || _e === void 0 ? void 0 : _e.href) !== null && _f !== void 0 ? _f : '';
|
|
174
174
|
pageForTargeting = (_g = targetingParams.page) !== null && _g !== void 0 ? _g : (pageUrl !== '' ? { url: pageUrl } : undefined);
|
|
175
|
+
// Record the targeting trigger event
|
|
176
|
+
this.recordDiagnosticEvent(diagnostics_1.SrDiagnostic.targetingTrigger, {
|
|
177
|
+
sessionId: this.identifiers.sessionId,
|
|
178
|
+
deviceId: this.getDeviceId(),
|
|
179
|
+
targetingConfig: this.config.targetingConfig,
|
|
180
|
+
targetingParams: {
|
|
181
|
+
userProperties: targetingParams.userProperties,
|
|
182
|
+
event: eventForTargeting,
|
|
183
|
+
page: pageForTargeting,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
175
186
|
evalStart = Date.now();
|
|
176
187
|
return [4 /*yield*/, (0, targeting_manager_1.evaluateTargetingAndStore)({
|
|
177
188
|
sessionId: this.identifiers.sessionId,
|
|
@@ -329,12 +340,17 @@ var SessionReplay = /** @class */ (function () {
|
|
|
329
340
|
*/
|
|
330
341
|
SessionReplay.prototype.setupUrlChangeListener = function () {
|
|
331
342
|
var _this = this;
|
|
332
|
-
var _a, _b;
|
|
343
|
+
var _a, _b, _c, _d, _e, _f;
|
|
333
344
|
// If init() runs multiple times, remove the previous URL-change subscription first
|
|
334
345
|
// so we don't leak callbacks and trigger duplicate targeting evaluations.
|
|
335
346
|
(_a = this.urlChangeCleanup) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
336
347
|
var globalScope = (0, analytics_core_1.getGlobalScope)();
|
|
337
348
|
if (!(globalScope === null || globalScope === void 0 ? void 0 : globalScope.location)) {
|
|
349
|
+
// No window/location (SSR, worker, or pre-render) — the listener can't attach, so TRC will
|
|
350
|
+
// never re-evaluate on navigation. Surface it rather than failing silently.
|
|
351
|
+
this.incrementDiagnostic(diagnostics_1.SrDiagnostic.urlListenerSkipped);
|
|
352
|
+
this.recordDiagnosticEvent(diagnostics_1.SrDiagnostic.urlListenerSkipped, { reason: 'no_global_scope' });
|
|
353
|
+
this.loggerProvider.debug('URL-change listener not attached: no global scope/location.');
|
|
338
354
|
return;
|
|
339
355
|
}
|
|
340
356
|
var hasTargeting = !!((_b = this.config) === null || _b === void 0 ? void 0 : _b.targetingConfig);
|
|
@@ -359,7 +375,27 @@ var SessionReplay = /** @class */ (function () {
|
|
|
359
375
|
_this.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(evaluationId, " for ").concat(href, "."));
|
|
360
376
|
}
|
|
361
377
|
};
|
|
362
|
-
|
|
378
|
+
// Pass the polling options so targeting re-evaluation also respects `enableUrlChangePolling`.
|
|
379
|
+
// Without this, the targeting listener only sees history.pushState/replaceState + popstate +
|
|
380
|
+
// hashchange — so SPA navigations that bypass the history API never re-evaluate TRC and
|
|
381
|
+
// recording never starts on the new URL (enableUrlChangePolling previously only affected the
|
|
382
|
+
// rrweb URL-tracking plugin, which runs only once recording is already active).
|
|
383
|
+
var enablePolling = (_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.enableUrlChangePolling) !== null && _d !== void 0 ? _d : false;
|
|
384
|
+
var unsubscribe = (0, url_tracking_plugin_1.subscribeToUrlChanges)(globalScope, onUrlChange, {
|
|
385
|
+
enablePolling: enablePolling,
|
|
386
|
+
pollingInterval: (_e = this.config) === null || _e === void 0 ? void 0 : _e.urlChangePollingInterval,
|
|
387
|
+
// Mirror each poll tick to the console (Debug level) so we can confirm polling is firing.
|
|
388
|
+
log: this.loggerProvider.debug.bind(this.loggerProvider),
|
|
389
|
+
});
|
|
390
|
+
// Confirm the listener is actually live, and under what settings — if recording never starts on
|
|
391
|
+
// navigation, this tells us whether the listener existed and whether polling (the fallback for
|
|
392
|
+
// SPAs that bypass the History API) was on.
|
|
393
|
+
this.recordDiagnosticEvent(diagnostics_1.SrDiagnostic.urlListenerAttached, {
|
|
394
|
+
hasTargeting: hasTargeting,
|
|
395
|
+
enablePolling: enablePolling,
|
|
396
|
+
pollingInterval: (_f = this.config) === null || _f === void 0 ? void 0 : _f.urlChangePollingInterval,
|
|
397
|
+
});
|
|
398
|
+
this.loggerProvider.debug("URL-change listener attached (polling: ".concat(String(enablePolling), ")."));
|
|
363
399
|
this.urlChangeCleanup = function () {
|
|
364
400
|
unsubscribe();
|
|
365
401
|
_this.urlChangeCleanup = null;
|
|
@@ -388,14 +424,34 @@ var SessionReplay = /** @class */ (function () {
|
|
|
388
424
|
var currentUrl = (_b = (_a = (0, analytics_core_1.getGlobalScope)()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href;
|
|
389
425
|
return currentUrl != null ? { url: currentUrl } : undefined;
|
|
390
426
|
};
|
|
427
|
+
/**
|
|
428
|
+
* Best-effort navigation type from the Navigation Timing API: 'reload' | 'navigate' |
|
|
429
|
+
* 'back_forward' | 'prerender'. Surfaced in the init diagnostic so a page refresh ('reload')
|
|
430
|
+
* is distinguishable from a fresh load ('navigate') — neither changes the session id, so this
|
|
431
|
+
* is the only way to tell them apart. Returns undefined when the API is unavailable.
|
|
432
|
+
*/
|
|
433
|
+
SessionReplay.prototype.getNavigationType = function () {
|
|
434
|
+
try {
|
|
435
|
+
var globalScope = (0, analytics_core_1.getGlobalScope)();
|
|
436
|
+
var performance_1 = globalScope && globalScope.performance;
|
|
437
|
+
if (!performance_1 || typeof performance_1.getEntriesByType !== 'function') {
|
|
438
|
+
return undefined;
|
|
439
|
+
}
|
|
440
|
+
var navEntries = performance_1.getEntriesByType('navigation');
|
|
441
|
+
return navEntries.length > 0 ? navEntries[0].type : undefined;
|
|
442
|
+
}
|
|
443
|
+
catch (_a) {
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
391
447
|
SessionReplay.prototype._init = function (apiKey, options) {
|
|
392
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
448
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
393
449
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
394
|
-
var now,
|
|
395
|
-
var e_2,
|
|
450
|
+
var now, _u, _v, joinedConfig, localConfig, remoteConfig, scrollWatcher, managers, storeType, compressionWorkerScript, trackDestinationWorkerScript, globalScope, _w, compressionScript, trackDestinationScript, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError, onFullSnapshotProcessed, pending_2, pending_1, pending_1_1, _x, event_1, sessionId, messenger, needsUrlTracking;
|
|
451
|
+
var e_2, _y;
|
|
396
452
|
var _this = this;
|
|
397
|
-
return tslib_1.__generator(this, function (
|
|
398
|
-
switch (
|
|
453
|
+
return tslib_1.__generator(this, function (_z) {
|
|
454
|
+
switch (_z.label) {
|
|
399
455
|
case 0:
|
|
400
456
|
// Re-init should always tear down any previous URL-change subscription, even when the
|
|
401
457
|
// next config has no targeting config and we don't subscribe again.
|
|
@@ -411,13 +467,13 @@ var SessionReplay = /** @class */ (function () {
|
|
|
411
467
|
options.sessionId !== undefined
|
|
412
468
|
? (_b = (0, replay_start_time_store_1.getOrInitReplayStartTime)(apiKey, options.sessionId, now, this.loggerProvider)) !== null && _b !== void 0 ? _b : now
|
|
413
469
|
: now;
|
|
414
|
-
|
|
470
|
+
_u = this;
|
|
415
471
|
return [4 /*yield*/, (0, joined_config_1.createSessionReplayJoinedConfigGenerator)(apiKey, options)];
|
|
416
472
|
case 1:
|
|
417
|
-
|
|
473
|
+
_u.joinedConfigGenerator = _z.sent();
|
|
418
474
|
return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig()];
|
|
419
475
|
case 2:
|
|
420
|
-
|
|
476
|
+
_v = _z.sent(), joinedConfig = _v.joinedConfig, localConfig = _v.localConfig, remoteConfig = _v.remoteConfig;
|
|
421
477
|
this.config = joinedConfig;
|
|
422
478
|
this.setMetadata(options.sessionId, joinedConfig, localConfig, remoteConfig, (_c = options.version) === null || _c === void 0 ? void 0 : _c.version, version_1.VERSION, (_d = options.version) === null || _d === void 0 ? void 0 : _d.type);
|
|
423
479
|
this.pageLeaveFns = [];
|
|
@@ -441,12 +497,12 @@ var SessionReplay = /** @class */ (function () {
|
|
|
441
497
|
if (!(this.config.useWebWorker && globalScope && globalScope.Worker)) return [3 /*break*/, 4];
|
|
442
498
|
return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('./worker')); })];
|
|
443
499
|
case 3:
|
|
444
|
-
|
|
500
|
+
_w = _z.sent(), compressionScript = _w.compressionScript, trackDestinationScript = _w.trackDestinationScript;
|
|
445
501
|
compressionWorkerScript = compressionScript;
|
|
446
502
|
trackDestinationWorkerScript = trackDestinationScript;
|
|
447
|
-
|
|
503
|
+
_z.label = 4;
|
|
448
504
|
case 4:
|
|
449
|
-
|
|
505
|
+
_z.trys.push([4, 6, , 7]);
|
|
450
506
|
return [4 /*yield*/, (0, events_manager_1.createEventsManager)({
|
|
451
507
|
config: this.config,
|
|
452
508
|
type: 'replay',
|
|
@@ -458,21 +514,21 @@ var SessionReplay = /** @class */ (function () {
|
|
|
458
514
|
shouldSend: function () { return !_this.isBelowMinSessionDuration(); },
|
|
459
515
|
})];
|
|
460
516
|
case 5:
|
|
461
|
-
rrwebEventManager =
|
|
517
|
+
rrwebEventManager = _z.sent();
|
|
462
518
|
this.rrwebEventManager = rrwebEventManager;
|
|
463
519
|
managers.push({ name: 'replay', manager: rrwebEventManager });
|
|
464
520
|
return [3 /*break*/, 7];
|
|
465
521
|
case 6:
|
|
466
|
-
error_1 =
|
|
522
|
+
error_1 = _z.sent();
|
|
467
523
|
typedError = error_1;
|
|
468
524
|
this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(typedError.toString()));
|
|
469
525
|
return [3 /*break*/, 7];
|
|
470
526
|
case 7:
|
|
471
527
|
if (!((_j = this.config.interactionConfig) === null || _j === void 0 ? void 0 : _j.enabled)) return [3 /*break*/, 11];
|
|
472
528
|
payloadBatcher = this.config.interactionConfig.batch ? click_1.clickBatcher : click_1.clickNonBatcher;
|
|
473
|
-
|
|
529
|
+
_z.label = 8;
|
|
474
530
|
case 8:
|
|
475
|
-
|
|
531
|
+
_z.trys.push([8, 10, , 11]);
|
|
476
532
|
return [4 /*yield*/, (0, events_manager_1.createEventsManager)({
|
|
477
533
|
config: this.config,
|
|
478
534
|
type: 'interaction',
|
|
@@ -484,11 +540,11 @@ var SessionReplay = /** @class */ (function () {
|
|
|
484
540
|
trackDestinationWorkerScript: trackDestinationWorkerScript,
|
|
485
541
|
})];
|
|
486
542
|
case 9:
|
|
487
|
-
interactionEventManager =
|
|
543
|
+
interactionEventManager = _z.sent();
|
|
488
544
|
managers.push({ name: 'interaction', manager: interactionEventManager });
|
|
489
545
|
return [3 /*break*/, 11];
|
|
490
546
|
case 10:
|
|
491
|
-
error_2 =
|
|
547
|
+
error_2 = _z.sent();
|
|
492
548
|
typedError = error_2;
|
|
493
549
|
this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(typedError.toString()));
|
|
494
550
|
return [3 /*break*/, 11];
|
|
@@ -506,14 +562,14 @@ var SessionReplay = /** @class */ (function () {
|
|
|
506
562
|
pending_2 = this.pendingEmitEvents.splice(0);
|
|
507
563
|
try {
|
|
508
564
|
for (pending_1 = tslib_1.__values(pending_2), pending_1_1 = pending_1.next(); !pending_1_1.done; pending_1_1 = pending_1.next()) {
|
|
509
|
-
|
|
565
|
+
_x = pending_1_1.value, event_1 = _x.event, sessionId = _x.sessionId;
|
|
510
566
|
this.eventCompressor.enqueueEvent(event_1, sessionId);
|
|
511
567
|
}
|
|
512
568
|
}
|
|
513
569
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
514
570
|
finally {
|
|
515
571
|
try {
|
|
516
|
-
if (pending_1_1 && !pending_1_1.done && (
|
|
572
|
+
if (pending_1_1 && !pending_1_1.done && (_y = pending_1.return)) _y.call(pending_1);
|
|
517
573
|
}
|
|
518
574
|
finally { if (e_2) throw e_2.error; }
|
|
519
575
|
}
|
|
@@ -550,7 +606,7 @@ var SessionReplay = /** @class */ (function () {
|
|
|
550
606
|
], false);
|
|
551
607
|
return [4 /*yield*/, this.initializeNetworkObservers()];
|
|
552
608
|
case 12:
|
|
553
|
-
|
|
609
|
+
_z.sent();
|
|
554
610
|
// Enable background capture when this page is opened by the Amplitude app
|
|
555
611
|
// (window.opener exists). Uses the shared messenger singleton so that if
|
|
556
612
|
// autocapture is also loaded, both share a single messenger and script load.
|
|
@@ -572,11 +628,27 @@ var SessionReplay = /** @class */ (function () {
|
|
|
572
628
|
sampleRate: this.config.sampleRate,
|
|
573
629
|
optOut: this.shouldOptOut(),
|
|
574
630
|
currentUrl: (_m = this.getCurrentPageForTargeting()) === null || _m === void 0 ? void 0 : _m.url,
|
|
631
|
+
// 'reload' tells a page refresh apart from a fresh load ('navigate') or back/forward
|
|
632
|
+
// ('back_forward'). New tabs and refreshes keep the same session id, so this is the only
|
|
633
|
+
// way to distinguish a refresh from a brand-new init within a session.
|
|
634
|
+
navigationType: this.getNavigationType(),
|
|
575
635
|
});
|
|
576
636
|
return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options.userProperties, page: this.getCurrentPageForTargeting() }, true)];
|
|
577
637
|
case 13:
|
|
578
|
-
|
|
638
|
+
_z.sent();
|
|
579
639
|
needsUrlTracking = this.config.targetingConfig || ((_q = (_p = (_o = this.config.privacyConfig) === null || _o === void 0 ? void 0 : _o.urlMaskLevels) === null || _p === void 0 ? void 0 : _p.length) !== null && _q !== void 0 ? _q : 0) > 0;
|
|
640
|
+
// Record whether we even attempt to wire up the URL-change listener, and the inputs behind that
|
|
641
|
+
// decision. If `needsUrlTracking` is false the listener is never attached, so SPA navigations are
|
|
642
|
+
// invisible to TRC — this is the first thing to check when "TRC is on but never re-evaluates".
|
|
643
|
+
this.recordDiagnosticEvent(diagnostics_1.SrDiagnostic.urlListenerSetup, {
|
|
644
|
+
needsUrlTracking: !!needsUrlTracking,
|
|
645
|
+
hasTargetingConfig: !!this.config.targetingConfig,
|
|
646
|
+
urlMaskLevels: (_t = (_s = (_r = this.config.privacyConfig) === null || _r === void 0 ? void 0 : _r.urlMaskLevels) === null || _s === void 0 ? void 0 : _s.length) !== null && _t !== void 0 ? _t : 0,
|
|
647
|
+
// config always defaults this to a boolean (see local-config), so no `?? false` needed here.
|
|
648
|
+
enableUrlChangePolling: this.config.enableUrlChangePolling,
|
|
649
|
+
urlChangePollingInterval: this.config.urlChangePollingInterval,
|
|
650
|
+
});
|
|
651
|
+
this.loggerProvider.debug("URL-change listener needed: ".concat(String(!!needsUrlTracking), "."));
|
|
580
652
|
if (needsUrlTracking) {
|
|
581
653
|
this.setupUrlChangeListener();
|
|
582
654
|
}
|
|
@@ -616,6 +688,18 @@ var SessionReplay = /** @class */ (function () {
|
|
|
616
688
|
this.sendEvents(previousSessionId);
|
|
617
689
|
}
|
|
618
690
|
isSessionChange = previousSessionId !== sessionId;
|
|
691
|
+
// A real session transition (not the first set): recording stops/restarts and targeting is
|
|
692
|
+
// re-evaluated here, so session churn (timeout, multi-tab custom ids, explicit setSessionId)
|
|
693
|
+
// is a prime suspect for "sometimes records, sometimes not". recordDiagnosticEvent ships to
|
|
694
|
+
// DataDog AND mirrors to loggerProvider.debug. New tabs / refreshes keep the same id and won't
|
|
695
|
+
// hit this — use the init diagnostic's navigationType for those.
|
|
696
|
+
if (isSessionChange && previousSessionId !== undefined) {
|
|
697
|
+
this.recordDiagnosticEvent(diagnostics_1.SrDiagnostic.sessionChanged, {
|
|
698
|
+
from: previousSessionId,
|
|
699
|
+
to: sessionId,
|
|
700
|
+
deviceIdChanged: deviceId !== undefined && deviceId !== currentDeviceId,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
619
703
|
// Drop any beacon-buffered events from the previous session BEFORE installing the
|
|
620
704
|
// new identifiers / start time. Otherwise the page-leave beacon path could attribute
|
|
621
705
|
// old-session events to the new session id, and the gate (using the new start time)
|
|
@@ -780,6 +864,9 @@ var SessionReplay = /** @class */ (function () {
|
|
|
780
864
|
SessionReplay.prototype.incrementDiagnostic = function (counter) {
|
|
781
865
|
var _a, _b;
|
|
782
866
|
try {
|
|
867
|
+
// Mirror to the console (Debug level) so the full set of diagnostics is visible in the
|
|
868
|
+
// browser, not only in DataDog — helps debugging when a customer can't share a repro env.
|
|
869
|
+
this.loggerProvider.debug("[SR diagnostics] ".concat(counter));
|
|
783
870
|
(_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.diagnosticsClient) === null || _b === void 0 ? void 0 : _b.increment(counter);
|
|
784
871
|
}
|
|
785
872
|
catch (_c) {
|
|
@@ -793,6 +880,8 @@ var SessionReplay = /** @class */ (function () {
|
|
|
793
880
|
SessionReplay.prototype.recordDiagnosticHistogram = function (name, value) {
|
|
794
881
|
var _a, _b;
|
|
795
882
|
try {
|
|
883
|
+
// Mirror to the console (Debug level) — see incrementDiagnostic.
|
|
884
|
+
this.loggerProvider.debug("[SR diagnostics] ".concat(name, "=").concat(value));
|
|
796
885
|
// The only caller runs inside evaluateTargetingAndCapture's `this.config` guard, so the
|
|
797
886
|
// `config == null` arm of this optional chain is unreachable here (kept as defensive parity
|
|
798
887
|
// with recordDiagnosticEvent). The diagnosticsClient-absent arm IS exercised by no-client tests.
|
|
@@ -810,16 +899,24 @@ var SessionReplay = /** @class */ (function () {
|
|
|
810
899
|
* meaningful decision points, not per-call tallies. Best-effort, never throws.
|
|
811
900
|
*/
|
|
812
901
|
SessionReplay.prototype.recordDiagnosticEvent = function (name, properties) {
|
|
813
|
-
var _a, _b, _c;
|
|
902
|
+
var _a, _b, _c, _d, _e, _f;
|
|
814
903
|
try {
|
|
815
904
|
var sessionId = (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId;
|
|
816
905
|
var deviceId = this.getDeviceId();
|
|
817
906
|
// Always stamp sessionId, deviceId and srId so every diagnostics event (→ DataDog Logs) can
|
|
818
907
|
// be correlated to a single session/device — and to the actual replay, since the Session
|
|
819
908
|
// Replay ID is `${deviceId}/${sessionId}`. Caller props override if they pass their own.
|
|
820
|
-
|
|
909
|
+
var enriched = tslib_1.__assign({ sessionId: sessionId, deviceId: deviceId, srId: deviceId != null && sessionId != null ? "".concat(deviceId, "/").concat(sessionId) : undefined }, properties);
|
|
910
|
+
// Mirror to the console (Debug level) so the full event + props are visible in the browser,
|
|
911
|
+
// not only in DataDog — see incrementDiagnostic.
|
|
912
|
+
this.loggerProvider.debug("[SR diagnostics] ".concat(name, " ").concat(JSON.stringify(enriched)));
|
|
913
|
+
(_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.diagnosticsClient) === null || _c === void 0 ? void 0 : _c.recordEvent(name, enriched);
|
|
914
|
+
// Flush immediately so the event ships now rather than on the client's ~5-min timer (and so
|
|
915
|
+
// short sessions that never reach the timer aren't lost). NOTE: this sends one capture POST
|
|
916
|
+
// per event — higher request volume; revisit/gate before production.
|
|
917
|
+
void ((_f = (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.diagnosticsClient) === null || _e === void 0 ? void 0 : _e._flush) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
821
918
|
}
|
|
822
|
-
catch (
|
|
919
|
+
catch (_g) {
|
|
823
920
|
// swallow — diagnostics is best-effort
|
|
824
921
|
}
|
|
825
922
|
};
|