@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.
Files changed (49) hide show
  1. package/lib/cjs/config/joined-config.d.ts.map +1 -1
  2. package/lib/cjs/config/joined-config.js +23 -19
  3. package/lib/cjs/config/joined-config.js.map +1 -1
  4. package/lib/cjs/diagnostics.d.ts +5 -0
  5. package/lib/cjs/diagnostics.d.ts.map +1 -1
  6. package/lib/cjs/diagnostics.js +11 -1
  7. package/lib/cjs/diagnostics.js.map +1 -1
  8. package/lib/cjs/plugins/url-tracking-plugin.d.ts +6 -0
  9. package/lib/cjs/plugins/url-tracking-plugin.d.ts.map +1 -1
  10. package/lib/cjs/plugins/url-tracking-plugin.js +3 -1
  11. package/lib/cjs/plugins/url-tracking-plugin.js.map +1 -1
  12. package/lib/cjs/session-replay.d.ts +7 -0
  13. package/lib/cjs/session-replay.d.ts.map +1 -1
  14. package/lib/cjs/session-replay.js +123 -26
  15. package/lib/cjs/session-replay.js.map +1 -1
  16. package/lib/cjs/targeting/targeting-manager.d.ts.map +1 -1
  17. package/lib/cjs/targeting/targeting-manager.js +28 -15
  18. package/lib/cjs/targeting/targeting-manager.js.map +1 -1
  19. package/lib/cjs/version.d.ts +1 -1
  20. package/lib/cjs/version.js +1 -1
  21. package/lib/cjs/version.js.map +1 -1
  22. package/lib/esm/config/joined-config.d.ts.map +1 -1
  23. package/lib/esm/config/joined-config.js +23 -19
  24. package/lib/esm/config/joined-config.js.map +1 -1
  25. package/lib/esm/diagnostics.d.ts +5 -0
  26. package/lib/esm/diagnostics.d.ts.map +1 -1
  27. package/lib/esm/diagnostics.js +11 -1
  28. package/lib/esm/diagnostics.js.map +1 -1
  29. package/lib/esm/plugins/url-tracking-plugin.d.ts +6 -0
  30. package/lib/esm/plugins/url-tracking-plugin.d.ts.map +1 -1
  31. package/lib/esm/plugins/url-tracking-plugin.js +3 -1
  32. package/lib/esm/plugins/url-tracking-plugin.js.map +1 -1
  33. package/lib/esm/session-replay.d.ts +7 -0
  34. package/lib/esm/session-replay.d.ts.map +1 -1
  35. package/lib/esm/session-replay.js +123 -26
  36. package/lib/esm/session-replay.js.map +1 -1
  37. package/lib/esm/targeting/targeting-manager.d.ts.map +1 -1
  38. package/lib/esm/targeting/targeting-manager.js +28 -15
  39. package/lib/esm/targeting/targeting-manager.js.map +1 -1
  40. package/lib/esm/version.d.ts +1 -1
  41. package/lib/esm/version.js +1 -1
  42. package/lib/esm/version.js.map +1 -1
  43. package/lib/scripts/index-min.js +1 -1
  44. package/lib/scripts/index-min.js.gz +0 -0
  45. package/lib/scripts/index-min.js.map +1 -1
  46. package/lib/scripts/session-replay-browser-min.js +1 -1
  47. package/lib/scripts/session-replay-browser-min.js.gz +0 -0
  48. package/lib/scripts/session-replay-browser-min.js.map +1 -1
  49. package/package.json +3 -3
