UNPKG

@datadog/browser-logs

Version:
64 lines 3.77 kB
import { sendToExtension, createPageMayExitObservable, willSyntheticsInjectRum, canUseEventBridge, startAccountContext, startGlobalContext, startUserContext, } from '@datadog/browser-core'; import { startLogsSessionManager, startLogsSessionManagerStub } from '../domain/logsSessionManager'; import { startLogsAssembly } from '../domain/assembly'; import { startConsoleCollection } from '../domain/console/consoleCollection'; import { startReportCollection } from '../domain/report/reportCollection'; import { startNetworkErrorCollection } from '../domain/networkError/networkErrorCollection'; import { startRuntimeErrorCollection } from '../domain/runtimeError/runtimeErrorCollection'; import { LifeCycle } from '../domain/lifeCycle'; import { startLoggerCollection } from '../domain/logger/loggerCollection'; import { startLogsBatch } from '../transport/startLogsBatch'; import { startLogsBridge } from '../transport/startLogsBridge'; import { startInternalContext } from '../domain/contexts/internalContext'; import { startReportError } from '../domain/reportError'; import { startRUMInternalContext } from '../domain/contexts/rumInternalContext'; import { startSessionContext } from '../domain/contexts/sessionContext'; import { startTrackingConsentContext } from '../domain/contexts/trackingConsentContext'; const LOGS_STORAGE_KEY = 'logs'; export function startLogs(configuration, getCommonContext, // `startLogs` and its subcomponents assume tracking consent is granted initially and starts // collecting logs unconditionally. As such, `startLogs` should be called with a // `trackingConsentState` set to "granted". trackingConsentState, bufferedDataObservable, hooks) { const lifeCycle = new LifeCycle(); const cleanupTasks = []; lifeCycle.subscribe(1 /* LifeCycleEventType.LOG_COLLECTED */, (log) => sendToExtension('logs', log)); const reportError = startReportError(lifeCycle); const pageMayExitObservable = createPageMayExitObservable(configuration); const session = configuration.sessionStoreStrategyType && !canUseEventBridge() && !willSyntheticsInjectRum() ? startLogsSessionManager(configuration, trackingConsentState) : startLogsSessionManagerStub(configuration); startTrackingConsentContext(hooks, trackingConsentState); // Start user and account context first to allow overrides from global context startSessionContext(hooks, configuration, session); const accountContext = startAccountContext(hooks, configuration, LOGS_STORAGE_KEY); const userContext = startUserContext(hooks, configuration, session, LOGS_STORAGE_KEY); const globalContext = startGlobalContext(hooks, configuration, LOGS_STORAGE_KEY, false); startRUMInternalContext(hooks); startNetworkErrorCollection(configuration, lifeCycle); startRuntimeErrorCollection(configuration, lifeCycle, bufferedDataObservable); bufferedDataObservable.unbuffer(); startConsoleCollection(configuration, lifeCycle); startReportCollection(configuration, lifeCycle); const { handleLog } = startLoggerCollection(lifeCycle); startLogsAssembly(configuration, lifeCycle, hooks, getCommonContext, reportError); if (!canUseEventBridge()) { const { stop: stopLogsBatch } = startLogsBatch(configuration, lifeCycle, reportError, pageMayExitObservable, session); cleanupTasks.push(() => stopLogsBatch()); } else { startLogsBridge(lifeCycle); } const internalContext = startInternalContext(session); return { handleLog, getInternalContext: internalContext.get, accountContext, globalContext, userContext, stop: () => { cleanupTasks.forEach((task) => task()); }, }; } //# sourceMappingURL=startLogs.js.map