"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIGNEObserver = void 0;
const api_1 = require("@opentelemetry/api");
const db_path_js_1 = __importDefault(require("../core/db-path.js"));
const type_js_1 = require("../core/type.js");
const util_js_1 = require("../core/util.js");
const init_js_1 = require("../opentelemetry/instrument/init.js");
class AIGNEObserver {
    storage;
    tracer = api_1.trace.getTracer("aigne-tracer");
    traceExporter;
    sdkServerStarted;
    static exportFn;
    static setExportFn(exportFn) {
        AIGNEObserver.exportFn = exportFn;
    }
    constructor(options) {
        const parsed = type_js_1.AIGNEObserverOptionsSchema.parse(options);
        this.storage = parsed?.storage ?? (!util_js_1.isBlocklet ? (0, db_path_js_1.default)() : undefined);
    }
    async serve() {
        this.sdkServerStarted ??= this._serve();
        return this.sdkServerStarted;
    }
    async _serve() {
        if (!this.storage && !util_js_1.isBlocklet) {
            throw new Error("Server storage is not configured");
        }
        this.traceExporter = await (0, init_js_1.initOpenTelemetry)({
            dbPath: this.storage,
            exportFn: AIGNEObserver.exportFn,
        });
    }
    async close() { }
}
exports.AIGNEObserver = AIGNEObserver;
