import { Tracer, Meter } from '@opentelemetry/api'; import { Logger } from '@opentelemetry/api-logs'; /** * OpenTelemetry configuration module * * Provides environment-based configuration for OTLP exporters. * * @module config */ /** * Available exporter types * * - CONSOLE: Outputs telemetry to stdout * - OTLP_HTTP: Sends telemetry via OTLP/HTTP protocol * - OTLP_GRPC: Sends telemetry via OTLP/gRPC protocol * - NONE: Disables telemetry export */ declare const ExporterType: { readonly CONSOLE: "console"; readonly OTLP_HTTP: "otlp/http"; readonly OTLP_GRPC: "otlp/grpc"; readonly NONE: "none"; }; type ExporterType = (typeof ExporterType)[keyof typeof ExporterType]; /** * OTLP settings for traces, metrics, and logs */ interface OTLPSettings { traces: ExporterType; metrics: ExporterType; logs: ExporterType; } /** * Collector endpoint options */ interface CollectorOptions { concurrencyLimit: number; url: string | undefined; } /** * Batch span processor options */ interface BatchSpanProcessorOptions { maxExportBatchSize: number; maxQueueSize: number; scheduledDelayMillis: number; exportTimeoutMillis: number; } /** * Gets OTLP exporter settings from environment variables * * Environment variables: * - OTEL_TRACES_EXPORTER: Trace exporter type (console|otlp/http|otlp/grpc|none) * - OTEL_METRICS_EXPORTER: Metric exporter type (console|otlp/http|otlp/grpc|none) * - OTEL_LOGS_EXPORTER: Logs exporter type (console|otlp/http|otlp/grpc|none) * * @returns OTLP settings object */ declare function getOTLPSettings(): OTLPSettings; /** * Gets collector endpoint options from environment variables * * Environment variables: * - OTEL_EXPORTER_OTLP_ENDPOINT: Collector endpoint URL * * @returns Collector options object */ declare function getCollectorOptions(): CollectorOptions; /** * Gets batch span processor options from environment variables * * Environment variables: * - OTEL_BSP_MAX_EXPORT_BATCH_SIZE: Max number of spans to export in a single batch (default: 100) * - OTEL_BSP_MAX_QUEUE_SIZE: Max queue size - if reached, new spans are dropped (default: 1000) * - OTEL_BSP_SCHEDULE_DELAY: Time to wait before automatically exporting spans in ms (default: 1000) * - OTEL_BSP_EXPORT_TIMEOUT: Max time allowed for a single export operation in ms (default: 10000) * * @returns Batch span processor options */ declare function getBatchSpanProcessorOptions(): BatchSpanProcessorOptions; /** * Gets service metadata from environment variables * * Uses OTEL_SERVICE_NAME as primary source, falls back to npm_package_name. * * @returns Service name and version */ declare function getServiceMetadata(): { name: string; version: string; }; /** * OpenTelemetry Provider * * Manages OpenTelemetry providers for traces, metrics, and logs. * Replaces the previous OTLPProvider singleton with explicit lifecycle control. * * @module provider */ /** * Options for initializing the OpenTelemetry provider */ interface ProviderOptions { /** Override service name (defaults to OTEL_SERVICE_NAME or npm_package_name) */ serviceName?: string; /** Override service version (defaults to npm_package_version) */ serviceVersion?: string; /** * Sets `service.instance.id` on the resource (OTel semconv). Lets a fleet of * same-role processes be told apart in telemetry. Takes precedence over the * `OTEL_SERVICE_INSTANCE_ID` env var. */ instanceId?: string; /** * Extra resource attributes merged into the resource (e.g. `device.id`, * `facility`). Applied to traces, metrics, and logs alike. Takes precedence * over attributes parsed from the `OTEL_RESOURCE_ATTRIBUTES` env var. */ resourceAttributes?: Record; /** Override OTLP exporter settings (defaults to env-based config) */ settings?: Partial; } /** * Parse the standard `OTEL_RESOURCE_ATTRIBUTES` env var * (`key1=value1,key2=value2`) into an attribute record. Malformed pairs (no * `=`, empty key) are skipped. Values are kept as strings; whitespace around * keys and values is trimmed. */ declare function parseOtelResourceAttributesEnv(raw: string | undefined): Record; /** Inputs for {@link buildResourceAttributes}. */ interface ResourceAttributeInputs { serviceName: string; serviceVersion: string; instanceId?: string | undefined; resourceAttributes?: Record | undefined; /** Environment source (defaults to `process.env`). */ env?: { OTEL_RESOURCE_ATTRIBUTES?: string; OTEL_SERVICE_INSTANCE_ID?: string; } | undefined; } /** * Build the flat resource-attribute record shared by traces, metrics, and logs. * * Precedence (lowest to highest): `service.name`/`service.version` → env * (`OTEL_RESOURCE_ATTRIBUTES`, `OTEL_SERVICE_INSTANCE_ID`) → explicit * `resourceAttributes` → explicit `instanceId`. */ declare function buildResourceAttributes(inputs: ResourceAttributeInputs): Record; /** * OpenTelemetry Provider * * Manages OTLP exporters for traces, metrics, and logs. * Supports console, OTLP/HTTP, OTLP/gRPC exporters, and no-op mode * based on environment configuration or explicit options. */ declare class OtelProvider { readonly tracer: Tracer; readonly meter: Meter; readonly logger: Logger; private traceProvider?; private meterProvider?; private loggerProvider?; private readonly settings; private readonly collectorOptions; private readonly serviceName; private readonly serviceVersion; private readonly resource; constructor(options?: ProviderOptions); /** * Build the OpenTelemetry resource from service metadata, environment * variables, and explicit options. See {@link buildResourceAttributes} for * the precedence rules. */ private buildResource; /** * Create and configure tracer provider * * @returns Tracer instance */ private createTracer; /** * Create and configure meter provider * * @returns Meter instance */ private createMeter; /** * Create and configure logger provider * * @returns Logger instance */ private createLogger; /** * Gracefully shutdown all OTLP providers * * @returns Promise that resolves when shutdown is complete */ shutdown(): Promise; } /** * Initialize the OpenTelemetry provider with explicit options. * * Optional -- {@link getProvider}, {@link getMeter}, {@link getTracer}, * and {@link getLogger} auto-initialize with environment-based defaults. * Idempotent: subsequent calls are no-ops if provider is already active. * Call {@link shutdownProvider} first to re-initialize with new options. * * @param options - Optional provider configuration overrides */ declare function initProvider(options?: ProviderOptions): void; /** * Get the current OpenTelemetry provider. * * If not yet initialized, lazily creates a provider with default * (environment-based) options. * * @returns The active OtelProvider instance */ declare function getProvider(): OtelProvider; /** * Gracefully shutdown the provider and release resources. * * After shutdown, subsequent calls to {@link getProvider} will create * a fresh provider. If no provider exists, this is a no-op. */ declare function shutdownProvider(): Promise; export { type BatchSpanProcessorOptions as B, type CollectorOptions as C, ExporterType as E, type OTLPSettings as O, type ProviderOptions as P, type ResourceAttributeInputs as R, getCollectorOptions as a, getOTLPSettings as b, getProvider as c, getServiceMetadata as d, buildResourceAttributes as e, getBatchSpanProcessorOptions as g, initProvider as i, parseOtelResourceAttributesEnv as p, shutdownProvider as s };