@servicetitan/datadog-rum 40.2.2 → 40.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/create-impl.d.ts.map +1 -1
  2. package/dist/create-impl.js +3 -0
  3. package/dist/create-impl.js.map +1 -1
  4. package/dist/datadog-provider.d.ts +3 -1
  5. package/dist/datadog-provider.d.ts.map +1 -1
  6. package/dist/datadog-provider.js +3 -1
  7. package/dist/datadog-provider.js.map +1 -1
  8. package/dist/get-env.d.ts +7 -0
  9. package/dist/get-env.d.ts.map +1 -0
  10. package/dist/get-env.js +26 -0
  11. package/dist/get-env.js.map +1 -0
  12. package/dist/hash-routing.d.ts +5 -1
  13. package/dist/hash-routing.d.ts.map +1 -1
  14. package/dist/hash-routing.js +23 -8
  15. package/dist/hash-routing.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/sanitize-view-name.d.ts.map +1 -1
  21. package/dist/sanitize-view-name.js +10 -0
  22. package/dist/sanitize-view-name.js.map +1 -1
  23. package/dist/shared-impl.d.ts +1 -1
  24. package/dist/shared-impl.d.ts.map +1 -1
  25. package/dist/shared-impl.js.map +1 -1
  26. package/dist/types.d.ts +1 -2
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js.map +1 -1
  29. package/package.json +8 -3
  30. package/src/create-impl.ts +2 -0
  31. package/src/datadog-provider.tsx +7 -3
  32. package/src/get-env.ts +27 -0
  33. package/src/hash-routing.tsx +28 -9
  34. package/src/index.ts +1 -0
  35. package/src/sanitize-view-name.tsx +17 -0
  36. package/src/shared-impl.ts +1 -1
  37. package/src/types.ts +6 -2
  38. package/src/__mocks__/before-send-data.ts +0 -538
  39. package/src/__mocks__/index.ts +0 -7
  40. package/src/__mocks__/init-config.ts +0 -6
  41. package/src/__mocks__/mfe-host.ts +0 -7
  42. package/src/__mocks__/process-event.ts +0 -20
  43. package/src/__mocks__/reset-shared-impl.ts +0 -8
  44. package/src/__mocks__/tracing-urls.ts +0 -30
  45. package/src/__mocks__/types.ts +0 -1
  46. package/src/__tests__/before-send.test.ts +0 -76
  47. package/src/__tests__/build-allowed-tracing-urls.test.ts +0 -120
  48. package/src/__tests__/build-before-send.test.ts +0 -193
  49. package/src/__tests__/create-impl.test.ts +0 -427
  50. package/src/__tests__/datadog-provider.test.tsx +0 -145
  51. package/src/__tests__/dd-rum-guard.test.ts +0 -73
  52. package/src/__tests__/element-service-recorder.test.ts +0 -127
  53. package/src/__tests__/enrich-event.test.ts +0 -139
  54. package/src/__tests__/get-shared.test.ts +0 -56
  55. package/src/__tests__/handle-resource.test.ts +0 -76
  56. package/src/__tests__/hash-routing.test.tsx +0 -70
  57. package/src/__tests__/init.test.ts +0 -69
  58. package/src/__tests__/integration.test.ts +0 -147
  59. package/src/__tests__/resolve-path-service.test.ts +0 -130
  60. package/src/__tests__/sanitize-view-name.test.tsx +0 -92
  61. package/src/__tests__/set-user.test.ts +0 -61
  62. package/src/__tests__/use-rum-service.test.tsx +0 -82
  63. package/src/runtime-override/__tests__/dev-console.test.ts +0 -158
  64. package/src/runtime-override/__tests__/override.test.ts +0 -109
