import { AsyncLocalStorage } from 'async_hooks'; import { GalileoLogger } from './utils/galileo-logger'; import type { StartSessionOptions } from './types/logging/logger.types'; import type { LocalMetricConfig } from './types/metrics.types'; import { StepWithChildSpans } from './types/logging/span.types'; /** * Context information that is automatically propagated through async execution chains. */ export interface ExperimentContext { /** (Optional) The project ID */ projectId?: string; /** (Optional) The experiment ID currently being executed */ experimentId?: string; /** (Optional) The project name for the current experiment */ projectName?: string; /** The parent stack for nested spans (trace, workflow, agent spans) */ parentStack?: StepWithChildSpans[]; /** The session ID for the current logger context */ sessionId?: string; /** The log stream name for the current logger context */ logStreamName?: string; } /** * AsyncLocalStorage instance for propagating experiment context through async execution chains. */ export declare const experimentContext: AsyncLocalStorage; /** * Logger context information that is automatically propagated through async execution chains. * This allows logger state (parent stack, session) to be available across async boundaries. */ export interface LoggerContext { /** The parent stack for nested spans (trace, workflow, agent spans) */ parentStack?: StepWithChildSpans[]; /** The session ID for the current logger context */ sessionId?: string; /** The log stream name for the current logger context */ logStreamName?: string; } /** * AsyncLocalStorage instance for propagating logger context through async execution chains. * This ensures that parent stack and session information are available across async boundaries. */ export declare const loggerContext: AsyncLocalStorage; /** * Options for identifying a logger by its key (project, logStreamName/experimentId, mode). */ export interface LoggerKeyOptions { /** (Optional) The project name */ projectName?: string; /** (Optional) The project ID */ projectId?: string; /** (Optional) The log stream name (used when experimentId is not provided) */ logStreamName?: string; /** (Optional) The experiment ID (takes precedence over logStreamName) */ experimentId?: string; /** (Optional) The logger mode (defaults to 'batch') */ mode?: string; } /** * Extends LoggerKeyOptions with localMetrics to configure new logger instances. */ export interface GetLoggerOptions extends LoggerKeyOptions { /** (Optional) Local metrics to run on traces/spans (only used when initializing a new logger) */ localMetrics?: LocalMetricConfig[]; } /** * A singleton class that manages a collection of GalileoLogger instances. */ export declare class GalileoSingleton { private static instance; private galileoLoggers; private lastAvailableLogger; private constructor(); /** * Gets the singleton instance of GalileoSingleton. * @returns The singleton instance */ static getInstance(): GalileoSingleton; /** * Returns the last available logger instance, or creates a new one if no logger is available. * @deprecated Use getLogger() method instead. This method is kept for backwards compatibility. * @returns An instance of GalileoLogger */ getClient(): GalileoLogger; /** * Generates a key string based on project, logStreamName/experimentId, and mode parameters. * @param projectName - (Optional) The project name * @param logStreamName - (Optional) The log stream name (used when experimentId is not provided) * @param experimentId - (Optional) The experiment ID (takes precedence over logStreamName) * @param mode - (Optional) The logger mode (defaults to "batch") * @returns A string key used for caching */ private static _getKey; /** * Retrieves an existing GalileoLogger or creates a new one if it does not exist. * @param options - Configuration options * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name (used when experimentId is not provided) * @param options.experimentId - (Optional) The experiment ID (takes precedence over logStreamName) * @param options.mode - (Optional) The logger mode (defaults to "batch") * @param options.localMetrics - (Optional) Local metrics to run on traces/spans (only used when initializing a new logger) * @returns An instance of GalileoLogger corresponding to the key */ getLogger(options?: GetLoggerOptions): GalileoLogger; /** * Retrieve a copy of the map containing all active loggers. * * @returns A map of keys to GalileoLogger instances */ getAllLoggers(): Map; /** * Removes a logger from internal tracking. Idempotent — only removes the * map entry / clears lastAvailableLogger if they still reference the given * logger, so it can be safely called from both the onTerminate hook and the * reset() backstop. */ private cleanupLogger; /** * Resets (terminates and removes) a GalileoLogger instance. * @param options - Configuration options to identify which logger to reset * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name * @param options.experimentId - (Optional) The experiment ID * @param options.mode - (Optional) The logger mode * @returns A promise that resolves when the logger is reset */ reset(options?: LoggerKeyOptions): Promise; /** * Resets (terminates and removes) all GalileoLogger instances. * @returns A promise that resolves when all loggers are reset */ resetAll(): Promise; /** * Flushes (uploads) a GalileoLogger instance. * @param options - Configuration options to identify which logger to flush * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name * @param options.experimentId - (Optional) The experiment ID * @param options.mode - (Optional) The logger mode * @returns A promise that resolves when the logger is flushed */ flush(options?: LoggerKeyOptions): Promise; /** * Flushes (uploads) all GalileoLogger instances. * @returns A promise that resolves when all loggers are flushed */ flushAll(): Promise; /** * Sets a client logger instance. * @deprecated Use getLogger() method instead. This maintains backward compatibility. * @param client - The GalileoLogger instance to set */ setClient(client: GalileoLogger): void; } /** * Gets or creates a logger and optionally initializes a session. * * Note: When startNewSession is true and an existing session is found via externalId, it is returned as-is. * All other session options (sessionName, previousSessionId, metadata) are ignored in that case - * they only apply when creating a new session. To update an existing session, use an explicit update method. * * @param options - Configuration options to initialize the logger * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name * @param options.experimentId - (Optional) The experiment ID * @param options.mode - (Optional) The logger mode * @param options.localMetrics - (Optional) Local metrics to run on traces/spans (only used when initializing a new logger) * @param options.sessionId - (Optional) The session ID * @param options.startNewSession - (Optional) Whether to start a new session * @param options.sessionName - (Optional) The name of the session. Only applied when creating a new session. * @param options.previousSessionId - (Optional) The ID of a previous session to link to. Creates a reference only; does not inherit metadata. Only applied when creating a new session. * @param options.externalId - (Optional) An external identifier for the session. If a session with this external ID already exists, it will be reused. * @param options.metadata - (Optional) User metadata for the session. Only applied when creating a new session. * @returns A promise that resolves when initialization is complete */ export declare const init: (options?: GetLoggerOptions & { sessionId?: string; startNewSession?: boolean; sessionName?: string; previousSessionId?: string; externalId?: string; metadata?: Record; }) => Promise; /** * Retrieves an existing GalileoLogger or creates a new one if it does not exist. * @param options - Configuration options * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name (used when experimentId is not provided) * @param options.experimentId - (Optional) The experiment ID (takes precedence over logStreamName) * @param options.mode - (Optional) The logger mode (defaults to "batch") * @param options.localMetrics - (Optional) Local metrics to run on traces/spans (only used when initializing a new logger) * @returns An instance of GalileoLogger corresponding to the key */ export declare const getLogger: (options?: GetLoggerOptions) => GalileoLogger; /** * Starts a new session on the logger for the current context. * * @param options - (Optional) Session options. * @param options.name - (Optional) The session name. * @param options.previousSessionId - (Optional) The previous session ID to link to. * @param options.externalId - (Optional) External ID for the session. * @param options.metadata - (Optional) User metadata for the session as key-value string pairs. Only applied when creating a new session. * @returns A promise that resolves to the session ID. */ export declare const startSession: (options?: StartSessionOptions) => Promise; /** * Sets the session ID on the logger for the current context. * Traces created via log() are associated with this session. * * @param sessionId - The session ID to set. * @returns Nothing. */ export declare const setSession: (sessionId: string) => void; /** * Clears the current session ID on the logger for the current context. * Subsequent traces are not associated with a session until startSession or setSession is called. * * @returns Nothing. */ export declare const clearSession: () => void; /** * Retrieves a shallow copy of the map containing all active loggers. * @returns A map of keys to GalileoLogger instances */ export declare const getAllLoggers: () => Map; /** * Resets (terminates and removes) a specific logger instance. * @param options - Configuration options to identify which logger to reset * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name * @param options.experimentId - (Optional) The experiment ID * @param options.mode - (Optional) The logger mode * @returns A promise that resolves when the logger is reset */ export declare const reset: (options?: LoggerKeyOptions) => Promise; /** * Resets (terminates and removes) all logger instances. * @returns A promise that resolves when all loggers are reset */ export declare const resetAll: () => Promise; /** * Flushes (uploads) traces from a specific logger to the Galileo platform. * @param options - Configuration options to identify which logger to flush * @param options.projectName - (Optional) The project name * @param options.logStreamName - (Optional) The log stream name * @param options.experimentId - (Optional) The experiment ID * @param options.mode - (Optional) The logger mode * @returns A promise that resolves when the logger is flushed */ export declare const flush: (options?: LoggerKeyOptions) => Promise; /** * Flushes (uploads) all captured traces to the Galileo platform. * @returns A promise that resolves when all loggers are flushed */ export declare const flushAll: () => Promise; /** * Lifecycle and context API for Galileo logging. * Groups init, flush, reset, and session methods for ergonomic use. */ export declare const galileoContext: { init: (options?: GetLoggerOptions & { sessionId?: string; startNewSession?: boolean; sessionName?: string; previousSessionId?: string; externalId?: string; metadata?: Record; }) => Promise; flush: (options?: LoggerKeyOptions) => Promise; flushAll: () => Promise; reset: (options?: LoggerKeyOptions) => Promise; resetAll: () => Promise; startSession: (options?: StartSessionOptions) => Promise; setSession: (sessionId: string) => void; clearSession: () => void; };