{"version":3,"sources":["../src/observability-sdk/features/data-capture/utils.ts","../src/observability-sdk/config.ts"],"sourcesContent":["import { type DataCaptureMode } from \"./types\";\n\n/**\n * Validates a data capture mode.\n */\nexport function validateDataCaptureMode(mode: DataCaptureMode): boolean {\n  return [\"none\", \"input\", \"output\", \"all\"].includes(mode);\n}\n","import { type Logger, NoOpLogger } from \"../logger/index.js\";\nimport {\n  type DataCaptureMode,\n  type DataCaptureOptions,\n} from \"./features/data-capture/types.js\";\nimport { validateDataCaptureMode } from \"./features/data-capture/utils.js\";\n\n/**\n * @module observability/config\n * @description\n * Provides configuration management for the LangWatch Observability SDK, including logger and data capture settings.\n *\n * @remarks\n * This module allows you to initialize, retrieve, and reset the global observability configuration. It also provides utilities for determining data capture behavior based on context and configuration.\n *\n * @see {@link ObservabilityConfig}\n * @see {@link initializeObservabilitySdkConfig}\n * @see {@link getObservabilitySdkConfig}\n * @see {@link resetObservabilitySdkConfig}\n * @see {@link getDataCaptureMode}\n * @see {@link shouldCaptureInput}\n * @see {@link shouldCaptureOutput}\n */\n/**\n * Configuration options for the LangWatch Observability SDK.\n *\n * @property logger - The logger instance to use for SDK logging.\n * @property dataCapture - Configuration for automatic data capture. Can be a string, function, or object.\n *\n * @example\n * ```ts\n * import { ObservabilityConfig, initializeObservabilitySdkConfig } from \"@langwatch/observability\";\n *\n * const config: ObservabilityConfig = {\n *   logger: new ConsoleLogger(),\n *   dataCapture: \"all\",\n * };\n *\n * initializeObservabilitySdkConfig(config);\n * ```\n */\nexport interface ObservabilityConfig {\n  /**\n   * The logger to use for the observability SDK.\n   *\n   * @default NoOpLogger\n   */\n  logger: Logger;\n\n  /**\n   * Configuration for automatic data capture.\n   *\n   * @default \"all\"\n   */\n  dataCapture?: DataCaptureOptions;\n}\n\n/**\n * The observability SDK config.\n */\nlet observabilitySdkConfig: ObservabilityConfig | null = null;\n\n/**\n * Initializes the global observability SDK configuration.\n *\n * @param config - The configuration object to use.\n *\n * @remarks\n * This function should be called once at application startup, before using any observability features.\n *\n * @warning\n * Calling this function will intentionally overwrite any existing configuration. This is by design to allow re-initialization in dynamic or testing environments. If you call this function multiple times, the most recent configuration will take effect.\n *\n * @example\n * ```ts\n * initializeObservabilitySdkConfig({ logger: new ConsoleLogger() });\n * ```\n */\nexport function initializeObservabilitySdkConfig(config: ObservabilityConfig) {\n  observabilitySdkConfig = config;\n}\n\n/**\n * Resets the global observability SDK configuration to its initial state (`null`).\n *\n * @remarks\n * Useful for testing or re-initializing the SDK in dynamic environments.\n *\n * @example\n * ```ts\n * resetObservabilitySdkConfig();\n * ```\n */\nexport function resetObservabilitySdkConfig() {\n  observabilitySdkConfig = null;\n}\n\n/**\n * Retrieves the current observability SDK configuration.\n *\n * @param options - Optional settings.\n * @param options.throwOnUninitialized - If true, throws an error if the config is not initialized. Defaults to `false` unless `NODE_ENV` is `development`.\n * @returns The current {@link ObservabilityConfig}.\n *\n * @throws {Error} If the config is uninitialized and `throwOnUninitialized` is true or in development mode.\n *\n * @example\n * ```ts\n * const config = getObservabilitySdkConfig();\n * ```\n */\nexport function getObservabilitySdkConfig(options?: {\n  throwOnUninitialized?: boolean;\n}): ObservabilityConfig {\n  if (!observabilitySdkConfig) {\n    const message =\n      \"[LangWatch Observability SDK] Please call setupObservability() before using the Observability SDK\";\n\n    if (\n      options?.throwOnUninitialized ||\n      process.env.NODE_ENV === \"development\"\n    ) {\n      throw new Error(message);\n    }\n\n    // Use a default logger that can be configured\n    return {\n      logger: new NoOpLogger(),\n    };\n  }\n  return observabilitySdkConfig;\n}\n\n/**\n * Gets the logger instance from the current observability SDK configuration.\n *\n * @returns The configured {@link Logger} instance.\n *\n * @example\n * ```ts\n * const logger = getObservabilitySdkLogger();\n * logger.info(\"Observability initialized\");\n * ```\n */\nexport function getObservabilitySdkLogger(): Logger {\n  return getObservabilitySdkConfig().logger;\n}\n\n/**\n * Determines the effective data capture mode.\n *\n * @returns The resolved {@link DataCaptureMode} (\"all\", \"input\", or \"output\").\n *\n * @remarks\n * The mode is determined by the configuration, which can be a string, function, or object. Defaults to \"all\" if not specified.\n *\n * @example\n * ```ts\n * const mode = getDataCaptureMode();\n * ```\n */\nexport function getDataCaptureMode(): DataCaptureMode {\n  const config = getObservabilitySdkConfig();\n\n  if (!config.dataCapture) {\n    return \"all\"; // Default: capture both input and output\n  }\n\n  // Handle different config formats\n  if (typeof config.dataCapture === \"string\") {\n    const validModes: DataCaptureMode[] = [\"none\", \"input\", \"output\", \"all\"];\n    if (validModes.includes(config.dataCapture)) {\n      return config.dataCapture;\n    }\n\n\n    getObservabilitySdkLogger().warn(\n      `Invalid data capture mode: ${config.dataCapture}. Using default: \"all\"`,\n    );\n\n    return \"all\";\n  }\n\n  if (typeof config.dataCapture === \"object\" && config.dataCapture.mode &&validateDataCaptureMode(config.dataCapture.mode)) {\n    return config.dataCapture.mode;\n  }\n\n  return \"all\"; // Default fallback\n}\n\n/**\n * Determines if input data should be captured.\n *\n * @returns `true` if input should be captured, otherwise `false`.\n *\n * @example\n * ```ts\n * if (shouldCaptureInput()) {\n *   // Capture input\n * }\n * ```\n */\nexport function shouldCaptureInput(): boolean {\n  const mode = getDataCaptureMode();\n  return mode === \"input\" || mode === \"all\";\n}\n\n/**\n * Determines if output data should be captured.\n *\n * @returns `true` if output should be captured, otherwise `false`.\n *\n * @example\n * ```ts\n * if (shouldCaptureOutput()) {\n *   // Capture output\n * }\n * ```\n */\nexport function shouldCaptureOutput(): boolean {\n  const mode = getDataCaptureMode();\n  return mode === \"output\" || mode === \"all\";\n}\n"],"mappings":";;;;;AAKO,SAAS,wBAAwB,MAAgC;AACtE,SAAO,CAAC,QAAQ,SAAS,UAAU,KAAK,EAAE,SAAS,IAAI;AACzD;;;ACqDA,IAAI,yBAAqD;AAkBlD,SAAS,iCAAiC,QAA6B;AAC5E,2BAAyB;AAC3B;AA+BO,SAAS,0BAA0B,SAElB;AACtB,MAAI,CAAC,wBAAwB;AAC3B,UAAM,UACJ;AAEF,SACE,mCAAS,yBACT,QAAQ,IAAI,aAAa,eACzB;AACA,YAAM,IAAI,MAAM,OAAO;AAAA,IACzB;AAGA,WAAO;AAAA,MACL,QAAQ,IAAI,WAAW;AAAA,IACzB;AAAA,EACF;AACA,SAAO;AACT;AAaO,SAAS,4BAAoC;AAClD,SAAO,0BAA0B,EAAE;AACrC;AAeO,SAAS,qBAAsC;AACpD,QAAM,SAAS,0BAA0B;AAEzC,MAAI,CAAC,OAAO,aAAa;AACvB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,OAAO,gBAAgB,UAAU;AAC1C,UAAM,aAAgC,CAAC,QAAQ,SAAS,UAAU,KAAK;AACvE,QAAI,WAAW,SAAS,OAAO,WAAW,GAAG;AAC3C,aAAO,OAAO;AAAA,IAChB;AAGA,8BAA0B,EAAE;AAAA,MAC1B,8BAA8B,OAAO,WAAW;AAAA,IAClD;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,OAAO,gBAAgB,YAAY,OAAO,YAAY,QAAO,wBAAwB,OAAO,YAAY,IAAI,GAAG;AACxH,WAAO,OAAO,YAAY;AAAA,EAC5B;AAEA,SAAO;AACT;AAcO,SAAS,qBAA8B;AAC5C,QAAM,OAAO,mBAAmB;AAChC,SAAO,SAAS,WAAW,SAAS;AACtC;AAcO,SAAS,sBAA+B;AAC7C,QAAM,OAAO,mBAAmB;AAChC,SAAO,SAAS,YAAY,SAAS;AACvC;","names":[]}