import { LangChainTracer } from "./tracer";
export function addTracerToHandlers(tracer, handlers) {
    if (handlers == null) {
        return [new LangChainTracer(tracer)];
    }
    if (Array.isArray(handlers)) {
        const tracerAlreadyRegistered = handlers.some((handler) => handler instanceof LangChainTracer);
        if (!tracerAlreadyRegistered) {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            handlers.push(new LangChainTracer(tracer));
        }
        return handlers;
    }
    const tracerAlreadyRegistered = handlers.inheritableHandlers.some((handler) => handler instanceof LangChainTracer) ||
        handlers.handlers.some((handler) => handler instanceof LangChainTracer);
    if (tracerAlreadyRegistered) {
        return handlers;
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    handlers.addHandler(new LangChainTracer(tracer), true);
    return handlers;
}
//# sourceMappingURL=instrumentationUtils.js.map