"use strict";
var import_vitest = require("vitest");
var import_log = require("./log.cjs");
var import_pino_otel_transport = require("./telemetry/pino_otel_transport.cjs");
const OTEL_ENABLED_KEY = Symbol.for("@livekit/agents:otelEnabled");
function resetOtelLoggingState() {
  delete globalThis[OTEL_ENABLED_KEY];
  (0, import_log.initializeLogger)({ pretty: false, level: "silent" });
}
(0, import_vitest.describe)("OTEL logging", () => {
  (0, import_vitest.afterEach)(() => {
    import_vitest.vi.restoreAllMocks();
    resetOtelLoggingState();
  });
  (0, import_vitest.it)("exports logs from logger instances captured before OTEL is enabled", async () => {
    (0, import_log.initializeLogger)({ pretty: false, level: "info" });
    const staleLogger = (0, import_log.log)().child({ capturedBeforeOtel: true });
    const emitSpy = import_vitest.vi.spyOn(import_pino_otel_transport.PinoCloudExporter.prototype, "emit").mockImplementation(() => {
    });
    (0, import_pino_otel_transport.initPinoCloudExporter)({
      cloudHostname: "example.livekit.cloud",
      roomId: "RM_test",
      jobId: "AJ_test"
    });
    (0, import_log.enableOtelLogging)();
    staleLogger.info("log from stale logger");
    (0, import_log.log)().info("log from fresh logger");
    await import_vitest.vi.waitFor(() => {
      const messages = emitSpy.mock.calls.map(([logObj]) => logObj.msg);
      (0, import_vitest.expect)(messages).toContain("log from stale logger");
      (0, import_vitest.expect)(messages).toContain("log from fresh logger");
    });
  });
});
//# sourceMappingURL=log.test.cjs.map