import { Context, Span, Tracer } from "@opentelemetry/api"; import { IdGenerator, RandomIdGenerator, ReadableSpan, Span as Span$1, SpanProcessor } from "@opentelemetry/sdk-trace-base"; //#region src/AttributeScrubber.d.ts type JsonPath = (number | string)[]; interface ScrubbedNote { matched_substring: string; path: JsonPath; } interface ScrubMatch { path: JsonPath; patternMatch: RegExpMatchArray; value: unknown; } type ScrubCallback = (match: ScrubMatch) => unknown; /** * Interface for attribute scrubbers that can process values and potentially * redact sensitive information. */ interface AttributeScrubber { /** * Scrubs a value recursively. * @param path The JSON path to this value. * @param value The value to scrub. * @returns A tuple: [scrubbedValue, scrubbedNotes] */ scrubValue(path: JsonPath, value: unknown): readonly [unknown, ScrubbedNote[]]; } /** * Base interface for attribute scrubbers with safe keys */ interface BaseScrubber extends AttributeScrubber { /** * List of keys that are considered safe and do not need scrubbing */ SAFE_KEYS: string[]; /** * Scrubs a value recursively. * @param path The JSON path to this value. * @param value The value to scrub. * @returns A tuple: [scrubbedValue, scrubbedNotes] */ scrubValue(path: JsonPath, value: T): readonly [T, ScrubbedNote[]]; } declare class LogfireAttributeScrubber implements BaseScrubber { /** * List of keys that are considered safe and don't need scrubbing */ SAFE_KEYS: string[]; private readonly callback?; private readonly pattern; constructor(patterns?: string[], callback?: ScrubCallback); /** * Scrubs a value recursively using default patterns. * @param path The JSON path to this value. * @param value The value to scrub. * @returns A tuple: [scrubbedValue, scrubbedNotes] */ scrubValue(path: JsonPath, value: T): readonly [T, ScrubbedNote[]]; private redact; private scrub; } /** * A no-op attribute scrubber that returns values unchanged. * Useful when you want to disable scrubbing entirely. */ declare class NoopAttributeScrubber implements BaseScrubber { /** * List of keys that are considered safe and don't need scrubbing */ SAFE_KEYS: string[]; /** * Returns the value unchanged with no scrubbing notes. * @param path The JSON path to this value. * @param value The value to return unchanged. * @returns A tuple: [originalValue, emptyNotes] */ scrubValue(_path: JsonPath, value: T): readonly [T, ScrubbedNote[]]; } /** * A singleton instance of NoopAttributeScrubber for convenience */ declare const NoopScrubber: NoopAttributeScrubber; //#endregion //#region src/fingerprint.d.ts /** * Creates a canonical string representation of an error for fingerprinting. * * The canonical format is designed for stability: * - Uses error type (constructor name) * - Uses function names from stack frames * - Deduplicates repeated frames (handles recursion) * - Includes error.cause chain * - Handles AggregateError by sorting and including all errors * * Line numbers are intentionally excluded since they change frequently * when code is edited, but the same logical error should produce the * same fingerprint. */ declare function canonicalizeError(error: Error, seen?: WeakSet): string; /** * Computes a fingerprint for an error that can be used to group * similar errors into issues. * * The fingerprint is a MurmurHash3 128-bit hash of the canonicalized error representation. * Errors with the same stack trace structure (ignoring line numbers) will * produce the same fingerprint. */ declare function computeFingerprint(error: Error): string; //#endregion //#region src/levels.d.ts declare const Level: { Trace: 1; Debug: 5; Info: 9; Notice: 10; Warning: 13; Error: 17; Fatal: 21; }; type LogFireLevel = (typeof Level)[keyof typeof Level]; declare const LEVEL_NAMES: readonly ["trace", "debug", "info", "notice", "warning", "error", "fatal"]; type LevelName = (typeof LEVEL_NAMES)[number]; type MinLevel = LogFireLevel | LevelName; //#endregion //#region src/serializeAttributes.d.ts type AttributeValue = boolean | number | string | string[]; type RawAttributes = Record; type SerializedAttributes = Record; declare function serializeAttributes(attributes: RawAttributes): SerializedAttributes; //#endregion //#region src/logfireApiConfig.d.ts interface ScrubbingOptions { callback?: ScrubCallback; extraPatterns?: string[]; } interface BaggageOptions { /** * Active OpenTelemetry baggage keys to copy to Logfire spans/logs. * * Keys are emitted as attributes prefixed with `baggage.`. * Defaults to []. */ spanAttributes?: readonly string[]; } type JsonSchemaMode = "rich" | "basic" | false; interface LogfireApiConfigOptions { baggage?: BaggageOptions; /** * Whether to compute fingerprints for errors reported via reportError(). * Fingerprints enable error grouping in the Logfire backend. * Defaults to true for Node.js, false for browser (minified code produces unstable fingerprints). */ errorFingerprinting?: boolean; /** * Controls JSON schema metadata for serialized object/array attributes. * * - 'rich' infers bounded nested schema metadata. * - 'basic' preserves the legacy broad top-level object/array schema metadata. * - false omits logfire.json_schema metadata. * * This does not change how attribute values are serialized. * Defaults to 'rich'. */ jsonSchema?: JsonSchemaMode; minLevel?: MinLevel | null; otelScope?: string; /** * Options for scrubbing sensitive data. Set to False to disable. */ scrubbing?: false | ScrubbingOptions; } interface ResolvedBaggageOptions { spanAttributes: readonly string[]; } type SendToLogfire = "if-token-present" | boolean | undefined; type Env = Record; interface LogfireApiConfig { baggage: ResolvedBaggageOptions; context: Context; enableErrorFingerprinting: boolean; jsonSchema: JsonSchemaMode; minLevel: LogFireLevel | undefined; otelScope: string; scrubber: BaseScrubber; tracer: Tracer; } declare const logfireApiConfig: LogfireApiConfig; declare function configureLogfireApi(config: LogfireApiConfigOptions): void; declare function resolveSendToLogfire(env: Env, option: SendToLogfire, token: string | undefined): boolean; declare function resolveBaseUrl(env: Env, passedUrl: string | undefined, token: string): string; //#endregion //#region src/PendingSpanProcessor.d.ts interface PendingSpanProcessorOptions { idGenerator?: IdGenerator; } declare class PendingSpanProcessor implements SpanProcessor { private readonly idGenerator; private readonly wrapped; constructor(wrapped: SpanProcessor, options?: PendingSpanProcessorOptions); forceFlush(): Promise; onEnd(_span: ReadableSpan): void; onStart(span: Span$1, parentContext: Context): void; shutdown(): Promise; } //#endregion //#region src/sampling.d.ts declare class SpanLevel { readonly number: number; get name(): LevelName | undefined; constructor(number: number); static fromSpan(span: ReadableSpan): SpanLevel; gt(level: LevelName): boolean; gte(level: LevelName): boolean; lt(level: LevelName): boolean; lte(level: LevelName): boolean; } interface TailSamplingSpanInfo { context: Context | null; duration: number; event: "end" | "start"; level: SpanLevel; span: ReadableSpan; } interface SamplingOptions { /** Head sampling rate (0.0-1.0). Default: 1.0 (sample everything). */ head?: number; /** Tail sampling callback. Return 0.0-1.0 probability for the entire trace. */ tail?: (spanInfo: TailSamplingSpanInfo) => number; } /** * Deterministic sampling decision based on trace ID, matching OTel JS's * TraceIdRatioBasedSampler algorithm. XOR-accumulates 8-char hex chunks * of the trace ID and compares against the threshold. */ declare function checkTraceIdRatio(traceId: string, rate: number): boolean; /** * Convenience factory for the common sampling pattern: keep traces that contain * spans with high severity levels or that exceed a duration threshold. */ declare function levelOrDuration(options?: { backgroundRate?: number; durationThreshold?: number; head?: number; levelThreshold?: LevelName; }): SamplingOptions; //#endregion //#region src/TailSamplingProcessor.d.ts type TailCallback = (spanInfo: TailSamplingSpanInfo) => number; interface TailSamplingProcessorOptions { deferredProcessor?: SpanProcessor; } declare class TailSamplingProcessor implements SpanProcessor { private readonly buffers; private readonly deferredProcessor; private readonly tail; private readonly wrapped; constructor(wrapped: SpanProcessor, tail: TailCallback, options?: TailSamplingProcessorOptions); forceFlush(): Promise; onEnd(span: ReadableSpan): void; onStart(span: Span$1, parentContext: Context): void; shutdown(): Promise; private addStart; private checkSpan; private flushBuffer; } //#endregion //#region src/ULIDGenerator.d.ts declare class ULIDGenerator extends RandomIdGenerator { override generateTraceId: () => string; } //#endregion //#region src/constants.d.ts declare const ATTRIBUTES_PENDING_SPAN_REAL_PARENT_KEY: "logfire.pending_parent_id"; //#endregion //#region src/index.d.ts interface LogOptions { /** * Override the OTel span name without changing the message template stored on * `logfire.msg_template`. Used by integrations (e.g. evals) that want a stable, * un-interpolated span name for query/saved-view consistency while still * presenting a friendly templated message in the UI. * * @internal */ _spanName?: string; /** * The log level for the span. * Defaults to Level.Info. */ level?: LogFireLevel; /** * Set to true to indicate that this span is a log. logs don't have child spans. */ log?: true; /** * Set a span started with `startSpan` as parentSpan to create a child span. */ parentSpan?: Span; /** * Tags to add to the span. */ tags?: string[]; } type StartPendingSpanOptions = Omit; interface LogfireClientSettings { level?: LogFireLevel; tags?: string[]; } interface ReportErrorOptions { /** * Set a span started with `startSpan` as parentSpan to create a child error span. */ parentSpan?: Span; /** * Tags to add to the error span. */ tags?: string[]; } interface InstrumentOptions { /** * Static attributes to add to each instrumented call span. */ attributes?: Record; /** * Extract positional arguments into span attributes. * * Defaults to false. Pass a string array for stable names, or true for * best-effort parameter-name extraction from function source. */ extractArgs?: boolean | readonly string[]; /** * The log level for the instrumented call span. */ level?: LogFireLevel; /** * The message template for the instrumented call span. */ message?: string; /** * Set a span started with `startSpan` as parentSpan to create a child span. */ parentSpan?: Span; /** * Record successful return values as span attributes. */ recordReturn?: boolean; /** * Override the OTel span name without changing the message template. */ spanName?: string; /** * Tags to add to the instrumented call span. */ tags?: string[]; } type InstrumentableFunction = (...args: never[]) => unknown; declare function startSpan(msgTemplate: string, attributes?: Record, options?: LogOptions): Span; declare function startPendingSpan(msgTemplate: string, attributes?: Record, options?: StartPendingSpanOptions): Span; type SpanCallback = (activeSpan: Span) => R; type SpanArgsVariant2 = [{ _spanName?: string; attributes?: Record; callback: SpanCallback; level?: LogFireLevel; parentSpan?: Span; tags?: string[]; }]; /** * Starts a new Span and calls the given function passing it the * created span as first argument. * Additionally the new span gets set in context and this context is activated within the execution of the function. * The span will be ended automatically after the function call. */ declare function span(msgTemplate: string, options: SpanArgsVariant2[0]): R; declare function span(msgTemplate: string, attributes: Record, options: LogOptions, callback: (span: Span) => R): R; declare function log(message: string, attributes?: Record, options?: LogOptions): void; declare function debug(message: string, attributes?: Record, options?: LogOptions): void; declare function info(message: string, attributes?: Record, options?: LogOptions): void; declare function trace(message: string, attributes?: Record, options?: LogOptions): void; declare function error(message: string, attributes?: Record, options?: LogOptions): void; declare function fatal(message: string, attributes?: Record, options?: LogOptions): void; declare function notice(message: string, attributes?: Record, options?: LogOptions): void; declare function warning(message: string, attributes?: Record, options?: LogOptions): void; declare function instrument(fn: F, options?: InstrumentOptions): F; declare function reportError(message: string, error: unknown, extraAttributes?: Record, options?: ReportErrorOptions): void; interface LogfireClient { debug(message: string, attributes?: Record, options?: LogOptions): void; error(message: string, attributes?: Record, options?: LogOptions): void; fatal(message: string, attributes?: Record, options?: LogOptions): void; info(message: string, attributes?: Record, options?: LogOptions): void; instrument(fn: F, options?: InstrumentOptions): F; log(message: string, attributes?: Record, options?: LogOptions): void; notice(message: string, attributes?: Record, options?: LogOptions): void; reportError(message: string, error: unknown, extraAttributes?: Record, options?: ReportErrorOptions): void; span: typeof span; startPendingSpan(message: string, attributes?: Record, options?: StartPendingSpanOptions): Span; startSpan(message: string, attributes?: Record, options?: LogOptions): Span; trace(message: string, attributes?: Record, options?: LogOptions): void; warning(message: string, attributes?: Record, options?: LogOptions): void; withSettings(settings: LogfireClientSettings): LogfireClient; withTags(...tags: string[]): LogfireClient; } declare function withSettings(settings: LogfireClientSettings): LogfireClient; declare function withTags(...tags: string[]): LogfireClient; declare const defaultExport: { LogfireAttributeScrubber: typeof LogfireAttributeScrubber; NoopAttributeScrubber: typeof NoopAttributeScrubber; NoopScrubber: NoopAttributeScrubber; PendingSpanProcessor: typeof PendingSpanProcessor; SpanLevel: typeof SpanLevel; TailSamplingProcessor: typeof TailSamplingProcessor; ULIDGenerator: typeof ULIDGenerator; canonicalizeError: typeof canonicalizeError; checkTraceIdRatio: typeof checkTraceIdRatio; configureLogfireApi: typeof configureLogfireApi; computeFingerprint: typeof computeFingerprint; debug: typeof debug; error: typeof error; fatal: typeof fatal; info: typeof info; instrument: typeof instrument; levelOrDuration: typeof levelOrDuration; log: typeof log; logfireApiConfig: typeof logfireApiConfig; notice: typeof notice; reportError: typeof reportError; resolveBaseUrl: typeof resolveBaseUrl; resolveSendToLogfire: typeof resolveSendToLogfire; serializeAttributes: typeof serializeAttributes; span: typeof span; startPendingSpan: typeof startPendingSpan; startSpan: typeof startSpan; trace: typeof trace; warning: typeof warning; withSettings: typeof withSettings; withTags: typeof withTags; Level: typeof Level; }; //#endregion export { ATTRIBUTES_PENDING_SPAN_REAL_PARENT_KEY, AttributeScrubber, type BaggageOptions, BaseScrubber, InstrumentOptions, JsonPath, type JsonSchemaMode, Level, type LevelName, type LogFireLevel, LogOptions, type LogfireApiConfig, type LogfireApiConfigOptions, LogfireAttributeScrubber, LogfireClient, LogfireClientSettings, type MinLevel, NoopAttributeScrubber, NoopScrubber, PendingSpanProcessor, ReportErrorOptions, SamplingOptions, ScrubCallback, ScrubMatch, ScrubbedNote, type ScrubbingOptions, SpanLevel, StartPendingSpanOptions, TailSamplingProcessor, type TailSamplingProcessorOptions, TailSamplingSpanInfo, ULIDGenerator, canonicalizeError, checkTraceIdRatio, computeFingerprint, configureLogfireApi, debug, defaultExport as default, error, fatal, info, instrument, levelOrDuration, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace, warning, withSettings, withTags };