import type { Context } from '@datadog/browser-core'; import type { MatchOption, PropagatorType, RumInitConfiguration } from '@datadog/browser-rum'; import type { ApplicationBeforeSendHandler, ServiceBeforeSendHandler } from './before-send'; /** * URL matchers grouped by the propagator type whose headers they should * activate. A service registers its tracing URLs as e.g. * `{ tracecontext: [/api\//, 'https://...'] }`. */ export type ServiceTracingUrls = Partial>; /** Tears down a service registration: handlers, tracing URLs, and persistent context. */ export type Cleanup = () => void; /** * Service handle returned by `useRumService`. `setServiceContext` is bound to the * service registered by the hook, so callers don't pass the service name again. */ export interface RumService { setServiceContext: (context: Context) => void; } /** Imperative service registration returned by `init`. Adds the cleanup contract. */ export interface RumServiceRegistration extends RumService { cleanup: Cleanup; } export type ApplicationConfig = Omit< RumInitConfiguration, 'beforeSend' | 'allowedTracingUrls' | 'service' > & { beforeSend?: ApplicationBeforeSendHandler; }; interface ServiceShape { beforeSend?: ServiceBeforeSendHandler; allowedTracingUrls?: ServiceTracingUrls; } export interface ServiceConfig extends ServiceShape { name: string; } export interface InitRumOptions { service: ServiceConfig; application?: ApplicationConfig; enabled?: boolean; } /** * Per-service entry — `beforeSend` and `allowedTracingUrls` come from * `init`; `context` comes from `setServiceContext`. One service = one entry. */ export interface ServiceEntry extends ServiceShape { context?: Context; } /** Registration state: application-level handler + per-service entries keyed by service name. */ export interface State { applicationBeforeSend?: ApplicationBeforeSendHandler; services: Map; }