@servicetitan/datadog-rum 36.3.0 → 36.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/before-send.d.ts +11 -1
- package/dist/before-send.d.ts.map +1 -1
- package/dist/before-send.js +2 -56
- package/dist/before-send.js.map +1 -1
- package/dist/build-allowed-tracing-urls.d.ts +9 -0
- package/dist/build-allowed-tracing-urls.d.ts.map +1 -0
- package/dist/build-allowed-tracing-urls.js +54 -0
- package/dist/build-allowed-tracing-urls.js.map +1 -0
- package/dist/build-before-send.d.ts +4 -0
- package/dist/build-before-send.d.ts.map +1 -0
- package/dist/build-before-send.js +64 -0
- package/dist/build-before-send.js.map +1 -0
- package/dist/bundle-state.d.ts +10 -0
- package/dist/bundle-state.d.ts.map +1 -0
- package/dist/bundle-state.js +10 -0
- package/dist/bundle-state.js.map +1 -0
- package/dist/create-impl.d.ts +8 -0
- package/dist/create-impl.d.ts.map +1 -0
- package/dist/create-impl.js +65 -0
- package/dist/create-impl.js.map +1 -0
- package/dist/datadog-provider.d.ts +2 -5
- package/dist/datadog-provider.d.ts.map +1 -1
- package/dist/datadog-provider.js +2 -2
- package/dist/datadog-provider.js.map +1 -1
- package/dist/enrich-event.d.ts +6 -0
- package/dist/enrich-event.d.ts.map +1 -0
- package/dist/enrich-event.js +33 -0
- package/dist/enrich-event.js.map +1 -0
- package/dist/get-shared.d.ts +10 -0
- package/dist/get-shared.d.ts.map +1 -0
- package/dist/get-shared.js +16 -0
- package/dist/get-shared.js.map +1 -0
- package/dist/handle-resource.d.ts +3 -0
- package/dist/handle-resource.d.ts.map +1 -0
- package/dist/handle-resource.js +27 -0
- package/dist/handle-resource.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +17 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +28 -0
- package/dist/init.js.map +1 -0
- package/dist/set-user.d.ts +13 -0
- package/dist/set-user.d.ts.map +1 -0
- package/dist/set-user.js +22 -0
- package/dist/set-user.js.map +1 -0
- package/dist/shared-impl.d.ts +11 -0
- package/dist/shared-impl.d.ts.map +1 -0
- package/dist/shared-impl.js +3 -0
- package/dist/shared-impl.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/use-rum-service.d.ts +12 -0
- package/dist/use-rum-service.d.ts.map +1 -0
- package/dist/use-rum-service.js +25 -0
- package/dist/use-rum-service.js.map +1 -0
- package/package.json +3 -3
- package/src/__mocks__/index.ts +6 -0
- package/src/__mocks__/init-config.ts +6 -0
- package/src/__mocks__/process-event.ts +20 -0
- package/src/__mocks__/reset-shared-impl.ts +8 -0
- package/src/__mocks__/tracing-urls.ts +30 -0
- package/src/__mocks__/types.ts +1 -0
- package/src/__tests__/before-send.test.ts +39 -87
- package/src/__tests__/build-allowed-tracing-urls.test.ts +120 -0
- package/src/__tests__/build-before-send.test.ts +193 -0
- package/src/__tests__/create-impl.test.ts +211 -0
- package/src/__tests__/datadog-provider.test.tsx +55 -25
- package/src/__tests__/enrich-event.test.ts +34 -0
- package/src/__tests__/get-shared.test.ts +56 -0
- package/src/__tests__/handle-resource.test.ts +76 -0
- package/src/__tests__/init.test.ts +69 -0
- package/src/__tests__/integration.test.ts +147 -0
- package/src/__tests__/set-user.test.ts +61 -0
- package/src/__tests__/use-rum-service.test.tsx +82 -0
- package/src/before-send.ts +15 -63
- package/src/build-allowed-tracing-urls.ts +53 -0
- package/src/build-before-send.ts +81 -0
- package/src/bundle-state.ts +9 -0
- package/src/create-impl.ts +71 -0
- package/src/datadog-provider.tsx +4 -6
- package/src/enrich-event.ts +38 -0
- package/src/get-shared.ts +24 -0
- package/src/handle-resource.ts +30 -0
- package/src/index.ts +3 -0
- package/src/init.ts +39 -0
- package/src/set-user.ts +25 -0
- package/src/shared-impl.ts +9 -0
- package/src/types.ts +61 -0
- package/src/use-rum-service.ts +28 -0
package/dist/before-send.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import type { RumInitConfiguration } from '@datadog/browser-rum';
|
|
1
|
+
import type { RumEvent, RumEventDomainContext, RumInitConfiguration } from '@datadog/browser-rum';
|
|
2
|
+
/**
|
|
3
|
+
* Used for `application.beforeSend`. Returning `false` drops the event app-wide;
|
|
4
|
+
* `void` / `true` passes it through.
|
|
5
|
+
*/
|
|
6
|
+
export type ApplicationBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => boolean | void;
|
|
7
|
+
/**
|
|
8
|
+
* Used for per-service `beforeSend`. Transform-only: the return value is
|
|
9
|
+
* ignored. Only `application.beforeSend` may drop events.
|
|
10
|
+
*/
|
|
11
|
+
export type ServiceBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => void;
|
|
2
12
|
export declare function beforeSend(handler?: RumInitConfiguration['beforeSend']): NonNullable<RumInitConfiguration['beforeSend']>;
|
|
3
13
|
//# sourceMappingURL=before-send.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"before-send.d.ts","sourceRoot":"","sources":["../src/before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"before-send.d.ts","sourceRoot":"","sources":["../src/before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,QAAQ,EACR,qBAAqB,EACrB,oBAAoB,EAEvB,MAAM,sBAAsB,CAAC;AAI9B;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACvC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,qBAAqB,KAC7B,OAAO,GAAG,IAAI,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEjG,wBAAgB,UAAU,CACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,GAC7C,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAcjD"}
|
package/dist/before-send.js
CHANGED
|
@@ -1,59 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return new URL(url).hostname === window.location.hostname;
|
|
4
|
-
}
|
|
5
|
-
function parseService(event, input) {
|
|
6
|
-
var _match_groups, _match_groups1;
|
|
7
|
-
const match = input === null || input === void 0 ? void 0 : input.match(SERVICE_REGEX);
|
|
8
|
-
const service = match === null || match === void 0 ? void 0 : (_match_groups = match.groups) === null || _match_groups === void 0 ? void 0 : _match_groups.service;
|
|
9
|
-
const version = match === null || match === void 0 ? void 0 : (_match_groups1 = match.groups) === null || _match_groups1 === void 0 ? void 0 : _match_groups1.version;
|
|
10
|
-
if (service) {
|
|
11
|
-
event.service = service;
|
|
12
|
-
event.version = version !== null && version !== void 0 ? version : 'unknown';
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
|
|
19
|
-
*/ function enrichEvent(event, context) {
|
|
20
|
-
var _ref;
|
|
21
|
-
var _event_error, _event_error1, _event_resource;
|
|
22
|
-
const stack = (_ref = context && 'handlingStack' in context ? context.handlingStack : undefined) !== null && _ref !== void 0 ? _ref : event.type === 'error' ? (_event_error = event.error) === null || _event_error === void 0 ? void 0 : _event_error.stack : undefined;
|
|
23
|
-
const message = event.type === 'error' ? (_event_error1 = event.error) === null || _event_error1 === void 0 ? void 0 : _event_error1.message : undefined;
|
|
24
|
-
const url = event.type === 'resource' ? (_event_resource = event.resource) === null || _event_resource === void 0 ? void 0 : _event_resource.url : undefined;
|
|
25
|
-
for (const source of [
|
|
26
|
-
stack,
|
|
27
|
-
message,
|
|
28
|
-
url
|
|
29
|
-
]){
|
|
30
|
-
if (parseService(event, source)) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function handleResource(event, context) {
|
|
36
|
-
if (!isSameDomainRequest(event.resource.url)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
let cfRay = undefined;
|
|
40
|
-
switch(event.resource.type){
|
|
41
|
-
case 'fetch':
|
|
42
|
-
var _context_response;
|
|
43
|
-
cfRay = (_context_response = context.response) === null || _context_response === void 0 ? void 0 : _context_response.headers.get('cf-ray');
|
|
44
|
-
break;
|
|
45
|
-
case 'xhr':
|
|
46
|
-
var _context_xhr;
|
|
47
|
-
cfRay = (_context_xhr = context.xhr) === null || _context_xhr === void 0 ? void 0 : _context_xhr.getResponseHeader('cf-ray');
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
if (cfRay) {
|
|
51
|
-
event.context = {
|
|
52
|
-
...event.context,
|
|
53
|
-
cfRay
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import { enrichEvent } from './enrich-event';
|
|
2
|
+
import { handleResource } from './handle-resource';
|
|
57
3
|
export function beforeSend(handler) {
|
|
58
4
|
return function(event, context) {
|
|
59
5
|
try {
|
package/dist/before-send.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n
|
|
1
|
+
{"version":3,"sources":["../src/before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumInitConfiguration,\n RumResourceEventDomainContext,\n} from '@datadog/browser-rum';\nimport { enrichEvent } from './enrich-event';\nimport { handleResource } from './handle-resource';\n\n/**\n * Used for `application.beforeSend`. Returning `false` drops the event app-wide;\n * `void` / `true` passes it through.\n */\nexport type ApplicationBeforeSendHandler = (\n event: RumEvent,\n context: RumEventDomainContext\n) => boolean | void;\n\n/**\n * Used for per-service `beforeSend`. Transform-only: the return value is\n * ignored. Only `application.beforeSend` may drop events.\n */\nexport type ServiceBeforeSendHandler = (event: RumEvent, context: RumEventDomainContext) => void;\n\nexport function beforeSend(\n handler?: RumInitConfiguration['beforeSend']\n): NonNullable<RumInitConfiguration['beforeSend']> {\n return function (event: RumEvent, context: RumEventDomainContext) {\n try {\n if (event.type === 'resource') {\n handleResource(event, context as RumResourceEventDomainContext);\n }\n\n enrichEvent(event, context);\n\n return handler?.(event, context) ?? true;\n } catch {} // eslint-disable-line no-empty\n\n return true;\n };\n}\n"],"names":["enrichEvent","handleResource","beforeSend","handler","event","context","type"],"mappings":"AAMA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,oBAAoB;AAiBnD,OAAO,SAASC,WACZC,OAA4C;IAE5C,OAAO,SAAUC,KAAe,EAAEC,OAA8B;QAC5D,IAAI;;YACA,IAAID,MAAME,IAAI,KAAK,YAAY;gBAC3BL,eAAeG,OAAOC;YAC1B;YAEAL,YAAYI,OAAOC;YAEnB,eAAOF,oBAAAA,8BAAAA,QAAUC,OAAOC,+CAAY;QACxC,EAAE,eAAM,CAAC,EAAE,+BAA+B;QAE1C,OAAO;IACX;AACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RumInitConfiguration } from '@datadog/browser-rum';
|
|
2
|
+
import type { State } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks
|
|
5
|
+
* registered services and returns true if any matcher registered under that
|
|
6
|
+
* propagator matches. Late-loading MFEs work fully dynamically.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildAllowedTracingUrls(state: State): NonNullable<RumInitConfiguration['allowedTracingUrls']>;
|
|
9
|
+
//# sourceMappingURL=build-allowed-tracing-urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-allowed-tracing-urls.d.ts","sourceRoot":"","sources":["../src/build-allowed-tracing-urls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA+B,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA0BrC;;;;GAIG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,GACb,WAAW,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,CAkBzD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const PROPAGATOR_TYPES = [
|
|
2
|
+
'datadog',
|
|
3
|
+
'tracecontext',
|
|
4
|
+
'b3',
|
|
5
|
+
'b3multi'
|
|
6
|
+
];
|
|
7
|
+
/**
|
|
8
|
+
* Mirrors `@datadog/browser-rum-core`'s tracing URL match semantics:
|
|
9
|
+
* - strings are prefix-matched (SDK passes `useStartsWith=true` for tracing URLs)
|
|
10
|
+
*
|
|
11
|
+
* Per-call try/catch mirrors the SDK's `matchList`: a throwing user function or
|
|
12
|
+
* malformed RegExp only loses its own match decision rather than breaking the
|
|
13
|
+
* wrapper for every other matcher.
|
|
14
|
+
*/ function matchOption(opt, url) {
|
|
15
|
+
try {
|
|
16
|
+
if (typeof opt === 'function') {
|
|
17
|
+
return opt(url);
|
|
18
|
+
}
|
|
19
|
+
if (typeof opt === 'string') {
|
|
20
|
+
return url.startsWith(opt);
|
|
21
|
+
}
|
|
22
|
+
return opt.test(url);
|
|
23
|
+
} catch (unused) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks
|
|
29
|
+
* registered services and returns true if any matcher registered under that
|
|
30
|
+
* propagator matches. Late-loading MFEs work fully dynamically.
|
|
31
|
+
*/ export function buildAllowedTracingUrls(state) {
|
|
32
|
+
return PROPAGATOR_TYPES.map((pt)=>({
|
|
33
|
+
match: (url)=>{
|
|
34
|
+
for (const entry of state.services.values()){
|
|
35
|
+
var _entry_allowedTracingUrls;
|
|
36
|
+
const matchers = (_entry_allowedTracingUrls = entry.allowedTracingUrls) === null || _entry_allowedTracingUrls === void 0 ? void 0 : _entry_allowedTracingUrls[pt];
|
|
37
|
+
if (!matchers) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const m of matchers){
|
|
41
|
+
if (matchOption(m, url)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
propagatorTypes: [
|
|
49
|
+
pt
|
|
50
|
+
]
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=build-allowed-tracing-urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/build-allowed-tracing-urls.ts"],"sourcesContent":["import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum';\nimport type { State } from './types';\n\nconst PROPAGATOR_TYPES: readonly PropagatorType[] = ['datadog', 'tracecontext', 'b3', 'b3multi'];\n\n/**\n * Mirrors `@datadog/browser-rum-core`'s tracing URL match semantics:\n * - strings are prefix-matched (SDK passes `useStartsWith=true` for tracing URLs)\n *\n * Per-call try/catch mirrors the SDK's `matchList`: a throwing user function or\n * malformed RegExp only loses its own match decision rather than breaking the\n * wrapper for every other matcher.\n */\nfunction matchOption(opt: MatchOption, url: string): boolean {\n try {\n if (typeof opt === 'function') {\n return opt(url);\n }\n if (typeof opt === 'string') {\n return url.startsWith(opt);\n }\n return opt.test(url);\n } catch {\n return false;\n }\n}\n\n/**\n * Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks\n * registered services and returns true if any matcher registered under that\n * propagator matches. Late-loading MFEs work fully dynamically.\n */\nexport function buildAllowedTracingUrls(\n state: State\n): NonNullable<RumInitConfiguration['allowedTracingUrls']> {\n return PROPAGATOR_TYPES.map(pt => ({\n match: (url: string) => {\n for (const entry of state.services.values()) {\n const matchers = entry.allowedTracingUrls?.[pt];\n if (!matchers) {\n continue;\n }\n for (const m of matchers) {\n if (matchOption(m, url)) {\n return true;\n }\n }\n }\n return false;\n },\n propagatorTypes: [pt],\n }));\n}\n"],"names":["PROPAGATOR_TYPES","matchOption","opt","url","startsWith","test","buildAllowedTracingUrls","state","map","pt","match","entry","services","values","matchers","allowedTracingUrls","m","propagatorTypes"],"mappings":"AAGA,MAAMA,mBAA8C;IAAC;IAAW;IAAgB;IAAM;CAAU;AAEhG;;;;;;;CAOC,GACD,SAASC,YAAYC,GAAgB,EAAEC,GAAW;IAC9C,IAAI;QACA,IAAI,OAAOD,QAAQ,YAAY;YAC3B,OAAOA,IAAIC;QACf;QACA,IAAI,OAAOD,QAAQ,UAAU;YACzB,OAAOC,IAAIC,UAAU,CAACF;QAC1B;QACA,OAAOA,IAAIG,IAAI,CAACF;IACpB,EAAE,eAAM;QACJ,OAAO;IACX;AACJ;AAEA;;;;CAIC,GACD,OAAO,SAASG,wBACZC,KAAY;IAEZ,OAAOP,iBAAiBQ,GAAG,CAACC,CAAAA,KAAO,CAAA;YAC/BC,OAAO,CAACP;gBACJ,KAAK,MAAMQ,SAASJ,MAAMK,QAAQ,CAACC,MAAM,GAAI;wBACxBF;oBAAjB,MAAMG,YAAWH,4BAAAA,MAAMI,kBAAkB,cAAxBJ,gDAAAA,yBAA0B,CAACF,GAAG;oBAC/C,IAAI,CAACK,UAAU;wBACX;oBACJ;oBACA,KAAK,MAAME,KAAKF,SAAU;wBACtB,IAAIb,YAAYe,GAAGb,MAAM;4BACrB,OAAO;wBACX;oBACJ;gBACJ;gBACA,OAAO;YACX;YACAc,iBAAiB;gBAACR;aAAG;QACzB,CAAA;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-before-send.d.ts","sourceRoot":"","sources":["../src/build-before-send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,oBAAoB,EAEvB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAyDrC,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAc7F"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { enrichEvent } from './enrich-event';
|
|
2
|
+
import { handleResource } from './handle-resource';
|
|
3
|
+
function applyBuiltIn(event, context) {
|
|
4
|
+
if (event.type === 'resource') {
|
|
5
|
+
handleResource(event, context);
|
|
6
|
+
}
|
|
7
|
+
enrichEvent(event, context);
|
|
8
|
+
}
|
|
9
|
+
function callApplicationHandler(handler, event, context) {
|
|
10
|
+
try {
|
|
11
|
+
return handler(event, context) !== false;
|
|
12
|
+
} catch (unused) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function callServiceHandler(handler, event, context) {
|
|
17
|
+
try {
|
|
18
|
+
handler(event, context);
|
|
19
|
+
} catch (unused) {
|
|
20
|
+
// Fail-open: a service handler may not drop or block events.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function applyApplication(state, event, context) {
|
|
24
|
+
if (state.applicationBeforeSend) {
|
|
25
|
+
return callApplicationHandler(state.applicationBeforeSend, event, context);
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function applyServiceSpecific(state, event, context) {
|
|
30
|
+
const serviceKey = event.service;
|
|
31
|
+
if (!serviceKey) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const entry = state.services.get(serviceKey);
|
|
35
|
+
if (!entry) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (entry.beforeSend) {
|
|
39
|
+
callServiceHandler(entry.beforeSend, event, context);
|
|
40
|
+
}
|
|
41
|
+
if (entry.context) {
|
|
42
|
+
event.context = {
|
|
43
|
+
...event.context,
|
|
44
|
+
...entry.context
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function buildBeforeSend(state) {
|
|
49
|
+
return function(event, context) {
|
|
50
|
+
try {
|
|
51
|
+
applyBuiltIn(event, context);
|
|
52
|
+
if (!applyApplication(state, event, context)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
applyServiceSpecific(state, event, context);
|
|
56
|
+
return true;
|
|
57
|
+
} catch (unused) {
|
|
58
|
+
// Fail-open: prefer noisy data over no data.
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=build-before-send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/build-before-send.ts"],"sourcesContent":["import type {\n RumEvent,\n RumEventDomainContext,\n RumInitConfiguration,\n RumResourceEventDomainContext,\n} from '@datadog/browser-rum';\nimport type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send';\nimport { enrichEvent } from './enrich-event';\nimport { handleResource } from './handle-resource';\nimport type { State } from './types';\n\nfunction applyBuiltIn(event: RumEvent, context: RumEventDomainContext): void {\n if (event.type === 'resource') {\n handleResource(event, context as RumResourceEventDomainContext);\n }\n enrichEvent(event, context);\n}\n\nfunction callApplicationHandler(\n handler: ApplicationBeforeSendHandler,\n event: RumEvent,\n context: RumEventDomainContext\n): boolean {\n try {\n return handler(event, context) !== false;\n } catch {\n return true;\n }\n}\n\nfunction callServiceHandler(\n handler: ServiceBeforeSendHandler,\n event: RumEvent,\n context: RumEventDomainContext\n): void {\n try {\n handler(event, context);\n } catch {\n // Fail-open: a service handler may not drop or block events.\n }\n}\n\nfunction applyApplication(state: State, event: RumEvent, context: RumEventDomainContext): boolean {\n if (state.applicationBeforeSend) {\n return callApplicationHandler(state.applicationBeforeSend, event, context);\n }\n return true;\n}\n\nfunction applyServiceSpecific(state: State, event: RumEvent, context: RumEventDomainContext): void {\n const serviceKey = event.service;\n if (!serviceKey) {\n return;\n }\n const entry = state.services.get(serviceKey);\n if (!entry) {\n return;\n }\n if (entry.beforeSend) {\n callServiceHandler(entry.beforeSend, event, context);\n }\n if (entry.context) {\n event.context = { ...event.context, ...entry.context };\n }\n}\n\nexport function buildBeforeSend(state: State): NonNullable<RumInitConfiguration['beforeSend']> {\n return function (event: RumEvent, context: RumEventDomainContext) {\n try {\n applyBuiltIn(event, context);\n if (!applyApplication(state, event, context)) {\n return false;\n }\n applyServiceSpecific(state, event, context);\n return true;\n } catch {\n // Fail-open: prefer noisy data over no data.\n return true;\n }\n };\n}\n"],"names":["enrichEvent","handleResource","applyBuiltIn","event","context","type","callApplicationHandler","handler","callServiceHandler","applyApplication","state","applicationBeforeSend","applyServiceSpecific","serviceKey","service","entry","services","get","beforeSend","buildBeforeSend"],"mappings":"AAOA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,oBAAoB;AAGnD,SAASC,aAAaC,KAAe,EAAEC,OAA8B;IACjE,IAAID,MAAME,IAAI,KAAK,YAAY;QAC3BJ,eAAeE,OAAOC;IAC1B;IACAJ,YAAYG,OAAOC;AACvB;AAEA,SAASE,uBACLC,OAAqC,EACrCJ,KAAe,EACfC,OAA8B;IAE9B,IAAI;QACA,OAAOG,QAAQJ,OAAOC,aAAa;IACvC,EAAE,eAAM;QACJ,OAAO;IACX;AACJ;AAEA,SAASI,mBACLD,OAAiC,EACjCJ,KAAe,EACfC,OAA8B;IAE9B,IAAI;QACAG,QAAQJ,OAAOC;IACnB,EAAE,eAAM;IACJ,6DAA6D;IACjE;AACJ;AAEA,SAASK,iBAAiBC,KAAY,EAAEP,KAAe,EAAEC,OAA8B;IACnF,IAAIM,MAAMC,qBAAqB,EAAE;QAC7B,OAAOL,uBAAuBI,MAAMC,qBAAqB,EAAER,OAAOC;IACtE;IACA,OAAO;AACX;AAEA,SAASQ,qBAAqBF,KAAY,EAAEP,KAAe,EAAEC,OAA8B;IACvF,MAAMS,aAAaV,MAAMW,OAAO;IAChC,IAAI,CAACD,YAAY;QACb;IACJ;IACA,MAAME,QAAQL,MAAMM,QAAQ,CAACC,GAAG,CAACJ;IACjC,IAAI,CAACE,OAAO;QACR;IACJ;IACA,IAAIA,MAAMG,UAAU,EAAE;QAClBV,mBAAmBO,MAAMG,UAAU,EAAEf,OAAOC;IAChD;IACA,IAAIW,MAAMX,OAAO,EAAE;QACfD,MAAMC,OAAO,GAAG;YAAE,GAAGD,MAAMC,OAAO;YAAE,GAAGW,MAAMX,OAAO;QAAC;IACzD;AACJ;AAEA,OAAO,SAASe,gBAAgBT,KAAY;IACxC,OAAO,SAAUP,KAAe,EAAEC,OAA8B;QAC5D,IAAI;YACAF,aAAaC,OAAOC;YACpB,IAAI,CAACK,iBAAiBC,OAAOP,OAAOC,UAAU;gBAC1C,OAAO;YACX;YACAQ,qBAAqBF,OAAOP,OAAOC;YACnC,OAAO;QACX,EAAE,eAAM;YACJ,6CAA6C;YAC7C,OAAO;QACX;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets
|
|
3
|
+
* its own copy of this module; nothing here lives on `globalThis`. The bundle
|
|
4
|
+
* whose `init` call wins the SDK init race sets `isSdkInitializer` here, and
|
|
5
|
+
* only its own bundle's `setUser` reads `true` from it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const bundleState: {
|
|
8
|
+
isSdkInitializer: boolean;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=bundle-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-state.d.ts","sourceRoot":"","sources":["../src/bundle-state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;CAEvB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets
|
|
3
|
+
* its own copy of this module; nothing here lives on `globalThis`. The bundle
|
|
4
|
+
* whose `init` call wins the SDK init race sets `isSdkInitializer` here, and
|
|
5
|
+
* only its own bundle's `setUser` reads `true` from it.
|
|
6
|
+
*/ export const bundleState = {
|
|
7
|
+
isSdkInitializer: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=bundle-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bundle-state.ts"],"sourcesContent":["/**\n * Bundle-local state. Each bundle that loads `@servicetitan/datadog-rum` gets\n * its own copy of this module; nothing here lives on `globalThis`. The bundle\n * whose `init` call wins the SDK init race sets `isSdkInitializer` here, and\n * only its own bundle's `setUser` reads `true` from it.\n */\nexport const bundleState = {\n isSdkInitializer: false,\n};\n"],"names":["bundleState","isSdkInitializer"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,MAAMA,cAAc;IACvBC,kBAAkB;AACtB,EAAE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SharedImpl } from './shared-impl';
|
|
2
|
+
/**
|
|
3
|
+
* Interop surface: stored on globalThis, shared across independently
|
|
4
|
+
* deployed bundles. First bundle to load wins. Append-only — never
|
|
5
|
+
* remove or change method signatures.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createImpl(): SharedImpl;
|
|
8
|
+
//# sourceMappingURL=create-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-impl.d.ts","sourceRoot":"","sources":["../src/create-impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAqDvC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
+
import { buildAllowedTracingUrls } from './build-allowed-tracing-urls';
|
|
3
|
+
import { buildBeforeSend } from './build-before-send';
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
sessionSampleRate: 100,
|
|
6
|
+
sessionReplaySampleRate: 0,
|
|
7
|
+
defaultPrivacyLevel: 'mask-user-input'
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Interop surface: stored on globalThis, shared across independently
|
|
11
|
+
* deployed bundles. First bundle to load wins. Append-only — never
|
|
12
|
+
* remove or change method signatures.
|
|
13
|
+
*/ export function createImpl() {
|
|
14
|
+
let initialized = false;
|
|
15
|
+
const state = {
|
|
16
|
+
services: new Map()
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
init ({ service, application }) {
|
|
20
|
+
let initializedSdk = false;
|
|
21
|
+
if (application) {
|
|
22
|
+
if (!initialized && !datadogRum.getInitConfiguration()) {
|
|
23
|
+
const { beforeSend: appBeforeSend, ...sdkConfigPart } = application;
|
|
24
|
+
if (appBeforeSend) {
|
|
25
|
+
state.applicationBeforeSend = appBeforeSend;
|
|
26
|
+
}
|
|
27
|
+
datadogRum.init({
|
|
28
|
+
...DEFAULTS,
|
|
29
|
+
...sdkConfigPart,
|
|
30
|
+
service: service.name,
|
|
31
|
+
beforeSend: buildBeforeSend(state),
|
|
32
|
+
allowedTracingUrls: buildAllowedTracingUrls(state)
|
|
33
|
+
});
|
|
34
|
+
initialized = true;
|
|
35
|
+
initializedSdk = true;
|
|
36
|
+
} else if (initialized) {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.info('[datadog-rum] init: application config ignored; SDK already initialized.');
|
|
39
|
+
} else {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.warn('[datadog-rum] init: SDK was initialized outside the facade; service handlers will not fire.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const { name, ...reg } = service;
|
|
45
|
+
const existing = state.services.get(name);
|
|
46
|
+
state.services.set(name, {
|
|
47
|
+
...reg,
|
|
48
|
+
context: existing === null || existing === void 0 ? void 0 : existing.context
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
cleanup: ()=>state.services.delete(name),
|
|
52
|
+
initializedSdk
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
setServiceContext (key, context) {
|
|
56
|
+
const existing = state.services.get(key);
|
|
57
|
+
state.services.set(key, {
|
|
58
|
+
...existing,
|
|
59
|
+
context
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=create-impl.js.map
|
|
@@ -0,0 +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 type { SharedImpl } from './shared-impl';\nimport type { 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 const state: State = {\n services: new Map(),\n };\n\n return {\n init({ service, application }) {\n let initializedSdk = false;\n\n if (application) {\n if (!initialized && !datadogRum.getInitConfiguration()) {\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 initialized = true;\n initializedSdk = true;\n } else if (initialized) {\n // eslint-disable-next-line no-console\n console.info(\n '[datadog-rum] init: application config ignored; SDK already initialized.'\n );\n } else {\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 }\n }\n\n const { name, ...reg } = service;\n const existing = state.services.get(name);\n state.services.set(name, { ...reg, context: existing?.context });\n\n return {\n cleanup: () => state.services.delete(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","DEFAULTS","sessionSampleRate","sessionReplaySampleRate","defaultPrivacyLevel","createImpl","initialized","state","services","Map","init","service","application","initializedSdk","getInitConfiguration","beforeSend","appBeforeSend","sdkConfigPart","applicationBeforeSend","name","allowedTracingUrls","console","info","warn","reg","existing","get","set","context","cleanup","delete","setServiceContext","key"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,eAAe,QAAQ,sBAAsB;AAItD,MAAMC,WAAW;IACbC,mBAAmB;IACnBC,yBAAyB;IACzBC,qBAAqB;AACzB;AAEA;;;;CAIC,GACD,OAAO,SAASC;IACZ,IAAIC,cAAc;IAClB,MAAMC,QAAe;QACjBC,UAAU,IAAIC;IAClB;IAEA,OAAO;QACHC,MAAK,EAAEC,OAAO,EAAEC,WAAW,EAAE;YACzB,IAAIC,iBAAiB;YAErB,IAAID,aAAa;gBACb,IAAI,CAACN,eAAe,CAACR,WAAWgB,oBAAoB,IAAI;oBACpD,MAAM,EAAEC,YAAYC,aAAa,EAAE,GAAGC,eAAe,GAAGL;oBACxD,IAAII,eAAe;wBACfT,MAAMW,qBAAqB,GAAGF;oBAClC;oBACAlB,WAAWY,IAAI,CAAC;wBACZ,GAAGT,QAAQ;wBACX,GAAGgB,aAAa;wBAChBN,SAASA,QAAQQ,IAAI;wBACrBJ,YAAYf,gBAAgBO;wBAC5Ba,oBAAoBrB,wBAAwBQ;oBAChD;oBACAD,cAAc;oBACdO,iBAAiB;gBACrB,OAAO,IAAIP,aAAa;oBACpB,sCAAsC;oBACtCe,QAAQC,IAAI,CACR;gBAER,OAAO;oBACH,sCAAsC;oBACtCD,QAAQE,IAAI,CACR;gBAER;YACJ;YAEA,MAAM,EAAEJ,IAAI,EAAE,GAAGK,KAAK,GAAGb;YACzB,MAAMc,WAAWlB,MAAMC,QAAQ,CAACkB,GAAG,CAACP;YACpCZ,MAAMC,QAAQ,CAACmB,GAAG,CAACR,MAAM;gBAAE,GAAGK,GAAG;gBAAEI,OAAO,EAAEH,qBAAAA,+BAAAA,SAAUG,OAAO;YAAC;YAE9D,OAAO;gBACHC,SAAS,IAAMtB,MAAMC,QAAQ,CAACsB,MAAM,CAACX;gBACrCN;YACJ;QACJ;QAEAkB,mBAAkBC,GAAG,EAAEJ,OAAO;YAC1B,MAAMH,WAAWlB,MAAMC,QAAQ,CAACkB,GAAG,CAACM;YACpCzB,MAAMC,QAAQ,CAACmB,GAAG,CAACK,KAAK;gBAAE,GAAGP,QAAQ;gBAAEG;YAAQ;QACnD;IACJ;AACJ"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
type
|
|
3
|
-
id: string;
|
|
4
|
-
};
|
|
2
|
+
import { type RumUser } from './set-user';
|
|
5
3
|
export interface Options {
|
|
6
4
|
hashRouting?: boolean;
|
|
7
5
|
}
|
|
8
6
|
export declare const DatadogProvider: FC<PropsWithChildren & {
|
|
9
7
|
isEnabled: boolean;
|
|
10
|
-
user?:
|
|
8
|
+
user?: RumUser;
|
|
11
9
|
options?: Options;
|
|
12
10
|
}>;
|
|
13
|
-
export {};
|
|
14
11
|
//# sourceMappingURL=datadog-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datadog-provider.d.ts","sourceRoot":"","sources":["../src/datadog-provider.tsx"],"names":[],"mappings":"
|
|
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,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"}
|
package/dist/datadog-provider.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { datadogRum } from '@datadog/browser-rum';
|
|
3
2
|
import { Fragment, useEffect } from 'react';
|
|
4
3
|
import { HashRouting } from './hash-routing';
|
|
4
|
+
import { setUser } from './set-user';
|
|
5
5
|
const SetUser = ({ user })=>{
|
|
6
6
|
useEffect(()=>{
|
|
7
7
|
if (user) {
|
|
8
|
-
|
|
8
|
+
setUser(user);
|
|
9
9
|
}
|
|
10
10
|
}, [
|
|
11
11
|
user
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/datadog-provider.tsx"],"sourcesContent":["import { FC, Fragment, PropsWithChildren, useEffect } from 'react';\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) {\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","HashRouting","setUser","SetUser","user","DatadogProvider","children","isEnabled","options","hashRouting"],"mappings":";AAAA,SAAaA,QAAQ,EAAqBC,SAAS,QAAQ,QAAQ;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAsB,aAAa;AAMnD,MAAMC,UAAkC,CAAC,EAAEC,IAAI,EAAE;IAC7CJ,UAAU;QACN,IAAII,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,WAAW;QACX,qBACI,MAACR;;8BACG,KAACI;oBAAQC,MAAMA;;gBACdI,CAAAA,oBAAAA,8BAAAA,QAASC,WAAW,mBAAI,KAACR;gBACzBK;;;IAGb;IACA,OAAOA;AACX,EAAE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';
|
|
2
|
+
/**
|
|
3
|
+
* See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
|
|
4
|
+
*/
|
|
5
|
+
export declare function enrichEvent(event: RumEvent, context: RumEventDomainContext): void;
|
|
6
|
+
//# sourceMappingURL=enrich-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrich-event.d.ts","sourceRoot":"","sources":["../src/enrich-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAoB5E;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAcjF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const SERVICE_REGEX = /unpkg\.servicetitan\.com\/@servicetitan\/(?<service>[\w-]+)(?:@(?<version>\d+\.\d+\.\d+(?:-[\w.]+)?))?/;
|
|
2
|
+
function parseService(event, input) {
|
|
3
|
+
var _match_groups, _match_groups1;
|
|
4
|
+
const match = input === null || input === void 0 ? void 0 : input.match(SERVICE_REGEX);
|
|
5
|
+
const service = match === null || match === void 0 ? void 0 : (_match_groups = match.groups) === null || _match_groups === void 0 ? void 0 : _match_groups.service;
|
|
6
|
+
const version = match === null || match === void 0 ? void 0 : (_match_groups1 = match.groups) === null || _match_groups1 === void 0 ? void 0 : _match_groups1.version;
|
|
7
|
+
if (service) {
|
|
8
|
+
event.service = service;
|
|
9
|
+
event.version = version !== null && version !== void 0 ? version : 'unknown';
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend
|
|
16
|
+
*/ export function enrichEvent(event, context) {
|
|
17
|
+
var _ref;
|
|
18
|
+
var _event_error, _event_error1, _event_resource;
|
|
19
|
+
const stack = (_ref = context && 'handlingStack' in context ? context.handlingStack : undefined) !== null && _ref !== void 0 ? _ref : event.type === 'error' ? (_event_error = event.error) === null || _event_error === void 0 ? void 0 : _event_error.stack : undefined;
|
|
20
|
+
const message = event.type === 'error' ? (_event_error1 = event.error) === null || _event_error1 === void 0 ? void 0 : _event_error1.message : undefined;
|
|
21
|
+
const url = event.type === 'resource' ? (_event_resource = event.resource) === null || _event_resource === void 0 ? void 0 : _event_resource.url : undefined;
|
|
22
|
+
for (const source of [
|
|
23
|
+
stack,
|
|
24
|
+
message,
|
|
25
|
+
url
|
|
26
|
+
]){
|
|
27
|
+
if (parseService(event, source)) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=enrich-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/enrich-event.ts"],"sourcesContent":["import type { RumEvent, RumEventDomainContext } from '@datadog/browser-rum';\n\nconst SERVICE_REGEX =\n /unpkg\\.servicetitan\\.com\\/@servicetitan\\/(?<service>[\\w-]+)(?:@(?<version>\\d+\\.\\d+\\.\\d+(?:-[\\w.]+)?))?/;\n\nfunction parseService(event: RumEvent, input: string | undefined) {\n const match = input?.match(SERVICE_REGEX);\n\n const service = match?.groups?.service;\n const version = match?.groups?.version;\n\n if (service) {\n event.service = service;\n event.version = version ?? 'unknown';\n return true;\n }\n\n return false;\n}\n\n/**\n * See https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#micro-frontend\n */\nexport function enrichEvent(event: RumEvent, context: RumEventDomainContext): void {\n const stack =\n (context && 'handlingStack' in context ? context.handlingStack : undefined) ??\n (event.type === 'error' ? event.error?.stack : undefined);\n\n const message = event.type === 'error' ? event.error?.message : undefined;\n\n const url = event.type === 'resource' ? event.resource?.url : undefined;\n\n for (const source of [stack, message, url]) {\n if (parseService(event, source)) {\n break;\n }\n }\n}\n"],"names":["SERVICE_REGEX","parseService","event","input","match","service","groups","version","enrichEvent","context","stack","handlingStack","undefined","type","error","message","url","resource","source"],"mappings":"AAEA,MAAMA,gBACF;AAEJ,SAASC,aAAaC,KAAe,EAAEC,KAAyB;QAG5CC,eACAA;IAHhB,MAAMA,QAAQD,kBAAAA,4BAAAA,MAAOC,KAAK,CAACJ;IAE3B,MAAMK,UAAUD,kBAAAA,6BAAAA,gBAAAA,MAAOE,MAAM,cAAbF,oCAAAA,cAAeC,OAAO;IACtC,MAAME,UAAUH,kBAAAA,6BAAAA,iBAAAA,MAAOE,MAAM,cAAbF,qCAAAA,eAAeG,OAAO;IAEtC,IAAIF,SAAS;QACTH,MAAMG,OAAO,GAAGA;QAChBH,MAAMK,OAAO,GAAGA,oBAAAA,qBAAAA,UAAW;QAC3B,OAAO;IACX;IAEA,OAAO;AACX;AAEA;;CAEC,GACD,OAAO,SAASC,YAAYN,KAAe,EAAEO,OAA8B;QAElEA;QACyBP,cAEWA,eAEDA;IANxC,MAAMQ,SACDD,OAAAA,WAAW,mBAAmBA,UAAUA,QAAQE,aAAa,GAAGC,uBAAhEH,kBAAAA,OACAP,MAAMW,IAAI,KAAK,WAAUX,eAAAA,MAAMY,KAAK,cAAXZ,mCAAAA,aAAaQ,KAAK,GAAGE;IAEnD,MAAMG,UAAUb,MAAMW,IAAI,KAAK,WAAUX,gBAAAA,MAAMY,KAAK,cAAXZ,oCAAAA,cAAaa,OAAO,GAAGH;IAEhE,MAAMI,MAAMd,MAAMW,IAAI,KAAK,cAAaX,kBAAAA,MAAMe,QAAQ,cAAdf,sCAAAA,gBAAgBc,GAAG,GAAGJ;IAE9D,KAAK,MAAMM,UAAU;QAACR;QAAOK;QAASC;KAAI,CAAE;QACxC,IAAIf,aAAaC,OAAOgB,SAAS;YAC7B;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SharedImpl } from './shared-impl';
|
|
2
|
+
export declare const STATE_KEY: unique symbol;
|
|
3
|
+
export interface GlobalSlot {
|
|
4
|
+
[STATE_KEY]?: SharedImpl;
|
|
5
|
+
}
|
|
6
|
+
/** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */
|
|
7
|
+
export declare function getOrCreateSharedImpl(): SharedImpl;
|
|
8
|
+
/** Returns the shared impl if it already exists, or `undefined`. */
|
|
9
|
+
export declare function getSharedImpl(): SharedImpl | undefined;
|
|
10
|
+
//# sourceMappingURL=get-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-shared.d.ts","sourceRoot":"","sources":["../src/get-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,SAAS,eAA0C,CAAC;AAEjE,MAAM,WAAW,UAAU;IACvB,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC;CAC5B;AAMD,2FAA2F;AAC3F,wBAAgB,qBAAqB,IAAI,UAAU,CAIlD;AAED,oEAAoE;AACpE,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createImpl } from './create-impl';
|
|
2
|
+
export const STATE_KEY = Symbol.for('@servicetitan/datadog-rum');
|
|
3
|
+
function slot() {
|
|
4
|
+
return globalThis;
|
|
5
|
+
}
|
|
6
|
+
/** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */ export function getOrCreateSharedImpl() {
|
|
7
|
+
var _s, _STATE_KEY, _;
|
|
8
|
+
const s = slot();
|
|
9
|
+
(_ = (_s = s)[_STATE_KEY = STATE_KEY]) !== null && _ !== void 0 ? _ : _s[_STATE_KEY] = createImpl();
|
|
10
|
+
return s[STATE_KEY];
|
|
11
|
+
}
|
|
12
|
+
/** Returns the shared impl if it already exists, or `undefined`. */ export function getSharedImpl() {
|
|
13
|
+
return slot()[STATE_KEY];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=get-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/get-shared.ts"],"sourcesContent":["import { createImpl } from './create-impl';\nimport type { SharedImpl } from './shared-impl';\n\nexport const STATE_KEY = Symbol.for('@servicetitan/datadog-rum');\n\nexport interface GlobalSlot {\n [STATE_KEY]?: SharedImpl;\n}\n\nfunction slot(): GlobalSlot {\n return globalThis as unknown as GlobalSlot;\n}\n\n/** Returns the shared impl, creating it if it doesn't exist yet. Only called by `init`. */\nexport function getOrCreateSharedImpl(): SharedImpl {\n const s = slot();\n s[STATE_KEY] ??= createImpl();\n return s[STATE_KEY];\n}\n\n/** Returns the shared impl if it already exists, or `undefined`. */\nexport function getSharedImpl(): SharedImpl | undefined {\n return slot()[STATE_KEY];\n}\n"],"names":["createImpl","STATE_KEY","Symbol","for","slot","globalThis","getOrCreateSharedImpl","s","getSharedImpl"],"mappings":"AAAA,SAASA,UAAU,QAAQ,gBAAgB;AAG3C,OAAO,MAAMC,YAAYC,OAAOC,GAAG,CAAC,6BAA6B;AAMjE,SAASC;IACL,OAAOC;AACX;AAEA,yFAAyF,GACzF,OAAO,SAASC;QAEZC,IAAEN,YAAFM;IADA,MAAMA,IAAIH;KACVG,IAAAA,CAAAA,KAAAA,EAAC,CAACN,aAAAA,UAAU,cAAZM,eAAAA,IAAAA,EAAC,CAACN,WAAU,GAAKD;IACjB,OAAOO,CAAC,CAACN,UAAU;AACvB;AAEA,kEAAkE,GAClE,OAAO,SAASO;IACZ,OAAOJ,MAAM,CAACH,UAAU;AAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-resource.d.ts","sourceRoot":"","sources":["../src/handle-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAM5F,wBAAgB,cAAc,CAC1B,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,6BAA6B,GACvC,IAAI,CAoBN"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function isSameDomainRequest(url) {
|
|
2
|
+
return new URL(url).hostname === window.location.hostname;
|
|
3
|
+
}
|
|
4
|
+
export function handleResource(event, context) {
|
|
5
|
+
if (!isSameDomainRequest(event.resource.url)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
let cfRay = undefined;
|
|
9
|
+
switch(event.resource.type){
|
|
10
|
+
case 'fetch':
|
|
11
|
+
var _context_response;
|
|
12
|
+
cfRay = (_context_response = context.response) === null || _context_response === void 0 ? void 0 : _context_response.headers.get('cf-ray');
|
|
13
|
+
break;
|
|
14
|
+
case 'xhr':
|
|
15
|
+
var _context_xhr;
|
|
16
|
+
cfRay = (_context_xhr = context.xhr) === null || _context_xhr === void 0 ? void 0 : _context_xhr.getResponseHeader('cf-ray');
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
if (cfRay) {
|
|
20
|
+
event.context = {
|
|
21
|
+
...event.context,
|
|
22
|
+
cfRay
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=handle-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handle-resource.ts"],"sourcesContent":["import type { RumResourceEvent, RumResourceEventDomainContext } from '@datadog/browser-rum';\n\nfunction isSameDomainRequest(url: string) {\n return new URL(url).hostname === window.location.hostname;\n}\n\nexport function handleResource(\n event: RumResourceEvent,\n context: RumResourceEventDomainContext\n): void {\n if (!isSameDomainRequest(event.resource.url)) {\n return;\n }\n\n let cfRay: string | undefined | null = undefined;\n\n switch (event.resource.type) {\n case 'fetch':\n cfRay = context.response?.headers.get('cf-ray');\n break;\n\n case 'xhr':\n cfRay = context.xhr?.getResponseHeader('cf-ray');\n break;\n }\n\n if (cfRay) {\n event.context = { ...event.context, cfRay };\n }\n}\n"],"names":["isSameDomainRequest","url","URL","hostname","window","location","handleResource","event","context","resource","cfRay","undefined","type","response","headers","get","xhr","getResponseHeader"],"mappings":"AAEA,SAASA,oBAAoBC,GAAW;IACpC,OAAO,IAAIC,IAAID,KAAKE,QAAQ,KAAKC,OAAOC,QAAQ,CAACF,QAAQ;AAC7D;AAEA,OAAO,SAASG,eACZC,KAAuB,EACvBC,OAAsC;IAEtC,IAAI,CAACR,oBAAoBO,MAAME,QAAQ,CAACR,GAAG,GAAG;QAC1C;IACJ;IAEA,IAAIS,QAAmCC;IAEvC,OAAQJ,MAAME,QAAQ,CAACG,IAAI;QACvB,KAAK;gBACOJ;YAARE,SAAQF,oBAAAA,QAAQK,QAAQ,cAAhBL,wCAAAA,kBAAkBM,OAAO,CAACC,GAAG,CAAC;YACtC;QAEJ,KAAK;gBACOP;YAARE,SAAQF,eAAAA,QAAQQ,GAAG,cAAXR,mCAAAA,aAAaS,iBAAiB,CAAC;YACvC;IACR;IAEA,IAAIP,OAAO;QACPH,MAAMC,OAAO,GAAG;YAAE,GAAGD,MAAMC,OAAO;YAAEE;QAAM;IAC9C;AACJ"}
|
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"}
|
|
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"}
|
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';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB"}
|
|
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"}
|