import { trace } from "@opentelemetry/api";
import getObservabilityDbPath from "../core/db-path.js";
import { AIGNEObserverOptionsSchema } from "../core/type.js";
import { isBlocklet } from "../core/util.js";
import { initOpenTelemetry } from "../opentelemetry/instrument/init.js";
export class AIGNEObserver {
    storage;
    tracer = trace.getTracer("aigne-tracer");
    traceExporter;
    sdkServerStarted;
    static exportFn;
    static setExportFn(exportFn) {
        AIGNEObserver.exportFn = exportFn;
    }
    constructor(options) {
        const parsed = AIGNEObserverOptionsSchema.parse(options);
        this.storage = parsed?.storage ?? (!isBlocklet ? getObservabilityDbPath() : undefined);
    }
    async serve() {
        this.sdkServerStarted ??= this._serve();
        return this.sdkServerStarted;
    }
    async _serve() {
        if (!this.storage && !isBlocklet) {
            throw new Error("Server storage is not configured");
        }
        this.traceExporter = await initOpenTelemetry({
            dbPath: this.storage,
            exportFn: AIGNEObserver.exportFn,
        });
    }
    async close() { }
}