@@ -8,39 +8,47 @@ var evaluateTargetingAndStore = function (_a) {
8
8
  var sessionId = _a.sessionId, targetingConfig = _a.targetingConfig, loggerProvider = _a.loggerProvider, apiKey = _a.apiKey, targetingParams = _a.targetingParams, _b = _a.urlChange, urlChange = _b === void 0 ? false : _b, diagnosticsClient = _a.diagnosticsClient, deviceId = _a.deviceId;
9
9
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
10
10
  var idbTargetingMatch, sessionTargetingMatch, evaluateTargetingPackage, params, targetingResult, err_1, knownError;
11
- var _c, _d, _e, _f;
12
- return tslib_1.__generator(this, function (_g) {
13
- switch (_g.label) {
11
+ var _c, _d, _e, _f, _g, _h, _j;
12
+ return tslib_1.__generator(this, function (_k) {
13
+ switch (_k.label) {
14
14
  case 0: return [4 /*yield*/, targeting_idb_store_1.targetingIDBStore.clearStoreOfOldSessions({
15
15
  loggerProvider: loggerProvider,
16
16
  apiKey: apiKey,
17
17
  currentSessionId: sessionId,
18
18
  })];
19
19
  case 1:
20
- _g.sent();
20
+ _k.sent();
21
21
  return [4 /*yield*/, targeting_idb_store_1.targetingIDBStore.getTargetingMatchForSession({
22
22
  loggerProvider: loggerProvider,
23
23
  apiKey: apiKey,
24
24
  sessionId: sessionId,
25
25
  })];
26
26
  case 2:
27
- idbTargetingMatch = _g.sent();
27
+ idbTargetingMatch = _k.sent();
28
28
  // Skip IDB cache when re-evaluating with a new page (e.g. URL change); otherwise we'd never
29
29
  // re-evaluate and would keep returning true after navigating to a non-matching page.
30
30
  if (idbTargetingMatch === true && !urlChange) {
31
31
  return [2 /*return*/, true];
32
32
  }
33
33
  sessionTargetingMatch = true;
34
- _g.label = 3;
34
+ _k.label = 3;
35
35
  case 3:
36
- _g.trys.push([3, 6, , 7]);
36
+ _k.trys.push([3, 6, , 7]);
37
37
  return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('@amplitude/targeting')); })];
38
38
  case 4:
39
- evaluateTargetingPackage = (_g.sent()).evaluateTargeting;
39
+ evaluateTargetingPackage = (_k.sent()).evaluateTargeting;
40
40
  params = tslib_1.__assign(tslib_1.__assign({}, targetingParams), { flag: targetingConfig, sessionId: typeof sessionId === 'string' ? parseInt(sessionId, 10) : sessionId, apiKey: apiKey, loggerProvider: loggerProvider });
41
+ diagnosticsClient === null || diagnosticsClient === void 0 ? void 0 : diagnosticsClient.recordEvent(diagnostics_1.SrDiagnostic.targetingTrigger, {
42
+ sessionId: sessionId,
43
+ deviceId: deviceId,
44
+ srId: deviceId != null && sessionId != null ? "".concat(deviceId, "/").concat(sessionId) : undefined,
45
+ pageUrl: (_c = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.page) === null || _c === void 0 ? void 0 : _c.url,
46
+ matched: sessionTargetingMatch,
47
+ targetingConfig: targetingConfig,
48
+ });
41
49
  return [4 /*yield*/, evaluateTargetingPackage(params)];
42
50
  case 5:
43
- targetingResult = _g.sent();
51
+ targetingResult = _k.sent();
44
52
  if (targetingResult && targetingResult.sr_targeting_config) {
45
53
  sessionTargetingMatch = targetingResult.sr_targeting_config.key === 'on';
46
54
  }
@@ -52,12 +60,16 @@ var evaluateTargetingAndStore = function (_a) {
52
60
  sessionId: sessionId,
53
61
  deviceId: deviceId,
54
62
  srId: deviceId != null && sessionId != null ? "".concat(deviceId, "/").concat(sessionId) : undefined,
55
- pageUrl: (_c = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.page) === null || _c === void 0 ? void 0 : _c.url,
56
- variantKey: (_e = (_d = targetingResult === null || targetingResult === void 0 ? void 0 : targetingResult.sr_targeting_config) === null || _d === void 0 ? void 0 : _d.key) !== null && _e !== void 0 ? _e : null,
63
+ pageUrl: (_d = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.page) === null || _d === void 0 ? void 0 : _d.url,
64
+ variantKey: (_f = (_e = targetingResult === null || targetingResult === void 0 ? void 0 : targetingResult.sr_targeting_config) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : null,
57
65
  matched: sessionTargetingMatch,
66
+ targetingConfig: targetingConfig,
58
67
  });
68
+ // Flush now so the verdict ships immediately (vs the client's ~5-min timer). One capture
69
+ // POST per event — higher volume; revisit/gate before production.
70
+ void ((_g = diagnosticsClient === null || diagnosticsClient === void 0 ? void 0 : diagnosticsClient._flush) === null || _g === void 0 ? void 0 : _g.call(diagnosticsClient));
59
71
  }
60
- catch (_h) {
72
+ catch (_l) {
61
73
  // diagnostics is best-effort
62
74
  }
63
75
  void targeting_idb_store_1.targetingIDBStore.storeTargetingMatchForSession({
@@ -68,7 +80,7 @@ var evaluateTargetingAndStore = function (_a) {
68
80
  });
69
81
  return [3 /*break*/, 7];
70
82
  case 6:
71
- err_1 = _g.sent();
83
+ err_1 = _k.sent();
72
84
  knownError = err_1;
73
85
  // Q3 "is the TRC failing?": the targeting engine threw — record it so the team sees TRC
74
86
  // errors in DataDog (this exception is otherwise swallowed). Best-effort, never re-throws.
@@ -78,11 +90,12 @@ var evaluateTargetingAndStore = function (_a) {
78
90
  sessionId: sessionId,
79
91
  deviceId: deviceId,
80
92
  srId: deviceId != null && sessionId != null ? "".concat(deviceId, "/").concat(sessionId) : undefined,
81
- pageUrl: (_f = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.page) === null || _f === void 0 ? void 0 : _f.url,
93
+ pageUrl: (_h = targetingParams === null || targetingParams === void 0 ? void 0 : targetingParams.page) === null || _h === void 0 ? void 0 : _h.url,
82
94
  message: knownError.message,
83
95
  });
96
+ void ((_j = diagnosticsClient === null || diagnosticsClient === void 0 ? void 0 : diagnosticsClient._flush) === null || _j === void 0 ? void 0 : _j.call(diagnosticsClient));
84
97
  }
85
- catch (_j) {
98
+ catch (_m) {
86
99
  // diagnostics is best-effort
87
100
  }
88
101
  loggerProvider.warn(knownError.message);
@@ -1 +1 @@
1
- {"version":3,"file":"targeting-manager.js","sourceRoot":"","sources":["../../../src/targeting/targeting-manager.ts"],"names":[],"mappings":";;;;AAKA,6DAA0D;AAC1D,8CAA8C;AAEvC,IAAM,yBAAyB,GAAG,UAAO,EAkB/C;QAjBC,SAAS,eAAA,EACT,eAAe,qBAAA,EACf,cAAc,oBAAA,EACd,MAAM,YAAA,EACN,eAAe,qBAAA,EACf,iBAAiB,EAAjB,SAAS,mBAAG,KAAK,KAAA,EACjB,iBAAiB,uBAAA,EACjB,QAAQ,cAAA;;;;;;wBAWR,qBAAM,uCAAiB,CAAC,uBAAuB,CAAC;wBAC9C,cAAc,EAAE,cAAc;wBAC9B,MAAM,EAAE,MAAM;wBACd,gBAAgB,EAAE,SAAS;qBAC5B,CAAC,EAAA;;oBAJF,SAIE,CAAC;oBAEuB,qBAAM,uCAAiB,CAAC,2BAA2B,CAAC;4BAC5E,cAAc,EAAE,cAAc;4BAC9B,MAAM,EAAE,MAAM;4BACd,SAAS,EAAE,SAAS;yBACrB,CAAC,EAAA;;oBAJI,iBAAiB,GAAG,SAIxB;oBAEF,4FAA4F;oBAC5F,qFAAqF;oBACrF,IAAI,iBAAiB,KAAK,IAAI,IAAI,CAAC,SAAS,EAA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A6B,CAAC;wBACnD,cAAc,EAAE,cAAc;wBAC9B,MAAM,EAAE,MAAM;wBACd,SAAS,EAAE,SAAS;wBACpB,cAAc,EAAE,qBAAqB;qBACtC,CAAC,CAAC;;;;oBAEG,UAAU,GAAG,KAAY,CAAC;oBAChC,wFAAwF;oBACxF,2FAA2F;oBAC3F,IAAI;wBACF,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,SAAS,CAAC,0BAAY,CAAC,SAAS,CAAC,CAAC;wBACrD,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,WAAW,CAAC,0BAAY,CAAC,SAAS,EAAE;4BACrD,SAAS,WAAA;4BACT,QAAQ,UAAA;4BACR,IAAI,EAAE,QAAQ,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,UAAG,QAAQ,cAAI,SAAS,CAAE,CAAC,CAAC,CAAC,SAAS;4BACpF,OAAO,EAAE,MAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,IAAI,0CAAE,GAAG;4BACnC,OAAO,EAAE,UAAU,CAAC,OAAO;yBAC5B,CAAC,CAAC;qBACJ;oBAAC,WAAM;wBACN,6BAA6B;qBAC9B;oBACD,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;;wBAE1C,sBAAO,qBAAqB,EAAC;;;;CAC9B,CAAC;AAjGW,QAAA,yBAAyB,6BAiGpC","sourcesContent":["import type { TargetingParameters } from '@amplitude/targeting';\nimport { TargetingConfig } from '../config/types';\nimport { Logger } from '@amplitude/analytics-types';\nimport { IDiagnosticsClient } from '@amplitude/analytics-core';\nimport { SessionReplayTargetingInput } from '../typings/session-replay';\nimport { targetingIDBStore } from './targeting-idb-store';\nimport { SrDiagnostic } from '../diagnostics';\n\nexport const evaluateTargetingAndStore = async ({\n sessionId,\n targetingConfig,\n loggerProvider,\n apiKey,\n targetingParams,\n urlChange = false,\n diagnosticsClient,\n deviceId,\n}: {\n sessionId: string | number;\n targetingConfig: TargetingConfig;\n loggerProvider: Logger;\n apiKey: string;\n targetingParams?: SessionReplayTargetingInput;\n urlChange?: boolean;\n diagnosticsClient?: IDiagnosticsClient;\n deviceId?: string;\n}) => {\n await targetingIDBStore.clearStoreOfOldSessions({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n currentSessionId: sessionId,\n });\n\n const idbTargetingMatch = await targetingIDBStore.getTargetingMatchForSession({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n sessionId: sessionId,\n });\n\n // Skip IDB cache when re-evaluating with a new page (e.g. URL change); otherwise we'd never\n // re-evaluate and would keep returning true after navigating to a non-matching page.\n if (idbTargetingMatch === true && !urlChange) {\n return true;\n }\n\n // If the targeting config is undefined or an empty object,\n // assume the response was valid but no conditions were set,\n // so all users match targeting\n let sessionTargetingMatch = true;\n try {\n // Dynamic import of the targeting package\n const { evaluateTargeting: evaluateTargetingPackage } = await import('@amplitude/targeting');\n\n const params: TargetingParameters = {\n ...targetingParams,\n flag: targetingConfig,\n sessionId: typeof sessionId === 'string' ? parseInt(sessionId, 10) : sessionId,\n apiKey: apiKey,\n loggerProvider: loggerProvider,\n };\n const targetingResult = await evaluateTargetingPackage(params);\n if (targetingResult && targetingResult.sr_targeting_config) {\n sessionTargetingMatch = targetingResult.sr_targeting_config.key === 'on';\n }\n // gap #2: the raw engine verdict. variantKey 'on' => matched; 'off'/undefined => not.\n // Pair with the eval event's pageUrl to tell \"URL condition didn't match\" from \"URL matched\n // but the segment bucket (capture %) didn't allocate this session\".\n try {\n diagnosticsClient?.recordEvent(SrDiagnostic.evalResult, {\n sessionId,\n deviceId,\n srId: deviceId != null && sessionId != null ? `${deviceId}/${sessionId}` : undefined,\n pageUrl: targetingParams?.page?.url,\n variantKey: targetingResult?.sr_targeting_config?.key ?? null,\n matched: sessionTargetingMatch,\n });\n } catch {\n // diagnostics is best-effort\n }\n\n void targetingIDBStore.storeTargetingMatchForSession({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n sessionId: sessionId,\n targetingMatch: sessionTargetingMatch,\n });\n } catch (err: unknown) {\n const knownError = err as Error;\n // Q3 \"is the TRC failing?\": the targeting engine threw — record it so the team sees TRC\n // errors in DataDog (this exception is otherwise swallowed). Best-effort, never re-throws.\n try {\n diagnosticsClient?.increment(SrDiagnostic.evalError);\n diagnosticsClient?.recordEvent(SrDiagnostic.evalError, {\n sessionId,\n deviceId,\n srId: deviceId != null && sessionId != null ? `${deviceId}/${sessionId}` : undefined,\n pageUrl: targetingParams?.page?.url,\n message: knownError.message,\n });\n } catch {\n // diagnostics is best-effort\n }\n loggerProvider.warn(knownError.message);\n }\n return sessionTargetingMatch;\n};\n"]}
1
+ {"version":3,"file":"targeting-manager.js","sourceRoot":"","sources":["../../../src/targeting/targeting-manager.ts"],"names":[],"mappings":";;;;AAKA,6DAA0D;AAC1D,8CAA8C;AAEvC,IAAM,yBAAyB,GAAG,UAAO,EAkB/C;QAjBC,SAAS,eAAA,EACT,eAAe,qBAAA,EACf,cAAc,oBAAA,EACd,MAAM,YAAA,EACN,eAAe,qBAAA,EACf,iBAAiB,EAAjB,SAAS,mBAAG,KAAK,KAAA,EACjB,iBAAiB,uBAAA,EACjB,QAAQ,cAAA;;;;;;wBAWR,qBAAM,uCAAiB,CAAC,uBAAuB,CAAC;wBAC9C,cAAc,EAAE,cAAc;wBAC9B,MAAM,EAAE,MAAM;wBACd,gBAAgB,EAAE,SAAS;qBAC5B,CAAC,EAAA;;oBAJF,SAIE,CAAC;oBAEuB,qBAAM,uCAAiB,CAAC,2BAA2B,CAAC;4BAC5E,cAAc,EAAE,cAAc;4BAC9B,MAAM,EAAE,MAAM;4BACd,SAAS,EAAE,SAAS;yBACrB,CAAC,EAAA;;oBAJI,iBAAiB,GAAG,SAIxB;oBAEF,4FAA4F;oBAC5F,qFAAqF;oBACrF,IAAI,iBAAiB,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE;wBAC5C,sBAAO,IAAI,EAAC;qBACb;oBA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AC5B,CAAC,CAAC;wBACH,KAAK,CAAA,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,iEAAI,CAAA,CAAC;qBACpC;oBAAC,WAAM;wBACN,6BAA6B;qBAC9B;oBACD,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;;wBAE1C,sBAAO,qBAAqB,EAAC;;;;CAC9B,CAAC;AA9GW,QAAA,yBAAyB,6BA8GpC","sourcesContent":["import type { TargetingParameters } from '@amplitude/targeting';\nimport { TargetingConfig } from '../config/types';\nimport { Logger } from '@amplitude/analytics-types';\nimport { IDiagnosticsClient } from '@amplitude/analytics-core';\nimport { SessionReplayTargetingInput } from '../typings/session-replay';\nimport { targetingIDBStore } from './targeting-idb-store';\nimport { SrDiagnostic } from '../diagnostics';\n\nexport const evaluateTargetingAndStore = async ({\n sessionId,\n targetingConfig,\n loggerProvider,\n apiKey,\n targetingParams,\n urlChange = false,\n diagnosticsClient,\n deviceId,\n}: {\n sessionId: string | number;\n targetingConfig: TargetingConfig;\n loggerProvider: Logger;\n apiKey: string;\n targetingParams?: SessionReplayTargetingInput;\n urlChange?: boolean;\n diagnosticsClient?: IDiagnosticsClient;\n deviceId?: string;\n}) => {\n await targetingIDBStore.clearStoreOfOldSessions({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n currentSessionId: sessionId,\n });\n\n const idbTargetingMatch = await targetingIDBStore.getTargetingMatchForSession({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n sessionId: sessionId,\n });\n\n // Skip IDB cache when re-evaluating with a new page (e.g. URL change); otherwise we'd never\n // re-evaluate and would keep returning true after navigating to a non-matching page.\n if (idbTargetingMatch === true && !urlChange) {\n return true;\n }\n\n // If the targeting config is undefined or an empty object,\n // assume the response was valid but no conditions were set,\n // so all users match targeting\n let sessionTargetingMatch = true;\n try {\n // Dynamic import of the targeting package\n const { evaluateTargeting: evaluateTargetingPackage } = await import('@amplitude/targeting');\n\n const params: TargetingParameters = {\n ...targetingParams,\n flag: targetingConfig,\n sessionId: typeof sessionId === 'string' ? parseInt(sessionId, 10) : sessionId,\n apiKey: apiKey,\n loggerProvider: loggerProvider,\n };\n diagnosticsClient?.recordEvent(SrDiagnostic.targetingTrigger, {\n sessionId,\n deviceId,\n srId: deviceId != null && sessionId != null ? `${deviceId}/${sessionId}` : undefined,\n pageUrl: targetingParams?.page?.url,\n matched: sessionTargetingMatch,\n targetingConfig: targetingConfig,\n });\n const targetingResult = await evaluateTargetingPackage(params);\n if (targetingResult && targetingResult.sr_targeting_config) {\n sessionTargetingMatch = targetingResult.sr_targeting_config.key === 'on';\n }\n // gap #2: the raw engine verdict. variantKey 'on' => matched; 'off'/undefined => not.\n // Pair with the eval event's pageUrl to tell \"URL condition didn't match\" from \"URL matched\n // but the segment bucket (capture %) didn't allocate this session\".\n try {\n diagnosticsClient?.recordEvent(SrDiagnostic.evalResult, {\n sessionId,\n deviceId,\n srId: deviceId != null && sessionId != null ? `${deviceId}/${sessionId}` : undefined,\n pageUrl: targetingParams?.page?.url,\n variantKey: targetingResult?.sr_targeting_config?.key ?? null,\n matched: sessionTargetingMatch,\n targetingConfig: targetingConfig,\n });\n // Flush now so the verdict ships immediately (vs the client's ~5-min timer). One capture\n // POST per event — higher volume; revisit/gate before production.\n void diagnosticsClient?._flush?.();\n } catch {\n // diagnostics is best-effort\n }\n\n void targetingIDBStore.storeTargetingMatchForSession({\n loggerProvider: loggerProvider,\n apiKey: apiKey,\n sessionId: sessionId,\n targetingMatch: sessionTargetingMatch,\n });\n } catch (err: unknown) {\n const knownError = err as Error;\n // Q3 \"is the TRC failing?\": the targeting engine threw — record it so the team sees TRC\n // errors in DataDog (this exception is otherwise swallowed). Best-effort, never re-throws.\n try {\n diagnosticsClient?.increment(SrDiagnostic.evalError);\n diagnosticsClient?.recordEvent(SrDiagnostic.evalError, {\n sessionId,\n deviceId,\n srId: deviceId != null && sessionId != null ? `${deviceId}/${sessionId}` : undefined,\n pageUrl: targetingParams?.page?.url,\n message: knownError.message,\n });\n void diagnosticsClient?._flush?.();\n } catch {\n // diagnostics is best-effort\n }\n loggerProvider.warn(knownError.message);\n }\n return sessionTargetingMatch;\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.47.0-sr-trc-debug-log.0";
1
+ export declare const VERSION = "1.47.0-sr-trc-debug-log.2";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Autogenerated by `pnpm version-file`. DO NOT EDIT
5
- exports.VERSION = '1.47.0-sr-trc-debug-log.0';
5
+ exports.VERSION = '1.47.0-sr-trc-debug-log.2';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.47.0-sr-trc-debug-log.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.47.0-sr-trc-debug-log.2';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAA4C,MAAM,2BAA2B,CAAC;AAGnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,aAAa,EACb,oBAAoB,EAGrB,MAAM,SAAS,CAAC;AAajB,eAAO,MAAM,uCAAuC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,CAAS;gBAGjC,kBAAkB,EAAE,mBAAmB,EACvC,WAAW,EAAE,yBAAyB,EACtC,QAAQ,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAQzD,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAwO3D;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;CAmBrC;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD,eAAO,MAAM,wCAAwC,WAAkB,MAAM,WAAW,oBAAoB,gDAc3G,CAAC"}
@@ -49,13 +49,13 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
49
49
  this.deviceId = identity === null || identity === void 0 ? void 0 : identity.deviceId;
50
50
  }
51
51
  SessionReplayJoinedConfigGenerator.prototype.generateJoinedConfig = function () {
52
- var _a, _b, _c, _d, _e, _f, _g, _h;
52
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
53
53
  return __awaiter(this, void 0, void 0, function () {
54
- var config, sessionReplayRemoteConfig, error_1, samplingConfig, remotePrivacyConfig, targetingConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _j, _k, _l, selector, selectorType;
55
- var e_1, _m;
54
+ var config, sessionReplayRemoteConfig, error_1, samplingConfig, remotePrivacyConfig, targetingConfig, localPrivacyConfig, joinedPrivacyConfig, privacyConfigSelectorMap, selectorMap, _l, _m, _o, selector, selectorType;
55
+ var e_1, _p;
56
56
  var _this = this;
57
- return __generator(this, function (_o) {
58
- switch (_o.label) {
57
+ return __generator(this, function (_q) {
58
+ switch (_q.label) {
59
59
  case 0:
60
60
  config = __assign({}, this.localConfig);
61
61
  // Special case here as optOut is implemented via getter/setter
@@ -63,16 +63,16 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
63
63
  // We always want captureEnabled to be true, unless there's an override
64
64
  // in the remote config.
65
65
  config.captureEnabled = true;
66
- _o.label = 1;
66
+ _q.label = 1;
67
67
  case 1:
68
- _o.trys.push([1, 3, , 4]);
68
+ _q.trys.push([1, 3, , 4]);
69
69
  // Subscribe with a timeout so the SDK prefers the remote response and only falls back
70
70
  // to cache after the budget elapses. 'all' mode would race a synchronous cache read
71
71
  // against the network and resolve on whichever fires first — cache always wins, so a
72
72
  // stale cache silently overrides the live config (SR-4234).
73
73
  return [4 /*yield*/, new Promise(function (resolve, reject) {
74
74
  _this.remoteConfigClient.subscribe('configs.sessionReplay', { timeout: REMOTE_CONFIG_TIMEOUT_MS }, function (remoteConfig, source) {
75
- var _a;
75
+ var _a, _b;
76
76
  _this.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(source, ":"), JSON.stringify(remoteConfig, null, 2));
77
77
  if (!remoteConfig) {
78
78
  reject(new Error('No remote config received'));
@@ -115,8 +115,11 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
115
115
  targetingSegmentCount: Array.isArray(targetingSegments) ? targetingSegments.length : undefined,
116
116
  hasPrivacy: !!privacyConfig,
117
117
  });
118
+ // Flush now (vs the client's ~5-min timer). One capture POST per event — higher
119
+ // volume; revisit/gate before production.
120
+ void ((_b = diagnosticsClient === null || diagnosticsClient === void 0 ? void 0 : diagnosticsClient._flush) === null || _b === void 0 ? void 0 : _b.call(diagnosticsClient));
118
121
  }
119
- catch (_b) {
122
+ catch (_c) {
120
123
  // diagnostics is best-effort
121
124
  }
122
125
  if (samplingConfig || privacyConfig || targetingConfig) {
@@ -139,15 +142,16 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
139
142
  // to cache after the budget elapses. 'all' mode would race a synchronous cache read
140
143
  // against the network and resolve on whichever fires first — cache always wins, so a
141
144
  // stale cache silently overrides the live config (SR-4234).
142
- _o.sent();
145
+ _q.sent();
143
146
  return [3 /*break*/, 4];
144
147
  case 3:
145
- error_1 = _o.sent();
148
+ error_1 = _q.sent();
146
149
  this.localConfig.loggerProvider.error('Failed to generate joined config: ', error_1);
147
150
  try {
148
151
  (_a = this.localConfig.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.increment(SrDiagnostic.configFetchFailed);
152
+ void ((_c = (_b = this.localConfig.diagnosticsClient) === null || _b === void 0 ? void 0 : _b._flush) === null || _c === void 0 ? void 0 : _c.call(_b));
149
153
  }
150
- catch (_p) {
154
+ catch (_r) {
151
155
  // diagnostics is best-effort
152
156
  }
153
157
  config.captureEnabled = false;
@@ -200,14 +204,14 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
200
204
  // ...remotePrivacyConfig,
201
205
  // };
202
206
  if (remotePrivacyConfig) {
203
- localPrivacyConfig = (_b = config.privacyConfig) !== null && _b !== void 0 ? _b : {};
207
+ localPrivacyConfig = (_d = config.privacyConfig) !== null && _d !== void 0 ? _d : {};
204
208
  joinedPrivacyConfig = {
205
- defaultMaskLevel: (_d = (_c = remotePrivacyConfig.defaultMaskLevel) !== null && _c !== void 0 ? _c : localPrivacyConfig.defaultMaskLevel) !== null && _d !== void 0 ? _d : 'medium',
209
+ defaultMaskLevel: (_f = (_e = remotePrivacyConfig.defaultMaskLevel) !== null && _e !== void 0 ? _e : localPrivacyConfig.defaultMaskLevel) !== null && _f !== void 0 ? _f : 'medium',
206
210
  blockSelector: [],
207
211
  maskSelector: [],
208
212
  unmaskSelector: [],
209
- maskAttributes: __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(((_e = localPrivacyConfig.maskAttributes) !== null && _e !== void 0 ? _e : [])), false), __read(((_f = remotePrivacyConfig.maskAttributes) !== null && _f !== void 0 ? _f : [])), false))), false),
210
- urlMaskLevels: __spreadArray(__spreadArray([], __read(((_g = remotePrivacyConfig.urlMaskLevels) !== null && _g !== void 0 ? _g : [])), false), __read(((_h = localPrivacyConfig.urlMaskLevels) !== null && _h !== void 0 ? _h : [])), false),
213
+ maskAttributes: __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(((_g = localPrivacyConfig.maskAttributes) !== null && _g !== void 0 ? _g : [])), false), __read(((_h = remotePrivacyConfig.maskAttributes) !== null && _h !== void 0 ? _h : [])), false))), false),
214
+ urlMaskLevels: __spreadArray(__spreadArray([], __read(((_j = remotePrivacyConfig.urlMaskLevels) !== null && _j !== void 0 ? _j : [])), false), __read(((_k = localPrivacyConfig.urlMaskLevels) !== null && _k !== void 0 ? _k : [])), false),
211
215
  };
212
216
  privacyConfigSelectorMap = function (privacyConfig) {
213
217
  var e_2, _a, e_3, _b, e_4, _c;
@@ -259,8 +263,8 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
259
263
  };
260
264
  selectorMap = __assign(__assign({}, privacyConfigSelectorMap(localPrivacyConfig)), privacyConfigSelectorMap(remotePrivacyConfig));
261
265
  try {
262
- for (_j = __values(Object.entries(selectorMap)), _k = _j.next(); !_k.done; _k = _j.next()) {
263
- _l = __read(_k.value, 2), selector = _l[0], selectorType = _l[1];
266
+ for (_l = __values(Object.entries(selectorMap)), _m = _l.next(); !_m.done; _m = _l.next()) {
267
+ _o = __read(_m.value, 2), selector = _o[0], selectorType = _o[1];
264
268
  if (selectorType === 'mask') {
265
269
  joinedPrivacyConfig.maskSelector.push(selector);
266
270
  }
@@ -275,7 +279,7 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
275
279
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
276
280
  finally {
277
281
  try {
278
- if (_k && !_k.done && (_m = _j.return)) _m.call(_j);
282
+ if (_m && !_m.done && (_p = _l.return)) _p.call(_l);
279
283
  }
280
284
  finally { if (e_1) throw e_1.error; }
281
285
  }
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAgC,kBAAkB,EAAwB,MAAM,2BAA2B,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,C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I,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE5D,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,MAAM,EACN,WAAW,CAAC,cAAc,EAC1B,WAAW,CAAC,UAAU,EACtB,OAAO,CAAC,eAAe,CACxB,CAAC;QAEF,sBAAO,IAAI,kCAAkC,CAAC,kBAAkB,EAAE,WAAW,EAAE;gBAC7E,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B,CAAC,EAAC;;KACJ,CAAC","sourcesContent":["import { ILogger, IRemoteConfigClient, RemoteConfigClient, RemoteConfig, Source } from '@amplitude/analytics-core';\nimport { getDebugConfig } from '../helpers';\nimport { SrDiagnostic } from '../diagnostics';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n PrivacyConfig,\n SessionReplayConfigs,\n SessionReplayJoinedConfig,\n SessionReplayRemoteConfig,\n} from './types';\n\n// Budget for waiting on the remote config response before falling back to the local cache.\n// The inner fetch in analytics-core uses a 1000ms per-attempt AbortController timeout with\n// up to 3 retries — but this outer timeout is the only thing the SR plugin waits on, so\n// only the first attempt can possibly complete in time (attempt 2 starts at ~1000-1333ms\n// after backoff jitter and runs to ~2000-2333ms, well past any reasonable outer budget).\n// 1500ms is set above the 1000ms inner abort to avoid a tie with the inner cutoff and\n// give the first attempt's resolution path room to finish; everything else falls through\n// to the cache fallback. See SR-4234: prefer remote over a stale cache that would\n// otherwise win the synchronous race in 'all' mode.\nconst REMOTE_CONFIG_TIMEOUT_MS = 1500;\n\nexport const removeInvalidSelectorsFromPrivacyConfig = (privacyConfig: PrivacyConfig, loggerProvider: ILogger) => {\n // This allows us to not search the DOM.\n const fragment = document.createDocumentFragment();\n\n const dropInvalidSelectors = (selectors: string[] | string = []): string[] | undefined => {\n if (typeof selectors === 'string') {\n selectors = [selectors];\n }\n selectors = selectors.filter((selector: string) => {\n try {\n fragment.querySelector(selector);\n } catch {\n loggerProvider.warn(`[session-replay-browser] omitting selector \"${selector}\" because it is invalid`);\n return false;\n }\n return true;\n });\n if (selectors.length === 0) {\n return undefined;\n }\n return selectors;\n };\n privacyConfig.blockSelector = dropInvalidSelectors(privacyConfig.blockSelector);\n privacyConfig.maskSelector = dropInvalidSelectors(privacyConfig.maskSelector);\n privacyConfig.unmaskSelector = dropInvalidSelectors(privacyConfig.unmaskSelector);\n return privacyConfig;\n};\nexport class SessionReplayJoinedConfigGenerator {\n private readonly localConfig: ISessionReplayLocalConfig;\n private readonly remoteConfigClient: IRemoteConfigClient;\n // Identity for diagnostics correlation (config fetch is per-session). Sourced from init options.\n private readonly sessionId?: string | number;\n private readonly deviceId?: string;\n\n constructor(\n remoteConfigClient: IRemoteConfigClient,\n localConfig: ISessionReplayLocalConfig,\n identity?: { sessionId?: string | number; deviceId?: string },\n ) {\n this.localConfig = localConfig;\n this.remoteConfigClient = remoteConfigClient;\n this.sessionId = identity?.sessionId;\n this.deviceId = identity?.deviceId;\n }\n\n async generateJoinedConfig(): Promise<SessionReplayConfigs> {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n // We always want captureEnabled to be true, unless there's an override\n // in the remote config.\n config.captureEnabled = true;\n let sessionReplayRemoteConfig: SessionReplayRemoteConfig | undefined;\n\n try {\n // Subscribe with a timeout so the SDK prefers the remote response and only falls back\n // to cache after the budget elapses. 'all' mode would race a synchronous cache read\n // against the network and resolve on whichever fires first — cache always wins, so a\n // stale cache silently overrides the live config (SR-4234).\n await new Promise<void>((resolve, reject) => {\n this.remoteConfigClient.subscribe(\n 'configs.sessionReplay',\n { timeout: REMOTE_CONFIG_TIMEOUT_MS },\n (remoteConfig: RemoteConfig | null, source: Source) => {\n this.localConfig.loggerProvider.debug(\n `Session Replay remote configuration received from ${source}:`,\n JSON.stringify(remoteConfig, null, 2),\n );\n\n if (!remoteConfig) {\n reject(new Error('No remote config received'));\n return;\n }\n\n // remoteConfig is already filtered to 'configs.sessionReplay' namespace\n const namespaceConfig = remoteConfig as SessionReplayRemoteConfig;\n const samplingConfig = namespaceConfig.sr_sampling_config;\n const privacyConfig = namespaceConfig.sr_privacy_config;\n const targetingConfig = namespaceConfig.sr_targeting_config;\n\n // Captured for the sr.trc.config.received diagnostics event below (remote vs cache is\n // the crux of SR-4234 stale-cache reports).\n const samplingForLog = samplingConfig as { capture_enabled?: boolean; sample_rate?: number } | undefined;\n const targetingSegments = (targetingConfig as unknown as { segments?: unknown[] } | undefined)?.segments;\n\n const ugcFilterRules = config.interactionConfig?.ugcFilterRules;\n // This is intentionally forced to only be set through the remote config.\n config.interactionConfig = namespaceConfig.sr_interaction_config;\n if (config.interactionConfig && ugcFilterRules) {\n config.interactionConfig.ugcFilterRules = ugcFilterRules;\n }\n\n // This is intentionally forced to only be set through the remote config.\n config.loggingConfig = namespaceConfig.sr_logging_config;\n\n // Team-visible diagnostics: which SOURCE the config came from (remote vs cache — the\n // crux of SR-4234) and whether targeting was present. Counters aggregate across the\n // customer's sessions; the event carries the full context (source, sample rate,\n // segment count) as queryable log fields. No-op when diagnostics isn't configured.\n try {\n const diagnosticsClient = this.localConfig.diagnosticsClient;\n diagnosticsClient?.increment(SrDiagnostic.configSource(String(source)));\n diagnosticsClient?.increment(\n targetingConfig ? SrDiagnostic.configHasTargeting : SrDiagnostic.configNoTargeting,\n );\n diagnosticsClient?.recordEvent(SrDiagnostic.configReceived, {\n sessionId: this.sessionId,\n deviceId: this.deviceId,\n srId:\n this.deviceId != null && this.sessionId != null ? `${this.deviceId}/${this.sessionId}` : undefined,\n source: String(source),\n hasSampling: !!samplingConfig,\n captureEnabled: samplingForLog?.capture_enabled,\n sampleRate: samplingForLog?.sample_rate,\n hasTargeting: !!targetingConfig,\n targetingSegmentCount: Array.isArray(targetingSegments) ? targetingSegments.length : undefined,\n hasPrivacy: !!privacyConfig,\n });\n } catch {\n // diagnostics is best-effort\n }\n\n if (samplingConfig || privacyConfig || targetingConfig) {\n sessionReplayRemoteConfig = {};\n if (samplingConfig) {\n sessionReplayRemoteConfig.sr_sampling_config = samplingConfig;\n }\n if (privacyConfig) {\n sessionReplayRemoteConfig.sr_privacy_config = privacyConfig;\n }\n if (targetingConfig) {\n sessionReplayRemoteConfig.sr_targeting_config = targetingConfig;\n }\n }\n\n resolve();\n },\n );\n });\n } catch (error) {\n this.localConfig.loggerProvider.error('Failed to generate joined config: ', error);\n try {\n this.localConfig.diagnosticsClient?.increment(SrDiagnostic.configFetchFailed);\n } catch {\n // diagnostics is best-effort\n }\n config.captureEnabled = false;\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: undefined,\n };\n }\n\n if (!sessionReplayRemoteConfig) {\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: sessionReplayRemoteConfig,\n };\n }\n\n const {\n sr_sampling_config: samplingConfig,\n sr_privacy_config: remotePrivacyConfig,\n sr_targeting_config: targetingConfig,\n } = sessionReplayRemoteConfig;\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'sample_rate')) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'min_session_duration_ms')) {\n config.minSessionDurationMs = this.sanitizeMinSessionDurationMs(samplingConfig.min_session_duration_ms);\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n this.localConfig.loggerProvider.debug(\n 'Remote config successfully fetched, but no values set for project, Session Replay capture enabled.',\n );\n }\n\n // Remote config join acts somewhat like a left join between the remote and the local\n // config. That is, remote config has precedence over local values as with sampling.\n // However, non conflicting values will be added to the lists.\n // Here's an example to illustrate:\n //\n // Remote config: {'.selector1': 'MASK', '.selector2': 'UNMASK'}\n // Local config: {'.selector1': 'UNMASK', '.selector3': 'MASK'}\n //\n // Resolved config: {'.selector1': 'MASK', '.selector2': 'UNMASK', '.selector3': 'MASK'}\n // config.privacyConfig = {\n // ...(config.privacyConfig ?? {}),\n // ...remotePrivacyConfig,\n // };\n\n if (remotePrivacyConfig) {\n const localPrivacyConfig: PrivacyConfig = config.privacyConfig ?? {};\n\n const joinedPrivacyConfig: Required<PrivacyConfig> & { blockSelector: string[] } = {\n defaultMaskLevel: remotePrivacyConfig.defaultMaskLevel ?? localPrivacyConfig.defaultMaskLevel ?? 'medium',\n blockSelector: [],\n maskSelector: [],\n unmaskSelector: [],\n maskAttributes: [\n ...new Set([...(localPrivacyConfig.maskAttributes ?? []), ...(remotePrivacyConfig.maskAttributes ?? [])]),\n ],\n urlMaskLevels: [...(remotePrivacyConfig.urlMaskLevels ?? []), ...(localPrivacyConfig.urlMaskLevels ?? [])],\n };\n\n const privacyConfigSelectorMap = (privacyConfig: PrivacyConfig): Record<string, 'mask' | 'unmask' | 'block'> => {\n const selectorMap: Record<string, 'mask' | 'unmask' | 'block'> = {};\n if (typeof privacyConfig.blockSelector === 'string') {\n privacyConfig.blockSelector = [privacyConfig.blockSelector];\n }\n\n for (const selector of privacyConfig.blockSelector ?? []) {\n selectorMap[selector] = 'block';\n }\n for (const selector of privacyConfig.maskSelector ?? []) {\n selectorMap[selector] = 'mask';\n }\n for (const selector of privacyConfig.unmaskSelector ?? []) {\n selectorMap[selector] = 'unmask';\n }\n return selectorMap;\n };\n\n const selectorMap: Record<string, 'mask' | 'unmask' | 'block'> = {\n ...privacyConfigSelectorMap(localPrivacyConfig),\n ...privacyConfigSelectorMap(remotePrivacyConfig),\n };\n\n for (const [selector, selectorType] of Object.entries(selectorMap)) {\n if (selectorType === 'mask') {\n joinedPrivacyConfig.maskSelector.push(selector);\n } else if (selectorType === 'block') {\n joinedPrivacyConfig.blockSelector.push(selector);\n } else if (selectorType === 'unmask') {\n joinedPrivacyConfig.unmaskSelector.push(selector);\n }\n }\n\n config.privacyConfig = removeInvalidSelectorsFromPrivacyConfig(\n joinedPrivacyConfig,\n this.localConfig.loggerProvider,\n );\n }\n\n if (targetingConfig && Object.keys(targetingConfig).length > 0) {\n config.targetingConfig = targetingConfig;\n }\n\n this.localConfig.loggerProvider.debug(\n JSON.stringify({ name: 'session replay joined config', config: getDebugConfig(config) }, null, 2),\n );\n\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: sessionReplayRemoteConfig,\n };\n }\n\n /**\n * Defensive bounds for the remote-supplied min_session_duration_ms. A misconfigured\n * value (e.g. 30_000_000) would silently suppress every replay until the config is\n * pushed again, so we clamp to a sane ceiling and warn on out-of-range inputs.\n * Returns undefined for clearly invalid values so the gate falls back to disabled\n * rather than carrying a NaN through downstream comparisons.\n */\n private sanitizeMinSessionDurationMs(raw: unknown): number | undefined {\n if (typeof raw !== 'number' || !Number.isFinite(raw)) {\n this.localConfig.loggerProvider.warn(\n `min_session_duration_ms remote value is not a finite number (got ${String(raw)}); ignoring.`,\n );\n return undefined;\n }\n if (raw < 0) {\n this.localConfig.loggerProvider.warn(`min_session_duration_ms remote value is negative (${raw}); ignoring.`);\n return undefined;\n }\n if (raw > MAX_MIN_SESSION_DURATION_MS) {\n this.localConfig.loggerProvider.warn(\n `min_session_duration_ms remote value ${raw} exceeds ${MAX_MIN_SESSION_DURATION_MS}ms ceiling; clamping.`,\n );\n return MAX_MIN_SESSION_DURATION_MS;\n }\n return raw;\n }\n}\n\n/**\n * Upper bound for the remote-configured replay min duration. 60 seconds is well above\n * any reasonable bounce threshold; values higher than this are almost certainly typos\n * (e.g. seconds confused for milliseconds, or an extra zero) and would otherwise\n * suppress every replay until the config is corrected.\n */\nexport const MAX_MIN_SESSION_DURATION_MS = 60_000;\n\nexport const createSessionReplayJoinedConfigGenerator = async (apiKey: string, options: SessionReplayOptions) => {\n const localConfig = new SessionReplayLocalConfig(apiKey, options);\n\n const remoteConfigClient = new RemoteConfigClient(\n apiKey,\n localConfig.loggerProvider,\n localConfig.serverZone,\n options.configServerUrl,\n );\n\n return new SessionReplayJoinedConfigGenerator(remoteConfigClient, localConfig, {\n sessionId: options.sessionId,\n deviceId: options.deviceId,\n });\n};\n"]}
1
+ {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAgC,kBAAkB,EAAwB,MAAM,2BAA2B,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAS1D,2FAA2F;AAC3F,2FAA2F;AAC3F,wFAAwF;AACxF,yFAAyF;AACzF,yFAAyF;AACzF,sFAAsF;AACtF,yFAAyF;AACzF,kFAAkF;AAClF,oDAAoD;AACpD,IAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC,MAAM,CAAC,IAAM,uCAAuC,GAAG,UAAC,aAA4B,EAAE,cAAuB;IAC3G,wCAAwC;IACxC,IAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;IAEnD,IAAM,oBAAoB,GAAG,UAAC,SAAiC;QAAjC,0BAAA,EAAA,cAAiC;QAC7D,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC;SACzB;QACD,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,UAAC,QAAgB;YAC5C,IAAI;gBACF,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;aAClC;YAAC,WAAM;gBACN,cAAc,CAAC,IAAI,CAAC,uDAA+C,QAAQ,6BAAyB,CAAC,CAAC;gBACtG,OAAO,KAAK,CAAC;aACd;Y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;YACpD,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAClC,2EAAoE,MAAM,CAAC,GAAG,CAAC,iBAAc,CAC9F,CAAC;YACF,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,GAAG,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,4DAAqD,GAAG,iBAAc,CAAC,CAAC;YAC7G,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,GAAG,GAAG,2BAA2B,EAAE;YACrC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAClC,+CAAwC,GAAG,sBAAY,2BAA2B,0BAAuB,CAC1G,CAAC;YACF,OAAO,2BAA2B,CAAC;SACpC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACH,yCAAC;AAAD,CAAC,AApRD,IAoRC;;AAED;;;;;GAKG;AACH,MAAM,CAAC,IAAM,2BAA2B,GAAG,KAAM,CAAC;AAElD,MAAM,CAAC,IAAM,wCAAwC,GAAG,UAAO,MAAc,EAAE,OAA6B;;;QACpG,WAAW,GAAG,IAAI,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE5D,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,MAAM,EACN,WAAW,CAAC,cAAc,EAC1B,WAAW,CAAC,UAAU,EACtB,OAAO,CAAC,eAAe,CACxB,CAAC;QAEF,sBAAO,IAAI,kCAAkC,CAAC,kBAAkB,EAAE,WAAW,EAAE;gBAC7E,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B,CAAC,EAAC;;KACJ,CAAC","sourcesContent":["import { ILogger, IRemoteConfigClient, RemoteConfigClient, RemoteConfig, Source } from '@amplitude/analytics-core';\nimport { getDebugConfig } from '../helpers';\nimport { SrDiagnostic } from '../diagnostics';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n PrivacyConfig,\n SessionReplayConfigs,\n SessionReplayJoinedConfig,\n SessionReplayRemoteConfig,\n} from './types';\n\n// Budget for waiting on the remote config response before falling back to the local cache.\n// The inner fetch in analytics-core uses a 1000ms per-attempt AbortController timeout with\n// up to 3 retries — but this outer timeout is the only thing the SR plugin waits on, so\n// only the first attempt can possibly complete in time (attempt 2 starts at ~1000-1333ms\n// after backoff jitter and runs to ~2000-2333ms, well past any reasonable outer budget).\n// 1500ms is set above the 1000ms inner abort to avoid a tie with the inner cutoff and\n// give the first attempt's resolution path room to finish; everything else falls through\n// to the cache fallback. See SR-4234: prefer remote over a stale cache that would\n// otherwise win the synchronous race in 'all' mode.\nconst REMOTE_CONFIG_TIMEOUT_MS = 1500;\n\nexport const removeInvalidSelectorsFromPrivacyConfig = (privacyConfig: PrivacyConfig, loggerProvider: ILogger) => {\n // This allows us to not search the DOM.\n const fragment = document.createDocumentFragment();\n\n const dropInvalidSelectors = (selectors: string[] | string = []): string[] | undefined => {\n if (typeof selectors === 'string') {\n selectors = [selectors];\n }\n selectors = selectors.filter((selector: string) => {\n try {\n fragment.querySelector(selector);\n } catch {\n loggerProvider.warn(`[session-replay-browser] omitting selector \"${selector}\" because it is invalid`);\n return false;\n }\n return true;\n });\n if (selectors.length === 0) {\n return undefined;\n }\n return selectors;\n };\n privacyConfig.blockSelector = dropInvalidSelectors(privacyConfig.blockSelector);\n privacyConfig.maskSelector = dropInvalidSelectors(privacyConfig.maskSelector);\n privacyConfig.unmaskSelector = dropInvalidSelectors(privacyConfig.unmaskSelector);\n return privacyConfig;\n};\nexport class SessionReplayJoinedConfigGenerator {\n private readonly localConfig: ISessionReplayLocalConfig;\n private readonly remoteConfigClient: IRemoteConfigClient;\n // Identity for diagnostics correlation (config fetch is per-session). Sourced from init options.\n private readonly sessionId?: string | number;\n private readonly deviceId?: string;\n\n constructor(\n remoteConfigClient: IRemoteConfigClient,\n localConfig: ISessionReplayLocalConfig,\n identity?: { sessionId?: string | number; deviceId?: string },\n ) {\n this.localConfig = localConfig;\n this.remoteConfigClient = remoteConfigClient;\n this.sessionId = identity?.sessionId;\n this.deviceId = identity?.deviceId;\n }\n\n async generateJoinedConfig(): Promise<SessionReplayConfigs> {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n // We always want captureEnabled to be true, unless there's an override\n // in the remote config.\n config.captureEnabled = true;\n let sessionReplayRemoteConfig: SessionReplayRemoteConfig | undefined;\n\n try {\n // Subscribe with a timeout so the SDK prefers the remote response and only falls back\n // to cache after the budget elapses. 'all' mode would race a synchronous cache read\n // against the network and resolve on whichever fires first — cache always wins, so a\n // stale cache silently overrides the live config (SR-4234).\n await new Promise<void>((resolve, reject) => {\n this.remoteConfigClient.subscribe(\n 'configs.sessionReplay',\n { timeout: REMOTE_CONFIG_TIMEOUT_MS },\n (remoteConfig: RemoteConfig | null, source: Source) => {\n this.localConfig.loggerProvider.debug(\n `Session Replay remote configuration received from ${source}:`,\n JSON.stringify(remoteConfig, null, 2),\n );\n\n if (!remoteConfig) {\n reject(new Error('No remote config received'));\n return;\n }\n\n // remoteConfig is already filtered to 'configs.sessionReplay' namespace\n const namespaceConfig = remoteConfig as SessionReplayRemoteConfig;\n const samplingConfig = namespaceConfig.sr_sampling_config;\n const privacyConfig = namespaceConfig.sr_privacy_config;\n const targetingConfig = namespaceConfig.sr_targeting_config;\n\n // Captured for the sr.trc.config.received diagnostics event below (remote vs cache is\n // the crux of SR-4234 stale-cache reports).\n const samplingForLog = samplingConfig as { capture_enabled?: boolean; sample_rate?: number } | undefined;\n const targetingSegments = (targetingConfig as unknown as { segments?: unknown[] } | undefined)?.segments;\n\n const ugcFilterRules = config.interactionConfig?.ugcFilterRules;\n // This is intentionally forced to only be set through the remote config.\n config.interactionConfig = namespaceConfig.sr_interaction_config;\n if (config.interactionConfig && ugcFilterRules) {\n config.interactionConfig.ugcFilterRules = ugcFilterRules;\n }\n\n // This is intentionally forced to only be set through the remote config.\n config.loggingConfig = namespaceConfig.sr_logging_config;\n\n // Team-visible diagnostics: which SOURCE the config came from (remote vs cache — the\n // crux of SR-4234) and whether targeting was present. Counters aggregate across the\n // customer's sessions; the event carries the full context (source, sample rate,\n // segment count) as queryable log fields. No-op when diagnostics isn't configured.\n try {\n const diagnosticsClient = this.localConfig.diagnosticsClient;\n diagnosticsClient?.increment(SrDiagnostic.configSource(String(source)));\n diagnosticsClient?.increment(\n targetingConfig ? SrDiagnostic.configHasTargeting : SrDiagnostic.configNoTargeting,\n );\n diagnosticsClient?.recordEvent(SrDiagnostic.configReceived, {\n sessionId: this.sessionId,\n deviceId: this.deviceId,\n srId:\n this.deviceId != null && this.sessionId != null ? `${this.deviceId}/${this.sessionId}` : undefined,\n source: String(source),\n hasSampling: !!samplingConfig,\n captureEnabled: samplingForLog?.capture_enabled,\n sampleRate: samplingForLog?.sample_rate,\n hasTargeting: !!targetingConfig,\n targetingSegmentCount: Array.isArray(targetingSegments) ? targetingSegments.length : undefined,\n hasPrivacy: !!privacyConfig,\n });\n // Flush now (vs the client's ~5-min timer). One capture POST per event — higher\n // volume; revisit/gate before production.\n void diagnosticsClient?._flush?.();\n } catch {\n // diagnostics is best-effort\n }\n\n if (samplingConfig || privacyConfig || targetingConfig) {\n sessionReplayRemoteConfig = {};\n if (samplingConfig) {\n sessionReplayRemoteConfig.sr_sampling_config = samplingConfig;\n }\n if (privacyConfig) {\n sessionReplayRemoteConfig.sr_privacy_config = privacyConfig;\n }\n if (targetingConfig) {\n sessionReplayRemoteConfig.sr_targeting_config = targetingConfig;\n }\n }\n\n resolve();\n },\n );\n });\n } catch (error) {\n this.localConfig.loggerProvider.error('Failed to generate joined config: ', error);\n try {\n this.localConfig.diagnosticsClient?.increment(SrDiagnostic.configFetchFailed);\n void this.localConfig.diagnosticsClient?._flush?.();\n } catch {\n // diagnostics is best-effort\n }\n config.captureEnabled = false;\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: undefined,\n };\n }\n\n if (!sessionReplayRemoteConfig) {\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: sessionReplayRemoteConfig,\n };\n }\n\n const {\n sr_sampling_config: samplingConfig,\n sr_privacy_config: remotePrivacyConfig,\n sr_targeting_config: targetingConfig,\n } = sessionReplayRemoteConfig;\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'sample_rate')) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'min_session_duration_ms')) {\n config.minSessionDurationMs = this.sanitizeMinSessionDurationMs(samplingConfig.min_session_duration_ms);\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n this.localConfig.loggerProvider.debug(\n 'Remote config successfully fetched, but no values set for project, Session Replay capture enabled.',\n );\n }\n\n // Remote config join acts somewhat like a left join between the remote and the local\n // config. That is, remote config has precedence over local values as with sampling.\n // However, non conflicting values will be added to the lists.\n // Here's an example to illustrate:\n //\n // Remote config: {'.selector1': 'MASK', '.selector2': 'UNMASK'}\n // Local config: {'.selector1': 'UNMASK', '.selector3': 'MASK'}\n //\n // Resolved config: {'.selector1': 'MASK', '.selector2': 'UNMASK', '.selector3': 'MASK'}\n // config.privacyConfig = {\n // ...(config.privacyConfig ?? {}),\n // ...remotePrivacyConfig,\n // };\n\n if (remotePrivacyConfig) {\n const localPrivacyConfig: PrivacyConfig = config.privacyConfig ?? {};\n\n const joinedPrivacyConfig: Required<PrivacyConfig> & { blockSelector: string[] } = {\n defaultMaskLevel: remotePrivacyConfig.defaultMaskLevel ?? localPrivacyConfig.defaultMaskLevel ?? 'medium',\n blockSelector: [],\n maskSelector: [],\n unmaskSelector: [],\n maskAttributes: [\n ...new Set([...(localPrivacyConfig.maskAttributes ?? []), ...(remotePrivacyConfig.maskAttributes ?? [])]),\n ],\n urlMaskLevels: [...(remotePrivacyConfig.urlMaskLevels ?? []), ...(localPrivacyConfig.urlMaskLevels ?? [])],\n };\n\n const privacyConfigSelectorMap = (privacyConfig: PrivacyConfig): Record<string, 'mask' | 'unmask' | 'block'> => {\n const selectorMap: Record<string, 'mask' | 'unmask' | 'block'> = {};\n if (typeof privacyConfig.blockSelector === 'string') {\n privacyConfig.blockSelector = [privacyConfig.blockSelector];\n }\n\n for (const selector of privacyConfig.blockSelector ?? []) {\n selectorMap[selector] = 'block';\n }\n for (const selector of privacyConfig.maskSelector ?? []) {\n selectorMap[selector] = 'mask';\n }\n for (const selector of privacyConfig.unmaskSelector ?? []) {\n selectorMap[selector] = 'unmask';\n }\n return selectorMap;\n };\n\n const selectorMap: Record<string, 'mask' | 'unmask' | 'block'> = {\n ...privacyConfigSelectorMap(localPrivacyConfig),\n ...privacyConfigSelectorMap(remotePrivacyConfig),\n };\n\n for (const [selector, selectorType] of Object.entries(selectorMap)) {\n if (selectorType === 'mask') {\n joinedPrivacyConfig.maskSelector.push(selector);\n } else if (selectorType === 'block') {\n joinedPrivacyConfig.blockSelector.push(selector);\n } else if (selectorType === 'unmask') {\n joinedPrivacyConfig.unmaskSelector.push(selector);\n }\n }\n\n config.privacyConfig = removeInvalidSelectorsFromPrivacyConfig(\n joinedPrivacyConfig,\n this.localConfig.loggerProvider,\n );\n }\n\n if (targetingConfig && Object.keys(targetingConfig).length > 0) {\n config.targetingConfig = targetingConfig;\n }\n\n this.localConfig.loggerProvider.debug(\n JSON.stringify({ name: 'session replay joined config', config: getDebugConfig(config) }, null, 2),\n );\n\n return {\n localConfig: this.localConfig,\n joinedConfig: config,\n remoteConfig: sessionReplayRemoteConfig,\n };\n }\n\n /**\n * Defensive bounds for the remote-supplied min_session_duration_ms. A misconfigured\n * value (e.g. 30_000_000) would silently suppress every replay until the config is\n * pushed again, so we clamp to a sane ceiling and warn on out-of-range inputs.\n * Returns undefined for clearly invalid values so the gate falls back to disabled\n * rather than carrying a NaN through downstream comparisons.\n */\n private sanitizeMinSessionDurationMs(raw: unknown): number | undefined {\n if (typeof raw !== 'number' || !Number.isFinite(raw)) {\n this.localConfig.loggerProvider.warn(\n `min_session_duration_ms remote value is not a finite number (got ${String(raw)}); ignoring.`,\n );\n return undefined;\n }\n if (raw < 0) {\n this.localConfig.loggerProvider.warn(`min_session_duration_ms remote value is negative (${raw}); ignoring.`);\n return undefined;\n }\n if (raw > MAX_MIN_SESSION_DURATION_MS) {\n this.localConfig.loggerProvider.warn(\n `min_session_duration_ms remote value ${raw} exceeds ${MAX_MIN_SESSION_DURATION_MS}ms ceiling; clamping.`,\n );\n return MAX_MIN_SESSION_DURATION_MS;\n }\n return raw;\n }\n}\n\n/**\n * Upper bound for the remote-configured replay min duration. 60 seconds is well above\n * any reasonable bounce threshold; values higher than this are almost certainly typos\n * (e.g. seconds confused for milliseconds, or an extra zero) and would otherwise\n * suppress every replay until the config is corrected.\n */\nexport const MAX_MIN_SESSION_DURATION_MS = 60_000;\n\nexport const createSessionReplayJoinedConfigGenerator = async (apiKey: string, options: SessionReplayOptions) => {\n const localConfig = new SessionReplayLocalConfig(apiKey, options);\n\n const remoteConfigClient = new RemoteConfigClient(\n apiKey,\n localConfig.loggerProvider,\n localConfig.serverZone,\n options.configServerUrl,\n );\n\n return new SessionReplayJoinedConfigGenerator(remoteConfigClient, localConfig, {\n sessionId: options.sessionId,\n deviceId: options.deviceId,\n });\n};\n"]}
@@ -10,11 +10,13 @@
10
10
  export declare const SR_DIAGNOSTIC_PREFIX = "sr.trc";
11
11
  export declare const SrDiagnostic: {
12
12
  readonly init: "sr.trc.init";
13
+ readonly sessionChanged: "sr.trc.session.changed";
13
14
  readonly configSource: (source: string) => string;
14
15
  readonly configHasTargeting: "sr.trc.config.has_targeting";
15
16
  readonly configNoTargeting: "sr.trc.config.no_targeting";
16
17
  readonly configFetchFailed: "sr.trc.config.fetch_failed";
17
18
  readonly configReceived: "sr.trc.config.received";
19
+ readonly targetingTrigger: "sr.trc.targeting.trigger";
18
20
  readonly evalTrigger: (trigger: string) => string;
19
21
  readonly evalNoConfig: "sr.trc.eval.no_config";
20
22
  readonly evalMissingPrereq: "sr.trc.eval.missing_prereq";
@@ -39,5 +41,8 @@ export declare const SrDiagnostic: {
39
41
  readonly decision: "sr.trc.decision";
40
42
  readonly urlChange: "sr.trc.url_change";
41
43
  readonly urlChangeEvent: "sr.trc.url_change";
44
+ readonly urlListenerSetup: "sr.trc.url_listener.setup";
45
+ readonly urlListenerAttached: "sr.trc.url_listener.attached";
46
+ readonly urlListenerSkipped: "sr.trc.url_listener.skipped";
42
47
  };
43
48
  //# sourceMappingURL=diagnostics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAI7C,eAAO,MAAM,YAAY;;oCAKA,MAAM;;;;;oCAQN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CA8BrB,CAAC"}
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAI7C,eAAO,MAAM,YAAY;;;oCAUA,MAAM;;;;;;oCAUN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCrB,CAAC"}
@@ -12,12 +12,17 @@ var p = SR_DIAGNOSTIC_PREFIX;
12
12
  export var SrDiagnostic = {
13
13
  // ── Init (Q1: did init even happen?) ─────────────────────────────────────
14
14
  init: "".concat(p, ".init"),
15
+ // ── Session lifecycle ────────────────────────────────────────────────────
16
+ // SR session id changed (timeout / explicit setSessionId / custom session id). New tabs and
17
+ // page refreshes do NOT change the session id, so this is distinct from a fresh init.
18
+ sessionChanged: "".concat(p, ".session.changed"),
15
19
  // ── Remote config fetch (joined-config) ──────────────────────────────────
16
20
  configSource: function (source) { return "".concat(p, ".config.source.").concat(source); },
17
21
  configHasTargeting: "".concat(p, ".config.has_targeting"),
18
22
  configNoTargeting: "".concat(p, ".config.no_targeting"),
19
23
  configFetchFailed: "".concat(p, ".config.fetch_failed"),
20
24
  configReceived: "".concat(p, ".config.received"),
25
+ targetingTrigger: "".concat(p, ".targeting.trigger"),
21
26
  // ── Targeting evaluation (evaluateTargetingAndCapture) ────────────────────
22
27
  // Q2 (did eval run?), Q3 (working/failed?), Q4 (missing value?), Q5 (all params).
23
28
  evalTrigger: function (trigger) { return "".concat(p, ".eval.").concat(trigger); },
@@ -46,6 +51,11 @@ export var SrDiagnostic = {
46
51
  decision: "".concat(p, ".decision"),
47
52
  // ── SPA URL change (setupUrlChangeListener) ──────────────────────────────
48
53
  urlChange: "".concat(p, ".url_change"),
49
- urlChangeEvent: "".concat(p, ".url_change"), // event (with props); same name, logs vs metric
54
+ urlChangeEvent: "".concat(p, ".url_change"),
55
+ // Was the URL-change listener even wired up? (covers "the SDK never saw any navigation"
56
+ // because the listener was never attached — e.g. no targeting config, or no global scope.)
57
+ urlListenerSetup: "".concat(p, ".url_listener.setup"),
58
+ urlListenerAttached: "".concat(p, ".url_listener.attached"),
59
+ urlListenerSkipped: "".concat(p, ".url_listener.skipped"), // counter + event: listener NOT attached (with reason)
50
60
  };
51
61
  //# sourceMappingURL=diagnostics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAG,QAAQ,CAAC;AAE7C,IAAM,CAAC,GAAG,oBAAoB,CAAC;AAE/B,MAAM,CAAC,IAAM,YAAY,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IACnC,aAAa,EAAE,UAAG,CAAC,qBAAkB;IACrC,QAAQ,EAAE,UAAG,CAAC,cAAW;IAEzB,4EAA4E;IAC5E,SAAS,EAAE,UAAG,CAAC,gBAAa;IAC5B,cAAc,EAAE,UAAG,CAAC,gBAAa,EAAE,gDAAgD;CAC3E,CAAC","sourcesContent":["/**\n * Centralized names for Session Replay diagnostics shipped via the analytics DiagnosticsClient.\n *\n * Every name shares SR_DIAGNOSTIC_PREFIX so they group together in DataDog as\n * `sdk.diagnostics.sr.trc.*`. The diagnostics pipeline prepends `sdk.diagnostics.` and appends\n * `.count` to counters / `.{min,max,avg,count}` to histograms; events are forwarded to DataDog\n * Logs keyed by `event_name`. Keep ALL SR diagnostic names here so the prefix stays unified —\n * changing the namespace is then a one-line edit.\n */\nexport const SR_DIAGNOSTIC_PREFIX = 'sr.trc';\n\nconst p = SR_DIAGNOSTIC_PREFIX;\n\nexport const SrDiagnostic = {\n // ── Init (Q1: did init even happen?) ─────────────────────────────────────\n init: `${p}.init`, // counter + event(with props): fires once per init()\n\n // ── Remote config fetch (joined-config) ──────────────────────────────────\n configSource: (source: string) => `${p}.config.source.${source}`,\n configHasTargeting: `${p}.config.has_targeting`,\n configNoTargeting: `${p}.config.no_targeting`,\n configFetchFailed: `${p}.config.fetch_failed`,\n configReceived: `${p}.config.received`, // event (with props)\n\n // ── Targeting evaluation (evaluateTargetingAndCapture) ────────────────────\n // Q2 (did eval run?), Q3 (working/failed?), Q4 (missing value?), Q5 (all params).\n evalTrigger: (trigger: string) => `${p}.eval.${trigger}`, // init | urlchange | event\n evalNoConfig: `${p}.eval.no_config`,\n evalMissingPrereq: `${p}.eval.missing_prereq`, // Q4: sessionId/config/deviceId missing\n evalMatch: `${p}.eval.match`,\n evalNoMatch: `${p}.eval.no_match`,\n evalError: `${p}.eval.error`, // Q3: targeting engine threw\n evalStaleDiscarded: `${p}.eval.stale_discarded`,\n evalSkippedAlreadyMatched: `${p}.eval.skipped_already_matched`,\n evalDurationMs: `${p}.eval.duration_ms`, // histogram\n evalEvent: `${p}.eval`, // event (with ALL eval params — Q5)\n evalResult: `${p}.eval.result`, // event: raw engine verdict (variantKey) — why match/no-match\n\n // ── Recording execution (getShouldRecord said yes — did rrweb actually start?) ──\n recordStarted: `${p}.record.started`, // event: capture began (carries the srId the replay uploads under)\n recordNoRecordFn: `${p}.record.no_record_fn`, // counter + event: rrweb import returned nothing\n sendSuppressedMinDuration: `${p}.send.suppressed_min_duration`, // counter: events held back by min_session_duration\n\n // ── Record / no-record gate (getShouldRecord) ────────────────────────────\n gateNoIdentifiers: `${p}.gate.no_identifiers`, // Q4: no config/sessionId at gate time\n gateCaptureDisabled: `${p}.gate.capture_disabled`,\n gateOptOut: `${p}.gate.optout`,\n gateTrcMatch: `${p}.gate.trc_match`,\n gateTrcNoMatch: `${p}.gate.trc_no_match`,\n gateSampleIn: `${p}.gate.sample_in`,\n gateSampleOut: `${p}.gate.sample_out`,\n decision: `${p}.decision`, // event (with props)\n\n // ── SPA URL change (setupUrlChangeListener) ──────────────────────────────\n urlChange: `${p}.url_change`,\n urlChangeEvent: `${p}.url_change`, // event (with props); same name, logs vs metric\n} as const;\n"]}
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAG,QAAQ,CAAC;AAE7C,IAAM,CAAC,GAAG,oBAAoB,CAAC;AAE/B,MAAM,CAAC,IAAM,YAAY,GAAG;IAC1B,4EAA4E;IAC5E,IAAI,EAAE,UAAG,CAAC,UAAO;IAEjB,4EAA4E;IAC5E,4FAA4F;IAC5F,sFAAsF;IACtF,cAAc,EAAE,UAAG,CAAC,qBAAkB;IAEtC,4EAA4E;IAC5E,YAAY,EAAE,UAAC,MAAc,IAAK,OAAA,UAAG,CAAC,4BAAkB,MAAM,CAAE,EAA9B,CAA8B;IAChE,kBAAkB,EAAE,UAAG,CAAC,0BAAuB;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AAa;IACjC,wFAAwF;IACxF,2FAA2F;IAC3F,gBAAgB,EAAE,UAAG,CAAC,wBAAqB;IAC3C,mBAAmB,EAAE,UAAG,CAAC,2BAAwB;IACjD,kBAAkB,EAAE,UAAG,CAAC,0BAAuB,EAAE,uDAAuD;CAChG,CAAC","sourcesContent":["/**\n * Centralized names for Session Replay diagnostics shipped via the analytics DiagnosticsClient.\n *\n * Every name shares SR_DIAGNOSTIC_PREFIX so they group together in DataDog as\n * `sdk.diagnostics.sr.trc.*`. The diagnostics pipeline prepends `sdk.diagnostics.` and appends\n * `.count` to counters / `.{min,max,avg,count}` to histograms; events are forwarded to DataDog\n * Logs keyed by `event_name`. Keep ALL SR diagnostic names here so the prefix stays unified —\n * changing the namespace is then a one-line edit.\n */\nexport const SR_DIAGNOSTIC_PREFIX = 'sr.trc';\n\nconst p = SR_DIAGNOSTIC_PREFIX;\n\nexport const SrDiagnostic = {\n // ── Init (Q1: did init even happen?) ─────────────────────────────────────\n init: `${p}.init`, // counter + event(with props): fires once per init()\n\n // ── Session lifecycle ────────────────────────────────────────────────────\n // SR session id changed (timeout / explicit setSessionId / custom session id). New tabs and\n // page refreshes do NOT change the session id, so this is distinct from a fresh init.\n sessionChanged: `${p}.session.changed`, // event (with from/to)\n\n // ── Remote config fetch (joined-config) ──────────────────────────────────\n configSource: (source: string) => `${p}.config.source.${source}`,\n configHasTargeting: `${p}.config.has_targeting`,\n configNoTargeting: `${p}.config.no_targeting`,\n configFetchFailed: `${p}.config.fetch_failed`,\n configReceived: `${p}.config.received`, // event (with props)\n\n targetingTrigger: `${p}.targeting.trigger`, // event: targeting evaluation triggered\n\n // ── Targeting evaluation (evaluateTargetingAndCapture) ────────────────────\n // Q2 (did eval run?), Q3 (working/failed?), Q4 (missing value?), Q5 (all params).\n evalTrigger: (trigger: string) => `${p}.eval.${trigger}`, // init | urlchange | event\n evalNoConfig: `${p}.eval.no_config`,\n evalMissingPrereq: `${p}.eval.missing_prereq`, // Q4: sessionId/config/deviceId missing\n evalMatch: `${p}.eval.match`,\n evalNoMatch: `${p}.eval.no_match`,\n evalError: `${p}.eval.error`, // Q3: targeting engine threw\n evalStaleDiscarded: `${p}.eval.stale_discarded`,\n evalSkippedAlreadyMatched: `${p}.eval.skipped_already_matched`,\n evalDurationMs: `${p}.eval.duration_ms`, // histogram\n evalEvent: `${p}.eval`, // event (with ALL eval params — Q5)\n evalResult: `${p}.eval.result`, // event: raw engine verdict (variantKey) — why match/no-match\n\n // ── Recording execution (getShouldRecord said yes — did rrweb actually start?) ──\n recordStarted: `${p}.record.started`, // event: capture began (carries the srId the replay uploads under)\n recordNoRecordFn: `${p}.record.no_record_fn`, // counter + event: rrweb import returned nothing\n sendSuppressedMinDuration: `${p}.send.suppressed_min_duration`, // counter: events held back by min_session_duration\n\n // ── Record / no-record gate (getShouldRecord) ────────────────────────────\n gateNoIdentifiers: `${p}.gate.no_identifiers`, // Q4: no config/sessionId at gate time\n gateCaptureDisabled: `${p}.gate.capture_disabled`,\n gateOptOut: `${p}.gate.optout`,\n gateTrcMatch: `${p}.gate.trc_match`,\n gateTrcNoMatch: `${p}.gate.trc_no_match`,\n gateSampleIn: `${p}.gate.sample_in`,\n gateSampleOut: `${p}.gate.sample_out`,\n decision: `${p}.decision`, // event (with props)\n\n // ── SPA URL change (setupUrlChangeListener) ──────────────────────────────\n urlChange: `${p}.url_change`,\n urlChangeEvent: `${p}.url_change`, // event (with props); same name, logs vs metric\n // Was the URL-change listener even wired up? (covers \"the SDK never saw any navigation\"\n // because the listener was never attached — e.g. no targeting config, or no global scope.)\n urlListenerSetup: `${p}.url_listener.setup`, // event: the needsUrlTracking decision + its inputs\n urlListenerAttached: `${p}.url_listener.attached`, // event: subscribeToUrlChanges succeeded (with polling opts)\n urlListenerSkipped: `${p}.url_listener.skipped`, // counter + event: listener NOT attached (with reason)\n} as const;\n"]}
@@ -35,6 +35,12 @@ export interface SubscribeToUrlChangesOptions {
35
35
  enablePolling?: boolean;
36
36
  /** Polling interval in ms when enablePolling is true (default: 1000) */
37
37
  pollingInterval?: number;
38
+ /**
39
+ * Optional debug logger, called once per poll tick (only on the polling path). Lets the SDK
40
+ * confirm in the browser console that the interval is actually firing — useful when verifying
41
+ * that enableUrlChangePolling took effect for an SPA that bypasses the History API.
42
+ */
43
+ log?: (message: string) => void;
38
44
  }
39
45
  /**
40
46
  * Single helper for URL change detection. Supports:
@@ -1 +1 @@
1
- {"version":3,"file":"url-tracking-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/url-tracking-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,6EAA6E;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,oEAAoE;AACpE,MAAM,WAAW,4BAA4B;IAC3C,2FAA2F;IAC3F,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACnC,OAAO,GAAE,4BAAiC,GACzC,MAAM,IAAI,CAqGZ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,wBAA6B,GACrC,YAAY,CAAC,wBAAwB,CAAC,CAqFxC;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,wCAA4B,CAAC"}
1
+ {"version":3,"file":"url-tracking-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/url-tracking-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,6EAA6E;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,oEAAoE;AACpE,MAAM,WAAW,4BAA4B;IAC3C,2FAA2F;IAC3F,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACnC,OAAO,GAAE,4BAAiC,GACzC,MAAM,IAAI,CAuGZ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,wBAA6B,GACrC,YAAY,CAAC,wBAAwB,CAAC,CAqFxC;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,wCAA4B,CAAC"}
@@ -25,12 +25,14 @@ export function subscribeToUrlChanges(globalScope, onUrlChange, options) {
25
25
  return;
26
26
  };
27
27
  }
28
- var _a = options.enablePolling, enablePolling = _a === void 0 ? false : _a, _b = options.pollingInterval, pollingInterval = _b === void 0 ? DEFAULT_URL_CHANGE_POLLING_INTERVAL : _b;
28
+ var _a = options.enablePolling, enablePolling = _a === void 0 ? false : _a, _b = options.pollingInterval, pollingInterval = _b === void 0 ? DEFAULT_URL_CHANGE_POLLING_INTERVAL : _b, log = options.log;
29
29
  if (enablePolling) {
30
30
  var getHref_1 = function () { var _a; return (_a = globalScope.location.href) !== null && _a !== void 0 ? _a : ''; };
31
31
  var lastHref_1 = getHref_1();
32
32
  var id_1 = globalScope.setInterval(function () {
33
33
  var href = getHref_1();
34
+ // Logged every tick (not just on change) so we can confirm the polling loop is alive.
35
+ log === null || log === void 0 ? void 0 : log("URL polling tick (href=".concat(href, ", changed=").concat(String(href !== lastHref_1), ")."));
34
36
  if (href === lastHref_1) {
35
37
  return;
36
38
  }