@@ -1 +1 @@
1
- {"version":3,"file":"create-impl.d.ts","sourceRoot":"","sources":["../src/create-impl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAiHvC"}
1
+ {"version":3,"file":"create-impl.d.ts","sourceRoot":"","sources":["../src/create-impl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAkHvC"}
@@ -3,6 +3,7 @@ import { buildAllowedTracingUrls } from './build-allowed-tracing-urls';
3
3
  import { buildBeforeSend } from './build-before-send';
4
4
  import { installDdRumGuard } from './dd-rum-guard';
5
5
  import { elementServiceRecorder } from './element-service-recorder';
6
+ import { getEnv } from './get-env';
6
7
  import { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';
7
8
  const DEFAULTS = {
8
9
  sessionSampleRate: 100,
@@ -20,6 +21,7 @@ const DEFAULTS = {
20
21
  services: new Map()
21
22
  };
22
23
  function initializeSdk({ service, application, enabled, initializedBy }) {
24
+ var _sdkConfigPart_env;
23
25
  if (datadogRum.getInitConfiguration()) {
24
26
  // eslint-disable-next-line no-console
25
27
  console.warn('[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.');
@@ -32,6 +34,7 @@ const DEFAULTS = {
32
34
  datadogRum.init({
33
35
  ...DEFAULTS,
34
36
  ...sdkConfigPart,
37
+ env: ((_sdkConfigPart_env = sdkConfigPart.env) === null || _sdkConfigPart_env === void 0 ? void 0 : _sdkConfigPart_env.length) ? sdkConfigPart.env : getEnv(),
35
38
  service: service.name,
36
39
  beforeSend: buildBeforeSend(state),
37
40
  allowedTracingUrls: buildAllowedTracingUrls(state)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create-impl.ts"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { buildAllowedTracingUrls } from './build-allowed-tracing-urls';\nimport { buildBeforeSend } from './build-before-send';\nimport { installDdRumGuard } from './dd-rum-guard';\nimport { elementServiceRecorder } from './element-service-recorder';\nimport { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';\nimport type { SharedImpl } from './shared-impl';\nimport type { ApplicationConfig, PendingApplication, ServiceConfig, State } from './types';\n\nconst DEFAULTS = {\n sessionSampleRate: 100,\n sessionReplaySampleRate: 0,\n defaultPrivacyLevel: 'mask-user-input',\n} as const;\n\n/**\n * Interop surface: stored on globalThis, shared across independently\n * deployed bundles. First bundle to load wins. Append-only — never\n * remove or change method signatures.\n */\nexport function createImpl(): SharedImpl {\n let initialized = false;\n let offer: PendingApplication | undefined;\n const state: State = {\n services: new Map(),\n };\n\n function initializeSdk({\n service,\n application,\n enabled,\n initializedBy,\n }: {\n service: ServiceConfig;\n application: ApplicationConfig;\n enabled: boolean;\n initializedBy?: string;\n }): boolean {\n if (datadogRum.getInitConfiguration()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.'\n );\n return false;\n }\n\n const { beforeSend: appBeforeSend, ...sdkConfigPart } = application;\n if (appBeforeSend) {\n state.applicationBeforeSend = appBeforeSend;\n }\n datadogRum.init({\n ...DEFAULTS,\n ...sdkConfigPart,\n service: service.name,\n beforeSend: buildBeforeSend(state),\n allowedTracingUrls: buildAllowedTracingUrls(state),\n });\n if (!enabled) {\n datadogRum.setGlobalContextProperty(DATADOG_RUM_FOR_DEV, true);\n }\n installDdRumGuard(datadogRum);\n elementServiceRecorder.install();\n if (initializedBy) {\n datadogRum.setGlobalContextProperty('initializedBy', { service: initializedBy });\n }\n initialized = true;\n return true;\n }\n\n function registerService({ name, ...reg }: ServiceConfig): void {\n const existing = state.services.get(name);\n state.services.set(name, { ...reg, context: existing?.context });\n }\n\n function startSdk(\n service: ServiceConfig,\n application: ApplicationConfig | undefined,\n enabled: boolean\n ): boolean {\n if (application && !enabled) {\n installDevConsole();\n }\n\n if (initialized) {\n if (application) {\n // eslint-disable-next-line no-console\n console.info(\n `[datadog-rum] init: application config from '${service.name}' ignored; the SDK is already started.`\n );\n }\n return false;\n }\n\n if (application) {\n offer ??= { service, application };\n }\n\n if (!offer || (!enabled && !isForceEnabled())) {\n return false;\n }\n\n const startedByOfferer = offer.service.name === service.name;\n if (application && !startedByOfferer) {\n // eslint-disable-next-line no-console\n console.info(\n `[datadog-rum] init: application config from '${service.name}' ignored; started the application offered by '${offer.service.name}'.`\n );\n }\n\n return initializeSdk({\n service: offer.service,\n application: offer.application,\n enabled,\n initializedBy: startedByOfferer ? undefined : service.name,\n });\n }\n\n return {\n init({ service, application, enabled = true }) {\n const initializedSdk = startSdk(service, application, enabled);\n registerService(service);\n\n return {\n cleanup: () => state.services.delete(service.name),\n initializedSdk,\n };\n },\n\n setServiceContext(key, context) {\n const existing = state.services.get(key);\n state.services.set(key, { ...existing, context });\n },\n };\n}\n"],"names":["datadogRum","buildAllowedTracingUrls","buildBeforeSend","installDdRumGuard","elementServiceRecorder","DATADOG_RUM_FOR_DEV","installDevConsole","isForceEnabled","DEFAULTS","sessionSampleRate","sessionReplaySampleRate","defaultPrivacyLevel","createImpl","initialized","offer","state","services","Map","initializeSdk","service","application","enabled","initializedBy","getInitConfiguration","console","warn","beforeSend","appBeforeSend","sdkConfigPart","applicationBeforeSend","init","name","allowedTracingUrls","setGlobalContextProperty","install","registerService","reg","existing","get","set","context","startSdk","info","startedByOfferer","undefined","initializedSdk","cleanup","delete","setServiceContext","key"],"mappings":"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"}
1
+ {"version":3,"sources":["../src/create-impl.ts"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { buildAllowedTracingUrls } from './build-allowed-tracing-urls';\nimport { buildBeforeSend } from './build-before-send';\nimport { installDdRumGuard } from './dd-rum-guard';\nimport { elementServiceRecorder } from './element-service-recorder';\nimport { getEnv } from './get-env';\nimport { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';\nimport type { SharedImpl } from './shared-impl';\nimport type { ApplicationConfig, PendingApplication, ServiceConfig, State } from './types';\n\nconst DEFAULTS = {\n sessionSampleRate: 100,\n sessionReplaySampleRate: 0,\n defaultPrivacyLevel: 'mask-user-input',\n} as const;\n\n/**\n * Interop surface: stored on globalThis, shared across independently\n * deployed bundles. First bundle to load wins. Append-only — never\n * remove or change method signatures.\n */\nexport function createImpl(): SharedImpl {\n let initialized = false;\n let offer: PendingApplication | undefined;\n const state: State = {\n services: new Map(),\n };\n\n function initializeSdk({\n service,\n application,\n enabled,\n initializedBy,\n }: {\n service: ServiceConfig;\n application: ApplicationConfig;\n enabled: boolean;\n initializedBy?: string;\n }): boolean {\n if (datadogRum.getInitConfiguration()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.'\n );\n return false;\n }\n\n const { beforeSend: appBeforeSend, ...sdkConfigPart } = application;\n if (appBeforeSend) {\n state.applicationBeforeSend = appBeforeSend;\n }\n datadogRum.init({\n ...DEFAULTS,\n ...sdkConfigPart,\n env: sdkConfigPart.env?.length ? sdkConfigPart.env : getEnv(),\n service: service.name,\n beforeSend: buildBeforeSend(state),\n allowedTracingUrls: buildAllowedTracingUrls(state),\n });\n if (!enabled) {\n datadogRum.setGlobalContextProperty(DATADOG_RUM_FOR_DEV, true);\n }\n installDdRumGuard(datadogRum);\n elementServiceRecorder.install();\n if (initializedBy) {\n datadogRum.setGlobalContextProperty('initializedBy', { service: initializedBy });\n }\n initialized = true;\n return true;\n }\n\n function registerService({ name, ...reg }: ServiceConfig): void {\n const existing = state.services.get(name);\n state.services.set(name, { ...reg, context: existing?.context });\n }\n\n function startSdk(\n service: ServiceConfig,\n application: ApplicationConfig | undefined,\n enabled: boolean\n ): boolean {\n if (application && !enabled) {\n installDevConsole();\n }\n\n if (initialized) {\n if (application) {\n // eslint-disable-next-line no-console\n console.info(\n `[datadog-rum] init: application config from '${service.name}' ignored; the SDK is already started.`\n );\n }\n return false;\n }\n\n if (application) {\n offer ??= { service, application };\n }\n\n if (!offer || (!enabled && !isForceEnabled())) {\n return false;\n }\n\n const startedByOfferer = offer.service.name === service.name;\n if (application && !startedByOfferer) {\n // eslint-disable-next-line no-console\n console.info(\n `[datadog-rum] init: application config from '${service.name}' ignored; started the application offered by '${offer.service.name}'.`\n );\n }\n\n return initializeSdk({\n service: offer.service,\n application: offer.application,\n enabled,\n initializedBy: startedByOfferer ? undefined : service.name,\n });\n }\n\n return {\n init({ service, application, enabled = true }) {\n const initializedSdk = startSdk(service, application, enabled);\n registerService(service);\n\n return {\n cleanup: () => state.services.delete(service.name),\n initializedSdk,\n };\n },\n\n setServiceContext(key, context) {\n const existing = state.services.get(key);\n state.services.set(key, { ...existing, context });\n },\n };\n}\n"],"names":["datadogRum","buildAllowedTracingUrls","buildBeforeSend","installDdRumGuard","elementServiceRecorder","getEnv","DATADOG_RUM_FOR_DEV","installDevConsole","isForceEnabled","DEFAULTS","sessionSampleRate","sessionReplaySampleRate","defaultPrivacyLevel","createImpl","initialized","offer","state","services","Map","initializeSdk","service","application","enabled","initializedBy","sdkConfigPart","getInitConfiguration","console","warn","beforeSend","appBeforeSend","applicationBeforeSend","init","env","length","name","allowedTracingUrls","setGlobalContextProperty","install","registerService","reg","existing","get","set","context","startSdk","info","startedByOfferer","undefined","initializedSdk","cleanup","delete","setServiceContext","key"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,mBAAmB,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,qBAAqB;AAI5F,MAAMC,WAAW;IACbC,mBAAmB;IACnBC,yBAAyB;IACzBC,qBAAqB;AACzB;AAEA;;;;CAIC,GACD,OAAO,SAASC;IACZ,IAAIC,cAAc;IAClB,IAAIC;IACJ,MAAMC,QAAe;QACjBC,UAAU,IAAIC;IAClB;IAEA,SAASC,cAAc,EACnBC,OAAO,EACPC,WAAW,EACXC,OAAO,EACPC,aAAa,EAMhB;YAgBYC;QAfT,IAAIxB,WAAWyB,oBAAoB,IAAI;YACnC,sCAAsC;YACtCC,QAAQC,IAAI,CACR;YAEJ,OAAO;QACX;QAEA,MAAM,EAAEC,YAAYC,aAAa,EAAE,GAAGL,eAAe,GAAGH;QACxD,IAAIQ,eAAe;YACfb,MAAMc,qBAAqB,GAAGD;QAClC;QACA7B,WAAW+B,IAAI,CAAC;YACZ,GAAGtB,QAAQ;YACX,GAAGe,aAAa;YAChBQ,KAAKR,EAAAA,qBAAAA,cAAcQ,GAAG,cAAjBR,yCAAAA,mBAAmBS,MAAM,IAAGT,cAAcQ,GAAG,GAAG3B;YACrDe,SAASA,QAAQc,IAAI;YACrBN,YAAY1B,gBAAgBc;YAC5BmB,oBAAoBlC,wBAAwBe;QAChD;QACA,IAAI,CAACM,SAAS;YACVtB,WAAWoC,wBAAwB,CAAC9B,qBAAqB;QAC7D;QACAH,kBAAkBH;QAClBI,uBAAuBiC,OAAO;QAC9B,IAAId,eAAe;YACfvB,WAAWoC,wBAAwB,CAAC,iBAAiB;gBAAEhB,SAASG;YAAc;QAClF;QACAT,cAAc;QACd,OAAO;IACX;IAEA,SAASwB,gBAAgB,EAAEJ,IAAI,EAAE,GAAGK,KAAoB;QACpD,MAAMC,WAAWxB,MAAMC,QAAQ,CAACwB,GAAG,CAACP;QACpClB,MAAMC,QAAQ,CAACyB,GAAG,CAACR,MAAM;YAAE,GAAGK,GAAG;YAAEI,OAAO,EAAEH,qBAAAA,+BAAAA,SAAUG,OAAO;QAAC;IAClE;IAEA,SAASC,SACLxB,OAAsB,EACtBC,WAA0C,EAC1CC,OAAgB;QAEhB,IAAID,eAAe,CAACC,SAAS;YACzBf;QACJ;QAEA,IAAIO,aAAa;YACb,IAAIO,aAAa;gBACb,sCAAsC;gBACtCK,QAAQmB,IAAI,CACR,CAAC,6CAA6C,EAAEzB,QAAQc,IAAI,CAAC,sCAAsC,CAAC;YAE5G;YACA,OAAO;QACX;QAEA,IAAIb,aAAa;YACbN,kBAAAA,mBAAAA,QAAAA,QAAU;gBAAEK;gBAASC;YAAY;QACrC;QAEA,IAAI,CAACN,SAAU,CAACO,WAAW,CAACd,kBAAmB;YAC3C,OAAO;QACX;QAEA,MAAMsC,mBAAmB/B,MAAMK,OAAO,CAACc,IAAI,KAAKd,QAAQc,IAAI;QAC5D,IAAIb,eAAe,CAACyB,kBAAkB;YAClC,sCAAsC;YACtCpB,QAAQmB,IAAI,CACR,CAAC,6CAA6C,EAAEzB,QAAQc,IAAI,CAAC,+CAA+C,EAAEnB,MAAMK,OAAO,CAACc,IAAI,CAAC,EAAE,CAAC;QAE5I;QAEA,OAAOf,cAAc;YACjBC,SAASL,MAAMK,OAAO;YACtBC,aAAaN,MAAMM,WAAW;YAC9BC;YACAC,eAAeuB,mBAAmBC,YAAY3B,QAAQc,IAAI;QAC9D;IACJ;IAEA,OAAO;QACHH,MAAK,EAAEX,OAAO,EAAEC,WAAW,EAAEC,UAAU,IAAI,EAAE;YACzC,MAAM0B,iBAAiBJ,SAASxB,SAASC,aAAaC;YACtDgB,gBAAgBlB;YAEhB,OAAO;gBACH6B,SAAS,IAAMjC,MAAMC,QAAQ,CAACiC,MAAM,CAAC9B,QAAQc,IAAI;gBACjDc;YACJ;QACJ;QAEAG,mBAAkBC,GAAG,EAAET,OAAO;YAC1B,MAAMH,WAAWxB,MAAMC,QAAQ,CAACwB,GAAG,CAACW;YACpCpC,MAAMC,QAAQ,CAACyB,GAAG,CAACU,KAAK;gBAAE,GAAGZ,QAAQ;gBAAEG;YAAQ;QACnD;IACJ;AACJ"}
@@ -1,7 +1,9 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
+ import { type HashRoutingOptions } from './hash-routing';
2
3
  import { type RumUser } from './set-user';
4
+ export type { HashRoutingOptions };
3
5
  export interface Options {
4
- hashRouting?: boolean;
6
+ hashRouting?: boolean | HashRoutingOptions;
5
7
  }
6
8
  export declare const DatadogProvider: FC<PropsWithChildren & {
7
9
  isEnabled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"datadog-provider.d.ts","sourceRoot":"","sources":["../src/datadog-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAY,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAGnE,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,OAAO;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAYD,eAAO,MAAM,eAAe,EAAE,EAAE,CAC5B,iBAAiB,GAAG;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAYJ,CAAC"}
1
+ {"version":3,"file":"datadog-provider.d.ts","sourceRoot":"","sources":["../src/datadog-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAY,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEnD,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAEnC,MAAM,WAAW,OAAO;IACpB,WAAW,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC;CAC9C;AAYD,eAAO,MAAM,eAAe,EAAE,EAAE,CAC5B,iBAAiB,GAAG;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAcJ,CAAC"}
@@ -20,7 +20,9 @@ export const DatadogProvider = ({ children, isEnabled, user, options })=>{
20
20
  /*#__PURE__*/ _jsx(SetUser, {
21
21
  user: user
22
22
  }),
23
- (options === null || options === void 0 ? void 0 : options.hashRouting) && /*#__PURE__*/ _jsx(HashRouting, {}),
23
+ (options === null || options === void 0 ? void 0 : options.hashRouting) && /*#__PURE__*/ _jsx(HashRouting, {
24
+ ...options.hashRouting === true ? {} : options.hashRouting
25
+ }),
24
26
  children
25
27
  ]
26
28
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import { FC, Fragment, PropsWithChildren, useEffect } from 'react';\nimport { bundleState } from './bundle-state';\nimport { HashRouting } from './hash-routing';\nimport { setUser, type RumUser } from './set-user';\n\nexport interface Options {\n hashRouting?: boolean;\n}\n\nconst SetUser: FC<{ user?: RumUser }> = ({ user }) => {\n useEffect(() => {\n if (user) {\n setUser(user);\n }\n }, [user]);\n\n return null;\n};\n\nexport const DatadogProvider: FC<\n PropsWithChildren & {\n isEnabled: boolean;\n user?: RumUser;\n options?: Options;\n }\n> = ({ children, isEnabled, user, options }) => {\n if (isEnabled || bundleState.isSdkInitializer) {\n return (\n <Fragment>\n <SetUser user={user} />\n {options?.hashRouting && <HashRouting />}\n {children}\n </Fragment>\n );\n }\n return children;\n};\n"],"names":["Fragment","useEffect","bundleState","HashRouting","setUser","SetUser","user","DatadogProvider","children","isEnabled","options","isSdkInitializer","hashRouting"],"mappings":";AAAA,SAAaA,QAAQ,EAAqBC,SAAS,QAAQ,QAAQ;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAsB,aAAa;AAMnD,MAAMC,UAAkC,CAAC,EAAEC,IAAI,EAAE;IAC7CL,UAAU;QACN,IAAIK,MAAM;YACNF,QAAQE;QACZ;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;AACX;AAEA,OAAO,MAAMC,kBAMT,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAEH,IAAI,EAAEI,OAAO,EAAE;IACvC,IAAID,aAAaP,YAAYS,gBAAgB,EAAE;QAC3C,qBACI,MAACX;;8BACG,KAACK;oBAAQC,MAAMA;;gBACdI,CAAAA,oBAAAA,8BAAAA,QAASE,WAAW,mBAAI,KAACT;gBACzBK;;;IAGb;IACA,OAAOA;AACX,EAAE"}
1
+ {"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import { FC, Fragment, PropsWithChildren, useEffect } from 'react';\nimport { bundleState } from './bundle-state';\nimport { HashRouting, type HashRoutingOptions } from './hash-routing';\nimport { setUser, type RumUser } from './set-user';\n\nexport type { HashRoutingOptions };\n\nexport interface Options {\n hashRouting?: boolean | HashRoutingOptions;\n}\n\nconst SetUser: FC<{ user?: RumUser }> = ({ user }) => {\n useEffect(() => {\n if (user) {\n setUser(user);\n }\n }, [user]);\n\n return null;\n};\n\nexport const DatadogProvider: FC<\n PropsWithChildren & {\n isEnabled: boolean;\n user?: RumUser;\n options?: Options;\n }\n> = ({ children, isEnabled, user, options }) => {\n if (isEnabled || bundleState.isSdkInitializer) {\n return (\n <Fragment>\n <SetUser user={user} />\n {options?.hashRouting && (\n <HashRouting {...(options.hashRouting === true ? {} : options.hashRouting)} />\n )}\n {children}\n </Fragment>\n );\n }\n return children;\n};\n"],"names":["Fragment","useEffect","bundleState","HashRouting","setUser","SetUser","user","DatadogProvider","children","isEnabled","options","isSdkInitializer","hashRouting"],"mappings":";AAAA,SAAaA,QAAQ,EAAqBC,SAAS,QAAQ,QAAQ;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,QAAiC,iBAAiB;AACtE,SAASC,OAAO,QAAsB,aAAa;AAQnD,MAAMC,UAAkC,CAAC,EAAEC,IAAI,EAAE;IAC7CL,UAAU;QACN,IAAIK,MAAM;YACNF,QAAQE;QACZ;IACJ,GAAG;QAACA;KAAK;IAET,OAAO;AACX;AAEA,OAAO,MAAMC,kBAMT,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAEH,IAAI,EAAEI,OAAO,EAAE;IACvC,IAAID,aAAaP,YAAYS,gBAAgB,EAAE;QAC3C,qBACI,MAACX;;8BACG,KAACK;oBAAQC,MAAMA;;gBACdI,CAAAA,oBAAAA,8BAAAA,QAASE,WAAW,mBACjB,KAACT;oBAAa,GAAIO,QAAQE,WAAW,KAAK,OAAO,CAAC,IAAIF,QAAQE,WAAW;;gBAE5EJ;;;IAGb;IACA,OAAOA;AACX,EAAE"}
@@ -0,0 +1,7 @@
1
+ export type RumEnv = 'go' | 'stage' | 'next' | 'practice' | 'integration' | 'qa' | 'dev' | 'test';
2
+ /**
3
+ * Maps a hostname to its deployment stage for the RUM `env` tag.
4
+ * Tenant and sharded production hosts (`<tenant>.eh.go.servicetitan.com`, `go2.servicetitan.com`) are `go`; an unrecognized host is `undefined`.
5
+ */
6
+ export declare function getEnv(hostname?: string): RumEnv | undefined;
7
+ //# sourceMappingURL=get-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-env.d.ts","sourceRoot":"","sources":["../src/get-env.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,aAAa,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;AAOlG;;;GAGG;AACH,wBAAgB,MAAM,CAAC,QAAQ,SAA2B,GAAG,MAAM,GAAG,SAAS,CAe9E"}
@@ -0,0 +1,26 @@
1
+ const PRODUCTION_HOST = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i;
2
+ const STAGE_HOST = /(?:^|\.)(stage|next|practice|integration|qa|test)\d*\.servicetitan\.com\.?$/i;
3
+ const QA_ST_DEV_HOST = /\.qa\.st\.dev\.?$/i;
4
+ const LOCAL_HOST = /^(?:localhost|127\.0\.0\.1|app-web)$|\.st\.dev\.?$/i;
5
+ /**
6
+ * Maps a hostname to its deployment stage for the RUM `env` tag.
7
+ * Tenant and sharded production hosts (`<tenant>.eh.go.servicetitan.com`, `go2.servicetitan.com`) are `go`; an unrecognized host is `undefined`.
8
+ */ export function getEnv(hostname = window.location.hostname) {
9
+ var _STAGE_HOST_exec;
10
+ if (PRODUCTION_HOST.test(hostname)) {
11
+ return 'go';
12
+ }
13
+ const stage = (_STAGE_HOST_exec = STAGE_HOST.exec(hostname)) === null || _STAGE_HOST_exec === void 0 ? void 0 : _STAGE_HOST_exec[1];
14
+ if (stage) {
15
+ return stage.toLowerCase();
16
+ }
17
+ if (QA_ST_DEV_HOST.test(hostname)) {
18
+ return 'qa';
19
+ }
20
+ if (LOCAL_HOST.test(hostname)) {
21
+ return 'dev';
22
+ }
23
+ return undefined;
24
+ }
25
+
26
+ //# sourceMappingURL=get-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-env.ts"],"sourcesContent":["export type RumEnv = 'go' | 'stage' | 'next' | 'practice' | 'integration' | 'qa' | 'dev' | 'test';\n\nconst PRODUCTION_HOST = /(?:^|\\.)go\\d*\\.servicetitan\\.com\\.?$/i;\nconst STAGE_HOST = /(?:^|\\.)(stage|next|practice|integration|qa|test)\\d*\\.servicetitan\\.com\\.?$/i;\nconst QA_ST_DEV_HOST = /\\.qa\\.st\\.dev\\.?$/i;\nconst LOCAL_HOST = /^(?:localhost|127\\.0\\.0\\.1|app-web)$|\\.st\\.dev\\.?$/i;\n\n/**\n * Maps a hostname to its deployment stage for the RUM `env` tag.\n * Tenant and sharded production hosts (`<tenant>.eh.go.servicetitan.com`, `go2.servicetitan.com`) are `go`; an unrecognized host is `undefined`.\n */\nexport function getEnv(hostname = window.location.hostname): RumEnv | undefined {\n if (PRODUCTION_HOST.test(hostname)) {\n return 'go';\n }\n const stage = STAGE_HOST.exec(hostname)?.[1];\n if (stage) {\n return stage.toLowerCase() as RumEnv;\n }\n if (QA_ST_DEV_HOST.test(hostname)) {\n return 'qa';\n }\n if (LOCAL_HOST.test(hostname)) {\n return 'dev';\n }\n return undefined;\n}\n"],"names":["PRODUCTION_HOST","STAGE_HOST","QA_ST_DEV_HOST","LOCAL_HOST","getEnv","hostname","window","location","test","stage","exec","toLowerCase","undefined"],"mappings":"AAEA,MAAMA,kBAAkB;AACxB,MAAMC,aAAa;AACnB,MAAMC,iBAAiB;AACvB,MAAMC,aAAa;AAEnB;;;CAGC,GACD,OAAO,SAASC,OAAOC,WAAWC,OAAOC,QAAQ,CAACF,QAAQ;QAIxCJ;IAHd,IAAID,gBAAgBQ,IAAI,CAACH,WAAW;QAChC,OAAO;IACX;IACA,MAAMI,SAAQR,mBAAAA,WAAWS,IAAI,CAACL,uBAAhBJ,uCAAAA,gBAA2B,CAAC,EAAE;IAC5C,IAAIQ,OAAO;QACP,OAAOA,MAAME,WAAW;IAC5B;IACA,IAAIT,eAAeM,IAAI,CAACH,WAAW;QAC/B,OAAO;IACX;IACA,IAAIF,WAAWK,IAAI,CAACH,WAAW;QAC3B,OAAO;IACX;IACA,OAAOO;AACX"}
@@ -1,3 +1,7 @@
1
1
  import { FC } from 'react';
2
- export declare const HashRouting: FC;
2
+ export interface HashRoutingOptions {
3
+ /** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */
4
+ redirectedViews?: string[];
5
+ }
6
+ export declare const HashRouting: FC<HashRoutingOptions>;
3
7
  //# sourceMappingURL=hash-routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAqB,MAAM,OAAO,CAAC;AAgB9C,eAAO,MAAM,WAAW,EAAE,EAGzB,CAAC"}
1
+ {"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAIvD,MAAM,WAAW,kBAAkB;IAC/B,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAG9C,CAAC"}
@@ -1,22 +1,37 @@
1
1
  import { datadogRum } from '@datadog/browser-rum';
2
- import { useEffect, useRef } from 'react';
2
+ import { useEffect, useMemo, useRef } from 'react';
3
3
  import { useLocation } from 'react-router-dom';
4
4
  import { sanitizeViewName } from './sanitize-view-name';
5
- const useHashRouting = ()=>{
5
+ export const HashRouting = ({ redirectedViews })=>{
6
+ useHashRouting(redirectedViews);
7
+ return null;
8
+ };
9
+ function useHashRouting(redirectedViews = []) {
6
10
  const pathname = sanitizeViewName(useLocation().pathname);
11
+ const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);
7
12
  const lastPathname = useRef(undefined);
13
+ const isRedirecting = useRef(false);
8
14
  useEffect(()=>{
9
15
  if (lastPathname.current !== pathname) {
10
- datadogRum.startView(pathname);
16
+ /* A redirect's destination takes over the view the redirect started. */ if (isRedirecting.current) {
17
+ datadogRum.setViewName(pathname);
18
+ } else {
19
+ datadogRum.startView(pathname);
20
+ }
11
21
  lastPathname.current = pathname;
22
+ isRedirecting.current = isRedirect;
12
23
  }
13
24
  }, [
25
+ isRedirect,
14
26
  pathname
15
27
  ]);
16
- };
17
- export const HashRouting = ()=>{
18
- useHashRouting();
19
- return null;
20
- };
28
+ }
29
+ function useSanitizedViewNames(viewNames) {
30
+ const key = viewNames.join('\n'); // handles when callers pass a new array on every render
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames
32
+ return useMemo(()=>new Set(viewNames.map(sanitizeViewName)), [
33
+ key
34
+ ]);
35
+ }
21
36
 
22
37
  //# sourceMappingURL=hash-routing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, useEffect, useRef } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { sanitizeViewName } from './sanitize-view-name';\n\nconst useHashRouting = () => {\n const pathname = sanitizeViewName(useLocation().pathname);\n const lastPathname = useRef<string | undefined>(undefined);\n\n useEffect(() => {\n if (lastPathname.current !== pathname) {\n datadogRum.startView(pathname);\n lastPathname.current = pathname;\n }\n }, [pathname]);\n};\n\nexport const HashRouting: FC = () => {\n useHashRouting();\n return null;\n};\n"],"names":["datadogRum","useEffect","useRef","useLocation","sanitizeViewName","useHashRouting","pathname","lastPathname","undefined","current","startView","HashRouting"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,MAAMC,iBAAiB;IACnB,MAAMC,WAAWF,iBAAiBD,cAAcG,QAAQ;IACxD,MAAMC,eAAeL,OAA2BM;IAEhDP,UAAU;QACN,IAAIM,aAAaE,OAAO,KAAKH,UAAU;YACnCN,WAAWU,SAAS,CAACJ;YACrBC,aAAaE,OAAO,GAAGH;QAC3B;IACJ,GAAG;QAACA;KAAS;AACjB;AAEA,OAAO,MAAMK,cAAkB;IAC3BN;IACA,OAAO;AACX,EAAE"}
1
+ {"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, useEffect, useMemo, useRef } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { sanitizeViewName } from './sanitize-view-name';\n\nexport interface HashRoutingOptions {\n /** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */\n redirectedViews?: string[];\n}\n\nexport const HashRouting: FC<HashRoutingOptions> = ({ redirectedViews }) => {\n useHashRouting(redirectedViews);\n return null;\n};\n\nfunction useHashRouting(redirectedViews: string[] = []) {\n const pathname = sanitizeViewName(useLocation().pathname);\n const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);\n const lastPathname = useRef<string | undefined>(undefined);\n const isRedirecting = useRef(false);\n\n useEffect(() => {\n if (lastPathname.current !== pathname) {\n /* A redirect's destination takes over the view the redirect started. */\n if (isRedirecting.current) {\n datadogRum.setViewName(pathname);\n } else {\n datadogRum.startView(pathname);\n }\n lastPathname.current = pathname;\n isRedirecting.current = isRedirect;\n }\n }, [isRedirect, pathname]);\n}\n\nfunction useSanitizedViewNames(viewNames: string[]) {\n const key = viewNames.join('\\n'); // handles when callers pass a new array on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames\n return useMemo(() => new Set(viewNames.map(sanitizeViewName)), [key]);\n}\n"],"names":["datadogRum","useEffect","useMemo","useRef","useLocation","sanitizeViewName","HashRouting","redirectedViews","useHashRouting","pathname","isRedirect","useSanitizedViewNames","has","lastPathname","undefined","isRedirecting","current","setViewName","startView","viewNames","key","join","Set","map"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACvD,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,gBAAgB,QAAQ,uBAAuB;AAOxD,OAAO,MAAMC,cAAsC,CAAC,EAAEC,eAAe,EAAE;IACnEC,eAAeD;IACf,OAAO;AACX,EAAE;AAEF,SAASC,eAAeD,kBAA4B,EAAE;IAClD,MAAME,WAAWJ,iBAAiBD,cAAcK,QAAQ;IACxD,MAAMC,aAAaC,sBAAsBJ,iBAAiBK,GAAG,CAACH;IAC9D,MAAMI,eAAeV,OAA2BW;IAChD,MAAMC,gBAAgBZ,OAAO;IAE7BF,UAAU;QACN,IAAIY,aAAaG,OAAO,KAAKP,UAAU;YACnC,sEAAsE,GACtE,IAAIM,cAAcC,OAAO,EAAE;gBACvBhB,WAAWiB,WAAW,CAACR;YAC3B,OAAO;gBACHT,WAAWkB,SAAS,CAACT;YACzB;YACAI,aAAaG,OAAO,GAAGP;YACvBM,cAAcC,OAAO,GAAGN;QAC5B;IACJ,GAAG;QAACA;QAAYD;KAAS;AAC7B;AAEA,SAASE,sBAAsBQ,SAAmB;IAC9C,MAAMC,MAAMD,UAAUE,IAAI,CAAC,OAAO,wDAAwD;IAC1F,+EAA+E;IAC/E,OAAOnB,QAAQ,IAAM,IAAIoB,IAAIH,UAAUI,GAAG,CAAClB,oBAAoB;QAACe;KAAI;AACxE"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './before-send';
2
2
  export * from './datadog-provider';
3
+ export * from './get-env';
3
4
  export * from './init';
4
5
  export * from './set-user';
5
6
  export * from './use-rum-service';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './before-send';
2
2
  export * from './datadog-provider';
3
+ export * from './get-env';
3
4
  export * from './init';
4
5
  export * from './set-user';
5
6
  export * from './use-rum-service';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './before-send';\nexport * from './datadog-provider';\nexport * from './init';\nexport * from './set-user';\nexport * from './use-rum-service';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,oBAAoB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './before-send';\nexport * from './datadog-provider';\nexport * from './get-env';\nexport * from './init';\nexport * from './set-user';\nexport * from './use-rum-service';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,oBAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize-view-name.d.ts","sourceRoot":"","sources":["../src/sanitize-view-name.tsx"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,UAoBhD"}
1
+ {"version":3,"file":"sanitize-view-name.d.ts","sourceRoot":"","sources":["../src/sanitize-view-name.tsx"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,UA6BhD"}
@@ -1,6 +1,10 @@
1
1
  export function sanitizeViewName(viewName) {
2
2
  try {
3
3
  const replaceIds = viewName.toLowerCase().replace(/\/(\d+[^/]*)(?=\/|$)/g, '/{id}') // turn numbers to {id} placeholder
4
+ .replace(/\/([^/]*[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}[^/]*)(?=\/|$)/g, '/{id}') // turn segments containing a UUID to {id} placeholder
5
+ .replace(/\/([a-z]{1,4}\.[\w-]{6,})(?=\/|$)/g, '/{id}') // turn prefixed tokens (for example "cid.x7k2...") to {id} placeholder
6
+ .replace(/\/(\([^/]*)(?=\/|$)/g, (match, segment)=>isPhoneNumber(segment) ? '/{id}' : match) // turn phone numbers like "(215) 360-2426" or "(02) 9876 5432" to {id} placeholder
7
+ .replace(/\/([^/]*\d{5}[^/]*)(?=\/|$)/g, '/{id}') // turn segments with 5+ digits in a row (for example "cf_168124196") to {id} placeholder
4
8
  .replace(/\/(null|undefined)(?=\/|$)/g, '/{id}') // turn null and undefined to {id} placeholder
5
9
  .replace(/\/([^/]*\.[a-z]+)(?=\/|$)/g, '/{id}') // turn file names to {id} placeholder
6
10
  .replace(/\/([^/]*[=%+][^/]*)(?=\/|$)/g, '/{id}') // turn dates, phone numbers and query parameters to {id} placeholder
@@ -17,5 +21,11 @@ export function sanitizeViewName(viewName) {
17
21
  return viewName;
18
22
  }
19
23
  }
24
+ /*
25
+ * Matches a segment that starts with a parenthesized digit and holds at least 8 digits,
26
+ * whatever separators or extension text sit between them.
27
+ */ function isPhoneNumber(segment) {
28
+ return /^\(\d/.test(segment) && segment.replace(/\D/g, '').length >= 8;
29
+ }
20
30
 
21
31
  //# sourceMappingURL=sanitize-view-name.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sanitize-view-name.tsx"],"sourcesContent":["export function sanitizeViewName(viewName: string) {\n try {\n const replaceIds = viewName\n .toLowerCase()\n .replace(/\\/(\\d+[^/]*)(?=\\/|$)/g, '/{id}') // turn numbers to {id} placeholder\n .replace(/\\/(null|undefined)(?=\\/|$)/g, '/{id}') // turn null and undefined to {id} placeholder\n .replace(/\\/([^/]*\\.[a-z]+)(?=\\/|$)/g, '/{id}') // turn file names to {id} placeholder\n .replace(/\\/([^/]*[=%+][^/]*)(?=\\/|$)/g, '/{id}') // turn dates, phone numbers and query parameters to {id} placeholder\n .replace(/(.+?)(\\/+)$/, '$1') // remove '/' from the end of the line\n .replace(/(\\/)(\\/+)/g, '/') // remove duplicate '/'\n .replace('#', '');\n if (replaceIds.startsWith('/proxy')) {\n return replaceIds.replace(/^\\/proxy/, '/').replace(/\\/[^/]*$/, '');\n }\n return replaceIds;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n return viewName;\n }\n}\n"],"names":["sanitizeViewName","viewName","replaceIds","toLowerCase","replace","startsWith","e","console","error"],"mappings":"AAAA,OAAO,SAASA,iBAAiBC,QAAgB;IAC7C,IAAI;QACA,MAAMC,aAAaD,SACdE,WAAW,GACXC,OAAO,CAAC,yBAAyB,SAAS,mCAAmC;SAC7EA,OAAO,CAAC,+BAA+B,SAAS,8CAA8C;SAC9FA,OAAO,CAAC,8BAA8B,SAAS,sCAAsC;SACrFA,OAAO,CAAC,gCAAgC,SAAS,qEAAqE;SACtHA,OAAO,CAAC,eAAe,MAAM,sCAAsC;SACnEA,OAAO,CAAC,cAAc,KAAK,uBAAuB;SAClDA,OAAO,CAAC,KAAK;QAClB,IAAIF,WAAWG,UAAU,CAAC,WAAW;YACjC,OAAOH,WAAWE,OAAO,CAAC,YAAY,KAAKA,OAAO,CAAC,YAAY;QACnE;QACA,OAAOF;IACX,EAAE,OAAOI,GAAG;QACR,sCAAsC;QACtCC,QAAQC,KAAK,CAACF;QACd,OAAOL;IACX;AACJ"}
1
+ {"version":3,"sources":["../src/sanitize-view-name.tsx"],"sourcesContent":["export function sanitizeViewName(viewName: string) {\n try {\n const replaceIds = viewName\n .toLowerCase()\n .replace(/\\/(\\d+[^/]*)(?=\\/|$)/g, '/{id}') // turn numbers to {id} placeholder\n .replace(\n /\\/([^/]*[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}[^/]*)(?=\\/|$)/g,\n '/{id}'\n ) // turn segments containing a UUID to {id} placeholder\n .replace(/\\/([a-z]{1,4}\\.[\\w-]{6,})(?=\\/|$)/g, '/{id}') // turn prefixed tokens (for example \"cid.x7k2...\") to {id} placeholder\n .replace(/\\/(\\([^/]*)(?=\\/|$)/g, (match, segment: string) =>\n isPhoneNumber(segment) ? '/{id}' : match\n ) // turn phone numbers like \"(215) 360-2426\" or \"(02) 9876 5432\" to {id} placeholder\n .replace(/\\/([^/]*\\d{5}[^/]*)(?=\\/|$)/g, '/{id}') // turn segments with 5+ digits in a row (for example \"cf_168124196\") to {id} placeholder\n .replace(/\\/(null|undefined)(?=\\/|$)/g, '/{id}') // turn null and undefined to {id} placeholder\n .replace(/\\/([^/]*\\.[a-z]+)(?=\\/|$)/g, '/{id}') // turn file names to {id} placeholder\n .replace(/\\/([^/]*[=%+][^/]*)(?=\\/|$)/g, '/{id}') // turn dates, phone numbers and query parameters to {id} placeholder\n .replace(/(.+?)(\\/+)$/, '$1') // remove '/' from the end of the line\n .replace(/(\\/)(\\/+)/g, '/') // remove duplicate '/'\n .replace('#', '');\n if (replaceIds.startsWith('/proxy')) {\n return replaceIds.replace(/^\\/proxy/, '/').replace(/\\/[^/]*$/, '');\n }\n return replaceIds;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n return viewName;\n }\n}\n\n/*\n * Matches a segment that starts with a parenthesized digit and holds at least 8 digits,\n * whatever separators or extension text sit between them.\n */\nfunction isPhoneNumber(segment: string) {\n return /^\\(\\d/.test(segment) && segment.replace(/\\D/g, '').length >= 8;\n}\n"],"names":["sanitizeViewName","viewName","replaceIds","toLowerCase","replace","match","segment","isPhoneNumber","startsWith","e","console","error","test","length"],"mappings":"AAAA,OAAO,SAASA,iBAAiBC,QAAgB;IAC7C,IAAI;QACA,MAAMC,aAAaD,SACdE,WAAW,GACXC,OAAO,CAAC,yBAAyB,SAAS,mCAAmC;SAC7EA,OAAO,CACJ,kFACA,SACF,sDAAsD;SACvDA,OAAO,CAAC,sCAAsC,SAAS,uEAAuE;SAC9HA,OAAO,CAAC,wBAAwB,CAACC,OAAOC,UACrCC,cAAcD,WAAW,UAAUD,OACrC,mFAAmF;SACpFD,OAAO,CAAC,gCAAgC,SAAS,yFAAyF;SAC1IA,OAAO,CAAC,+BAA+B,SAAS,8CAA8C;SAC9FA,OAAO,CAAC,8BAA8B,SAAS,sCAAsC;SACrFA,OAAO,CAAC,gCAAgC,SAAS,qEAAqE;SACtHA,OAAO,CAAC,eAAe,MAAM,sCAAsC;SACnEA,OAAO,CAAC,cAAc,KAAK,uBAAuB;SAClDA,OAAO,CAAC,KAAK;QAClB,IAAIF,WAAWM,UAAU,CAAC,WAAW;YACjC,OAAON,WAAWE,OAAO,CAAC,YAAY,KAAKA,OAAO,CAAC,YAAY;QACnE;QACA,OAAOF;IACX,EAAE,OAAOO,GAAG;QACR,sCAAsC;QACtCC,QAAQC,KAAK,CAACF;QACd,OAAOR;IACX;AACJ;AAEA;;;CAGC,GACD,SAASM,cAAcD,OAAe;IAClC,OAAO,QAAQM,IAAI,CAACN,YAAYA,QAAQF,OAAO,CAAC,OAAO,IAAIS,MAAM,IAAI;AACzE"}
@@ -1,4 +1,4 @@
1
- import type { Context, User } from '@datadog/browser-core';
1
+ import type { Context, User } from '@datadog/browser-rum';
2
2
  import type { Cleanup, InitRumOptions } from './types';
3
3
  export type RumUser = Omit<User, 'id'> & Required<Pick<User, 'id'>>;
4
4
  export interface SharedImpl {
@@ -1 +1 @@
1
- {"version":3,"file":"shared-impl.d.ts","sourceRoot":"","sources":["../src/shared-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,UAAU;IACvB,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1E,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1D"}
1
+ {"version":3,"file":"shared-impl.d.ts","sourceRoot":"","sources":["../src/shared-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,UAAU;IACvB,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1E,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1D"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/shared-impl.ts"],"sourcesContent":["import type { Context, User } from '@datadog/browser-core';\nimport type { Cleanup, InitRumOptions } from './types';\n\nexport type RumUser = Omit<User, 'id'> & Required<Pick<User, 'id'>>;\n\nexport interface SharedImpl {\n init(opts: InitRumOptions): { cleanup: Cleanup; initializedSdk: boolean };\n setServiceContext(key: string, context: Context): void;\n}\n"],"names":[],"mappings":"AAKA,WAGC"}
1
+ {"version":3,"sources":["../src/shared-impl.ts"],"sourcesContent":["import type { Context, User } from '@datadog/browser-rum';\nimport type { Cleanup, InitRumOptions } from './types';\n\nexport type RumUser = Omit<User, 'id'> & Required<Pick<User, 'id'>>;\n\nexport interface SharedImpl {\n init(opts: InitRumOptions): { cleanup: Cleanup; initializedSdk: boolean };\n setServiceContext(key: string, context: Context): void;\n}\n"],"names":[],"mappings":"AAKA,WAGC"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { Context } from '@datadog/browser-core';
2
- import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';
1
+ import type { Context, MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';
3
2
  import type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';
4
3
  /**
5
4
  * URL matchers grouped by the propagator type whose headers they should
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE5F;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;AAEhF,yFAAyF;AACzF,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD;AAED,qFAAqF;AACrF,MAAM,WAAW,sBAAuB,SAAQ,UAAU;IACtD,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAChC,oBAAoB,EACpB,YAAY,GAAG,oBAAoB,GAAG,SAAS,CAClD,GAAG;IACA,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC7C,CAAC;AAEF,UAAU,YAAY;IAClB,UAAU,CAAC,EAAE,wBAAwB,CAAC;IACtC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CAC3C;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IAC/C,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,YAAY;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,WAAW,EAAE,iBAAiB,CAAC;CAClC;AAED,iGAAiG;AACjG,MAAM,WAAW,KAAK;IAClB,qBAAqB,CAAC,EAAE,4BAA4B,CAAC;IACrD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,OAAO,EACP,WAAW,EACX,cAAc,EACd,oBAAoB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE5F;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;AAEhF,yFAAyF;AACzF,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD;AAED,qFAAqF;AACrF,MAAM,WAAW,sBAAuB,SAAQ,UAAU;IACtD,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAChC,oBAAoB,EACpB,YAAY,GAAG,oBAAoB,GAAG,SAAS,CAClD,GAAG;IACA,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC7C,CAAC;AAEF,UAAU,YAAY;IAClB,UAAU,CAAC,EAAE,wBAAwB,CAAC;IACtC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CAC3C;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IAC/C,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,YAAY;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,WAAW,EAAE,iBAAiB,CAAC;CAClC;AAED,iGAAiG;AACjG,MAAM,WAAW,KAAK;IAClB,qBAAqB,CAAC,EAAE,4BAA4B,CAAC;IACrD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACvC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Context } from '@datadog/browser-core';\nimport type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';\nimport type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';\n\n/**\n * URL matchers grouped by the propagator type whose headers they should\n * activate. A service registers its tracing URLs as e.g.\n * `{ tracecontext: [/api\\//, 'https://...'] }`.\n */\nexport type ServiceTracingUrls = Partial<Record<PropagatorType, MatchOption[]>>;\n\n/** Tears down a service registration: handlers, tracing URLs, and persistent context. */\nexport type Cleanup = () => void;\n\n/**\n * Service handle returned by `useRumService`. `setServiceContext` is bound to the\n * service registered by the hook, so callers don't pass the service name again.\n */\nexport interface RumService {\n setServiceContext: (context: Context) => void;\n}\n\n/** Imperative service registration returned by `init`. Adds the cleanup contract. */\nexport interface RumServiceRegistration extends RumService {\n cleanup: Cleanup;\n}\n\nexport type ApplicationConfig = Omit<\n RumInitConfiguration,\n 'beforeSend' | 'allowedTracingUrls' | 'service'\n> & {\n beforeSend?: ApplicationBeforeSendHandler;\n};\n\ninterface ServiceShape {\n beforeSend?: ServiceBeforeSendHandler;\n allowedTracingUrls?: ServiceTracingUrls;\n}\n\nexport interface ServiceConfig extends ServiceShape {\n name: string;\n}\n\nexport interface InitRumOptions {\n service: ServiceConfig;\n application?: ApplicationConfig;\n enabled?: boolean;\n}\n\n/**\n * Per-service entry — `beforeSend` and `allowedTracingUrls` come from\n * `init`; `context` comes from `setServiceContext`. One service = one entry.\n */\nexport interface ServiceEntry extends ServiceShape {\n context?: Context;\n}\n\nexport interface PendingApplication {\n service: ServiceConfig;\n application: ApplicationConfig;\n}\n\n/** Registration state: application-level handler + per-service entries keyed by service name. */\nexport interface State {\n applicationBeforeSend?: ApplicationBeforeSendHandler;\n services: Map<string, ServiceEntry>;\n}\n"],"names":[],"mappings":"AA8DA,+FAA+F,GAC/F,WAGC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Context,\n MatchOption,\n PropagatorType,\n RumInitConfiguration,\n} from '@datadog/browser-rum';\nimport type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';\n\n/**\n * URL matchers grouped by the propagator type whose headers they should\n * activate. A service registers its tracing URLs as e.g.\n * `{ tracecontext: [/api\\//, 'https://...'] }`.\n */\nexport type ServiceTracingUrls = Partial<Record<PropagatorType, MatchOption[]>>;\n\n/** Tears down a service registration: handlers, tracing URLs, and persistent context. */\nexport type Cleanup = () => void;\n\n/**\n * Service handle returned by `useRumService`. `setServiceContext` is bound to the\n * service registered by the hook, so callers don't pass the service name again.\n */\nexport interface RumService {\n setServiceContext: (context: Context) => void;\n}\n\n/** Imperative service registration returned by `init`. Adds the cleanup contract. */\nexport interface RumServiceRegistration extends RumService {\n cleanup: Cleanup;\n}\n\nexport type ApplicationConfig = Omit<\n RumInitConfiguration,\n 'beforeSend' | 'allowedTracingUrls' | 'service'\n> & {\n beforeSend?: ApplicationBeforeSendHandler;\n};\n\ninterface ServiceShape {\n beforeSend?: ServiceBeforeSendHandler;\n allowedTracingUrls?: ServiceTracingUrls;\n}\n\nexport interface ServiceConfig extends ServiceShape {\n name: string;\n}\n\nexport interface InitRumOptions {\n service: ServiceConfig;\n application?: ApplicationConfig;\n enabled?: boolean;\n}\n\n/**\n * Per-service entry — `beforeSend` and `allowedTracingUrls` come from\n * `init`; `context` comes from `setServiceContext`. One service = one entry.\n */\nexport interface ServiceEntry extends ServiceShape {\n context?: Context;\n}\n\nexport interface PendingApplication {\n service: ServiceConfig;\n application: ApplicationConfig;\n}\n\n/** Registration state: application-level handler + per-service entries keyed by service name. */\nexport interface State {\n applicationBeforeSend?: ApplicationBeforeSendHandler;\n services: Map<string, ServiceEntry>;\n}\n"],"names":[],"mappings":"AAkEA,+FAA+F,GAC/F,WAGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/datadog-rum",
3
- "version": "40.2.2",
3
+ "version": "40.3.0",
4
4
  "description": "DataDog RUM JS SDK configuration for standalone applications",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/datadog-rum",
6
6
  "repository": {
@@ -19,13 +19,18 @@
19
19
  "typings": "./dist/index.d.ts",
20
20
  "files": [
21
21
  "dist",
22
- "src"
22
+ "src",
23
+ "!**/__tests__",
24
+ "!**/__mocks__",
25
+ "!**/__snapshots__",
26
+ "!**/*.test.*"
23
27
  ],
24
28
  "devDependencies": {
25
- "@datadog/browser-rum": "^7.15.0",
29
+ "@datadog/browser-rum": "^7.16.2",
26
30
  "@testing-library/dom": "^10.4.2",
27
31
  "@testing-library/jest-dom": "^7.0.1",
28
32
  "@testing-library/react": "^16.3.3",
33
+ "history": "~4.10.1",
29
34
  "react": "~18.3.1",
30
35
  "react-router-dom": "~5.3.0"
31
36
  },
@@ -3,6 +3,7 @@ import { buildAllowedTracingUrls } from './build-allowed-tracing-urls';
3
3
  import { buildBeforeSend } from './build-before-send';
4
4
  import { installDdRumGuard } from './dd-rum-guard';
5
5
  import { elementServiceRecorder } from './element-service-recorder';
6
+ import { getEnv } from './get-env';
6
7
  import { DATADOG_RUM_FOR_DEV, installDevConsole, isForceEnabled } from './runtime-override';
7
8
  import type { SharedImpl } from './shared-impl';
8
9
  import type { ApplicationConfig, PendingApplication, ServiceConfig, State } from './types';
@@ -51,6 +52,7 @@ export function createImpl(): SharedImpl {
51
52
  datadogRum.init({
52
53
  ...DEFAULTS,
53
54
  ...sdkConfigPart,
55
+ env: sdkConfigPart.env?.length ? sdkConfigPart.env : getEnv(),
54
56
  service: service.name,
55
57
  beforeSend: buildBeforeSend(state),
56
58
  allowedTracingUrls: buildAllowedTracingUrls(state),
@@ -1,10 +1,12 @@
1
1
  import { FC, Fragment, PropsWithChildren, useEffect } from 'react';
2
2
  import { bundleState } from './bundle-state';
3
- import { HashRouting } from './hash-routing';
3
+ import { HashRouting, type HashRoutingOptions } from './hash-routing';
4
4
  import { setUser, type RumUser } from './set-user';
5
5
 
6
+ export type { HashRoutingOptions };
7
+
6
8
  export interface Options {
7
- hashRouting?: boolean;
9
+ hashRouting?: boolean | HashRoutingOptions;
8
10
  }
9
11
 
10
12
  const SetUser: FC<{ user?: RumUser }> = ({ user }) => {
@@ -28,7 +30,9 @@ export const DatadogProvider: FC<
28
30
  return (
29
31
  <Fragment>
30
32
  <SetUser user={user} />
31
- {options?.hashRouting && <HashRouting />}
33
+ {options?.hashRouting && (
34
+ <HashRouting {...(options.hashRouting === true ? {} : options.hashRouting)} />
35
+ )}
32
36
  {children}
33
37
  </Fragment>
34
38
  );
package/src/get-env.ts ADDED
@@ -0,0 +1,27 @@
1
+ export type RumEnv = 'go' | 'stage' | 'next' | 'practice' | 'integration' | 'qa' | 'dev' | 'test';
2
+
3
+ const PRODUCTION_HOST = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i;
4
+ const STAGE_HOST = /(?:^|\.)(stage|next|practice|integration|qa|test)\d*\.servicetitan\.com\.?$/i;
5
+ const QA_ST_DEV_HOST = /\.qa\.st\.dev\.?$/i;
6
+ const LOCAL_HOST = /^(?:localhost|127\.0\.0\.1|app-web)$|\.st\.dev\.?$/i;
7
+
8
+ /**
9
+ * Maps a hostname to its deployment stage for the RUM `env` tag.
10
+ * Tenant and sharded production hosts (`<tenant>.eh.go.servicetitan.com`, `go2.servicetitan.com`) are `go`; an unrecognized host is `undefined`.
11
+ */
12
+ export function getEnv(hostname = window.location.hostname): RumEnv | undefined {
13
+ if (PRODUCTION_HOST.test(hostname)) {
14
+ return 'go';
15
+ }
16
+ const stage = STAGE_HOST.exec(hostname)?.[1];
17
+ if (stage) {
18
+ return stage.toLowerCase() as RumEnv;
19
+ }
20
+ if (QA_ST_DEV_HOST.test(hostname)) {
21
+ return 'qa';
22
+ }
23
+ if (LOCAL_HOST.test(hostname)) {
24
+ return 'dev';
25
+ }
26
+ return undefined;
27
+ }
@@ -1,21 +1,40 @@
1
1
  import { datadogRum } from '@datadog/browser-rum';
2
- import { FC, useEffect, useRef } from 'react';
2
+ import { FC, useEffect, useMemo, useRef } from 'react';
3
3
  import { useLocation } from 'react-router-dom';
4
4
  import { sanitizeViewName } from './sanitize-view-name';
5
5
 
6
- const useHashRouting = () => {
6
+ export interface HashRoutingOptions {
7
+ /** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */
8
+ redirectedViews?: string[];
9
+ }
10
+
11
+ export const HashRouting: FC<HashRoutingOptions> = ({ redirectedViews }) => {
12
+ useHashRouting(redirectedViews);
13
+ return null;
14
+ };
15
+
16
+ function useHashRouting(redirectedViews: string[] = []) {
7
17
  const pathname = sanitizeViewName(useLocation().pathname);
18
+ const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);
8
19
  const lastPathname = useRef<string | undefined>(undefined);
20
+ const isRedirecting = useRef(false);
9
21
 
10
22
  useEffect(() => {
11
23
  if (lastPathname.current !== pathname) {
12
- datadogRum.startView(pathname);
24
+ /* A redirect's destination takes over the view the redirect started. */
25
+ if (isRedirecting.current) {
26
+ datadogRum.setViewName(pathname);
27
+ } else {
28
+ datadogRum.startView(pathname);
29
+ }
13
30
  lastPathname.current = pathname;
31
+ isRedirecting.current = isRedirect;
14
32
  }
15
- }, [pathname]);
16
- };
33
+ }, [isRedirect, pathname]);
34
+ }
17
35
 
18
- export const HashRouting: FC = () => {
19
- useHashRouting();
20
- return null;
21
- };
36
+ function useSanitizedViewNames(viewNames: string[]) {
37
+ const key = viewNames.join('\n'); // handles when callers pass a new array on every render
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames
39
+ return useMemo(() => new Set(viewNames.map(sanitizeViewName)), [key]);
40
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './before-send';
2
2
  export * from './datadog-provider';
3
+ export * from './get-env';
3
4
  export * from './init';
4
5
  export * from './set-user';
5
6
  export * from './use-rum-service';
@@ -3,6 +3,15 @@ export function sanitizeViewName(viewName: string) {
3
3
  const replaceIds = viewName
4
4
  .toLowerCase()
5
5
  .replace(/\/(\d+[^/]*)(?=\/|$)/g, '/{id}') // turn numbers to {id} placeholder
6
+ .replace(
7
+ /\/([^/]*[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}[^/]*)(?=\/|$)/g,
8
+ '/{id}'
9
+ ) // turn segments containing a UUID to {id} placeholder
10
+ .replace(/\/([a-z]{1,4}\.[\w-]{6,})(?=\/|$)/g, '/{id}') // turn prefixed tokens (for example "cid.x7k2...") to {id} placeholder
11
+ .replace(/\/(\([^/]*)(?=\/|$)/g, (match, segment: string) =>
12
+ isPhoneNumber(segment) ? '/{id}' : match
13
+ ) // turn phone numbers like "(215) 360-2426" or "(02) 9876 5432" to {id} placeholder
14
+ .replace(/\/([^/]*\d{5}[^/]*)(?=\/|$)/g, '/{id}') // turn segments with 5+ digits in a row (for example "cf_168124196") to {id} placeholder
6
15
  .replace(/\/(null|undefined)(?=\/|$)/g, '/{id}') // turn null and undefined to {id} placeholder
7
16
  .replace(/\/([^/]*\.[a-z]+)(?=\/|$)/g, '/{id}') // turn file names to {id} placeholder
8
17
  .replace(/\/([^/]*[=%+][^/]*)(?=\/|$)/g, '/{id}') // turn dates, phone numbers and query parameters to {id} placeholder
@@ -19,3 +28,11 @@ export function sanitizeViewName(viewName: string) {
19
28
  return viewName;
20
29
  }
21
30
  }
31
+
32
+ /*
33
+ * Matches a segment that starts with a parenthesized digit and holds at least 8 digits,
34
+ * whatever separators or extension text sit between them.
35
+ */
36
+ function isPhoneNumber(segment: string) {
37
+ return /^\(\d/.test(segment) && segment.replace(/\D/g, '').length >= 8;
38
+ }
@@ -1,4 +1,4 @@
1
- import type { Context, User } from '@datadog/browser-core';
1
+ import type { Context, User } from '@datadog/browser-rum';
2
2
  import type { Cleanup, InitRumOptions } from './types';
3
3
 
4
4
  export type RumUser = Omit<User, 'id'> & Required<Pick<User, 'id'>>;
package/src/types.ts CHANGED
@@ -1,5 +1,9 @@
1
- import type { Context } from '@datadog/browser-core';
2
- import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';
1
+ import type {
2
+ Context,
3
+ MatchOption,
4
+ PropagatorType,
5
+ RumInitConfiguration,
6
+ } from '@datadog/browser-rum';
3
7
  import type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';
4
8
 
5
9
  /**