@servicetitan/datadog-rum 40.2.2 → 40.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-impl.d.ts.map +1 -1
- package/dist/create-impl.js +3 -0
- package/dist/create-impl.js.map +1 -1
- package/dist/datadog-provider.d.ts +3 -1
- package/dist/datadog-provider.d.ts.map +1 -1
- package/dist/datadog-provider.js +3 -1
- package/dist/datadog-provider.js.map +1 -1
- package/dist/get-env.d.ts +7 -0
- package/dist/get-env.d.ts.map +1 -0
- package/dist/get-env.js +26 -0
- package/dist/get-env.js.map +1 -0
- package/dist/hash-routing.d.ts +5 -1
- package/dist/hash-routing.d.ts.map +1 -1
- package/dist/hash-routing.js +59 -15
- package/dist/hash-routing.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sanitize-view-name.d.ts.map +1 -1
- package/dist/sanitize-view-name.js +10 -0
- package/dist/sanitize-view-name.js.map +1 -1
- package/dist/shared-impl.d.ts +1 -1
- package/dist/shared-impl.d.ts.map +1 -1
- package/dist/shared-impl.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -3
- package/src/create-impl.ts +2 -0
- package/src/datadog-provider.tsx +7 -3
- package/src/get-env.ts +27 -0
- package/src/hash-routing.tsx +68 -14
- package/src/index.ts +1 -0
- package/src/sanitize-view-name.tsx +17 -0
- package/src/shared-impl.ts +1 -1
- package/src/types.ts +6 -2
- package/src/__mocks__/before-send-data.ts +0 -538
- package/src/__mocks__/index.ts +0 -7
- package/src/__mocks__/init-config.ts +0 -6
- package/src/__mocks__/mfe-host.ts +0 -7
- package/src/__mocks__/process-event.ts +0 -20
- package/src/__mocks__/reset-shared-impl.ts +0 -8
- package/src/__mocks__/tracing-urls.ts +0 -30
- package/src/__mocks__/types.ts +0 -1
- package/src/__tests__/before-send.test.ts +0 -76
- package/src/__tests__/build-allowed-tracing-urls.test.ts +0 -120
- package/src/__tests__/build-before-send.test.ts +0 -193
- package/src/__tests__/create-impl.test.ts +0 -427
- package/src/__tests__/datadog-provider.test.tsx +0 -145
- package/src/__tests__/dd-rum-guard.test.ts +0 -73
- package/src/__tests__/element-service-recorder.test.ts +0 -127
- package/src/__tests__/enrich-event.test.ts +0 -139
- package/src/__tests__/get-shared.test.ts +0 -56
- package/src/__tests__/handle-resource.test.ts +0 -76
- package/src/__tests__/hash-routing.test.tsx +0 -70
- package/src/__tests__/init.test.ts +0 -69
- package/src/__tests__/integration.test.ts +0 -147
- package/src/__tests__/resolve-path-service.test.ts +0 -130
- package/src/__tests__/sanitize-view-name.test.tsx +0 -92
- package/src/__tests__/set-user.test.ts +0 -61
- package/src/__tests__/use-rum-service.test.tsx +0 -82
- package/src/runtime-override/__tests__/dev-console.test.ts +0 -158
- 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":"
|
|
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"}
|
package/dist/create-impl.js
CHANGED
|
@@ -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)
|
package/dist/create-impl.js.map
CHANGED
|
@@ -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","
|
|
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":"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"}
|
|
@@ -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;
|
|
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"}
|
package/dist/datadog-provider.js
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/get-env.js
ADDED
|
@@ -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"}
|
package/dist/hash-routing.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
export
|
|
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,
|
|
1
|
+
{"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAoC,MAAM,OAAO,CAAC;AAO7D,MAAM,WAAW,kBAAkB;IAC/B,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAG9C,CAAC"}
|
package/dist/hash-routing.js
CHANGED
|
@@ -1,22 +1,66 @@
|
|
|
1
1
|
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import * as ReactRouterDom from 'react-router-dom';
|
|
4
4
|
import { sanitizeViewName } from './sanitize-view-name';
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */ const { useHistory, useLocation } = ReactRouterDom;
|
|
6
|
+
export const HashRouting = ({ redirectedViews })=>{
|
|
7
|
+
useHashRouting(redirectedViews);
|
|
8
|
+
return null;
|
|
9
|
+
};
|
|
10
|
+
const useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;
|
|
11
|
+
/*
|
|
12
|
+
* Starts views from the router's history, before it re-renders and the page sends requests.
|
|
13
|
+
* A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.
|
|
14
|
+
*/ function useHistoryRouting(redirectedViews = []) {
|
|
15
|
+
const history = useHistory();
|
|
16
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
17
|
+
const view = useRef(noView);
|
|
18
|
+
useLayoutEffect(()=>{
|
|
19
|
+
const update = ({ pathname })=>{
|
|
20
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
21
|
+
};
|
|
22
|
+
update(history.location);
|
|
23
|
+
return history.listen(update);
|
|
13
24
|
}, [
|
|
14
|
-
|
|
25
|
+
history,
|
|
26
|
+
redirects
|
|
15
27
|
]);
|
|
28
|
+
}
|
|
29
|
+
/* A layout effect starts the view before pages' componentDidMount and effects send requests. */ function useLocationRouting(redirectedViews = []) {
|
|
30
|
+
const { pathname } = useLocation();
|
|
31
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
32
|
+
const view = useRef(noView);
|
|
33
|
+
useLayoutEffect(()=>{
|
|
34
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
35
|
+
}, [
|
|
36
|
+
pathname,
|
|
37
|
+
redirects
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
const noView = {
|
|
41
|
+
isRedirect: false
|
|
16
42
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
43
|
+
function updateView(view, pathname, redirects) {
|
|
44
|
+
const name = sanitizeViewName(pathname);
|
|
45
|
+
if (name === view.name) {
|
|
46
|
+
return view;
|
|
47
|
+
}
|
|
48
|
+
/* A redirect's destination takes over the view the redirect started. */ if (view.isRedirect) {
|
|
49
|
+
datadogRum.setViewName(name);
|
|
50
|
+
} else {
|
|
51
|
+
datadogRum.startView(name);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
name,
|
|
55
|
+
isRedirect: redirects.has(name)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function useSanitizedViewNames(viewNames) {
|
|
59
|
+
const key = viewNames.join('\n'); // handles when callers pass a new array on every render
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames
|
|
61
|
+
return useMemo(()=>new Set(viewNames.map(sanitizeViewName)), [
|
|
62
|
+
key
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
21
65
|
|
|
22
66
|
//# sourceMappingURL=hash-routing.js.map
|
package/dist/hash-routing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC,
|
|
1
|
+
{"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, useLayoutEffect, useMemo, useRef } from 'react';\nimport * as ReactRouterDom from 'react-router-dom';\nimport { sanitizeViewName } from './sanitize-view-name';\n\n/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */\nconst { useHistory, useLocation } = ReactRouterDom;\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\nconst useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;\n\n/*\n * Starts views from the router's history, before it re-renders and the page sends requests.\n * A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.\n */\nfunction useHistoryRouting(redirectedViews: string[] = []) {\n const history = useHistory();\n const redirects = useSanitizedViewNames(redirectedViews);\n const view = useRef(noView);\n\n useLayoutEffect(() => {\n const update = ({ pathname }: { pathname: string }) => {\n view.current = updateView(view.current, pathname, redirects);\n };\n update(history.location);\n return history.listen(update);\n }, [history, redirects]);\n}\n\n/* A layout effect starts the view before pages' componentDidMount and effects send requests. */\nfunction useLocationRouting(redirectedViews: string[] = []) {\n const { pathname } = useLocation();\n const redirects = useSanitizedViewNames(redirectedViews);\n const view = useRef(noView);\n\n useLayoutEffect(() => {\n view.current = updateView(view.current, pathname, redirects);\n }, [pathname, redirects]);\n}\n\ninterface View {\n name?: string;\n isRedirect: boolean;\n}\n\nconst noView: View = { isRedirect: false };\n\nfunction updateView(view: View, pathname: string, redirects: ReadonlySet<string>): View {\n const name = sanitizeViewName(pathname);\n if (name === view.name) {\n return view;\n }\n /* A redirect's destination takes over the view the redirect started. */\n if (view.isRedirect) {\n datadogRum.setViewName(name);\n } else {\n datadogRum.startView(name);\n }\n return { name, isRedirect: redirects.has(name) };\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","useLayoutEffect","useMemo","useRef","ReactRouterDom","sanitizeViewName","useHistory","useLocation","HashRouting","redirectedViews","useHashRouting","useHistoryRouting","useLocationRouting","history","redirects","useSanitizedViewNames","view","noView","update","pathname","current","updateView","location","listen","isRedirect","name","setViewName","startView","has","viewNames","key","join","Set","map"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,eAAe,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAC7D,YAAYC,oBAAoB,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,+EAA+E,GAC/E,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAE,GAAGH;AAOpC,OAAO,MAAMI,cAAsC,CAAC,EAAEC,eAAe,EAAE;IACnEC,eAAeD;IACf,OAAO;AACX,EAAE;AAEF,MAAMC,iBAAiB,OAAOJ,eAAe,aAAaK,oBAAoBC;AAE9E;;;CAGC,GACD,SAASD,kBAAkBF,kBAA4B,EAAE;IACrD,MAAMI,UAAUP;IAChB,MAAMQ,YAAYC,sBAAsBN;IACxC,MAAMO,OAAOb,OAAOc;IAEpBhB,gBAAgB;QACZ,MAAMiB,SAAS,CAAC,EAAEC,QAAQ,EAAwB;YAC9CH,KAAKI,OAAO,GAAGC,WAAWL,KAAKI,OAAO,EAAED,UAAUL;QACtD;QACAI,OAAOL,QAAQS,QAAQ;QACvB,OAAOT,QAAQU,MAAM,CAACL;IAC1B,GAAG;QAACL;QAASC;KAAU;AAC3B;AAEA,8FAA8F,GAC9F,SAASF,mBAAmBH,kBAA4B,EAAE;IACtD,MAAM,EAAEU,QAAQ,EAAE,GAAGZ;IACrB,MAAMO,YAAYC,sBAAsBN;IACxC,MAAMO,OAAOb,OAAOc;IAEpBhB,gBAAgB;QACZe,KAAKI,OAAO,GAAGC,WAAWL,KAAKI,OAAO,EAAED,UAAUL;IACtD,GAAG;QAACK;QAAUL;KAAU;AAC5B;AAOA,MAAMG,SAAe;IAAEO,YAAY;AAAM;AAEzC,SAASH,WAAWL,IAAU,EAAEG,QAAgB,EAAEL,SAA8B;IAC5E,MAAMW,OAAOpB,iBAAiBc;IAC9B,IAAIM,SAAST,KAAKS,IAAI,EAAE;QACpB,OAAOT;IACX;IACA,sEAAsE,GACtE,IAAIA,KAAKQ,UAAU,EAAE;QACjBxB,WAAW0B,WAAW,CAACD;IAC3B,OAAO;QACHzB,WAAW2B,SAAS,CAACF;IACzB;IACA,OAAO;QAAEA;QAAMD,YAAYV,UAAUc,GAAG,CAACH;IAAM;AACnD;AAEA,SAASV,sBAAsBc,SAAmB;IAC9C,MAAMC,MAAMD,UAAUE,IAAI,CAAC,OAAO,wDAAwD;IAC1F,+EAA+E;IAC/E,OAAO7B,QAAQ,IAAM,IAAI8B,IAAIH,UAAUI,GAAG,CAAC5B,oBAAoB;QAACyB;KAAI;AACxE"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -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
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,
|
|
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,
|
|
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"}
|
package/dist/shared-impl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context, User } from '@datadog/browser-
|
|
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,
|
|
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"}
|
package/dist/shared-impl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shared-impl.ts"],"sourcesContent":["import type { Context, User } from '@datadog/browser-
|
|
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-
|
|
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
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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 {
|
|
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.
|
|
3
|
+
"version": "40.4.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.
|
|
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
|
},
|
package/src/create-impl.ts
CHANGED
|
@@ -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),
|
package/src/datadog-provider.tsx
CHANGED
|
@@ -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 &&
|
|
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
|
+
}
|
package/src/hash-routing.tsx
CHANGED
|
@@ -1,21 +1,75 @@
|
|
|
1
1
|
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import { FC,
|
|
3
|
-
import
|
|
2
|
+
import { FC, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import * as ReactRouterDom from 'react-router-dom';
|
|
4
4
|
import { sanitizeViewName } from './sanitize-view-name';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const lastPathname = useRef<string | undefined>(undefined);
|
|
6
|
+
/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */
|
|
7
|
+
const { useHistory, useLocation } = ReactRouterDom;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}, [pathname]);
|
|
16
|
-
};
|
|
9
|
+
export interface HashRoutingOptions {
|
|
10
|
+
/** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */
|
|
11
|
+
redirectedViews?: string[];
|
|
12
|
+
}
|
|
17
13
|
|
|
18
|
-
export const HashRouting: FC = () => {
|
|
19
|
-
useHashRouting();
|
|
14
|
+
export const HashRouting: FC<HashRoutingOptions> = ({ redirectedViews }) => {
|
|
15
|
+
useHashRouting(redirectedViews);
|
|
20
16
|
return null;
|
|
21
17
|
};
|
|
18
|
+
|
|
19
|
+
const useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Starts views from the router's history, before it re-renders and the page sends requests.
|
|
23
|
+
* A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.
|
|
24
|
+
*/
|
|
25
|
+
function useHistoryRouting(redirectedViews: string[] = []) {
|
|
26
|
+
const history = useHistory();
|
|
27
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
28
|
+
const view = useRef(noView);
|
|
29
|
+
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
const update = ({ pathname }: { pathname: string }) => {
|
|
32
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
33
|
+
};
|
|
34
|
+
update(history.location);
|
|
35
|
+
return history.listen(update);
|
|
36
|
+
}, [history, redirects]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* A layout effect starts the view before pages' componentDidMount and effects send requests. */
|
|
40
|
+
function useLocationRouting(redirectedViews: string[] = []) {
|
|
41
|
+
const { pathname } = useLocation();
|
|
42
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
43
|
+
const view = useRef(noView);
|
|
44
|
+
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
47
|
+
}, [pathname, redirects]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface View {
|
|
51
|
+
name?: string;
|
|
52
|
+
isRedirect: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const noView: View = { isRedirect: false };
|
|
56
|
+
|
|
57
|
+
function updateView(view: View, pathname: string, redirects: ReadonlySet<string>): View {
|
|
58
|
+
const name = sanitizeViewName(pathname);
|
|
59
|
+
if (name === view.name) {
|
|
60
|
+
return view;
|
|
61
|
+
}
|
|
62
|
+
/* A redirect's destination takes over the view the redirect started. */
|
|
63
|
+
if (view.isRedirect) {
|
|
64
|
+
datadogRum.setViewName(name);
|
|
65
|
+
} else {
|
|
66
|
+
datadogRum.startView(name);
|
|
67
|
+
}
|
|
68
|
+
return { name, isRedirect: redirects.has(name) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function useSanitizedViewNames(viewNames: string[]) {
|
|
72
|
+
const key = viewNames.join('\n'); // handles when callers pass a new array on every render
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames
|
|
74
|
+
return useMemo(() => new Set(viewNames.map(sanitizeViewName)), [key]);
|
|
75
|
+
}
|