import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum'; import type { State } from './types'; const PROPAGATOR_TYPES: readonly PropagatorType[] = ['datadog', 'tracecontext', 'b3', 'b3multi']; /** * Mirrors `@datadog/browser-rum-core`'s tracing URL match semantics: * - strings are prefix-matched (SDK passes `useStartsWith=true` for tracing URLs) * * Per-call try/catch mirrors the SDK's `matchList`: a throwing user function or * malformed RegExp only loses its own match decision rather than breaking the * wrapper for every other matcher. */ function matchOption(opt: MatchOption, url: string): boolean { try { if (typeof opt === 'function') { return opt(url); } if (typeof opt === 'string') { return url.startsWith(opt); } return opt.test(url); } catch { return false; } } /** * Emits one dynamic wrapper per `PropagatorType`. Each wrapper's `match` walks * registered services and returns true if any matcher registered under that * propagator matches. Late-loading MFEs work fully dynamically. */ export function buildAllowedTracingUrls( state: State ): NonNullable { return PROPAGATOR_TYPES.map(pt => ({ match: (url: string) => { for (const entry of state.services.values()) { const matchers = entry.allowedTracingUrls?.[pt]; if (!matchers) { continue; } for (const m of matchers) { if (matchOption(m, url)) { return true; } } } return false; }, propagatorTypes: [pt], })); }