import { bundleState } from './bundle-state'; import { getOrCreateSharedImpl } from './get-shared'; import type { InitRumOptions, RumServiceRegistration } from './types'; export type { ApplicationConfig, Cleanup, InitRumOptions, RumService, RumServiceRegistration, ServiceConfig, ServiceTracingUrls, } from './types'; /** * Registers a service and, optionally, initializes the Datadog RUM SDK. * * Any caller may pass `application`. The first call that includes it * initializes the SDK; subsequent callers' `application` config is ignored * with a warning. Callers that omit `application` register their service * without attempting SDK init. * * Returns a `RumServiceRegistration` — `{ cleanup, setServiceContext }`. * `cleanup` removes this service's `beforeSend`, `allowedTracingUrls`, and * persistent context. `setServiceContext` attaches session-lifetime metadata * to every event whose `event.service` matches this service's name. */ export function init(opts: InitRumOptions): RumServiceRegistration { const impl = getOrCreateSharedImpl(); const result = impl.init(opts); if (result.initializedSdk) { bundleState.isSdkInitializer = true; } const { name } = opts.service; return { cleanup: result.cleanup, setServiceContext: context => impl.setServiceContext(name, context), }; }