import { metrics } from '@opentelemetry/api';
let meter;
function getMeter() {
    if (!meter) {
        meter = metrics.getMeter('zero');
    }
    return meter;
}
function cache() {
    const instruments = new Map();
    return (name, creator) => {
        const existing = instruments.get(name);
        if (existing) {
            return existing;
        }
        const ret = creator(name);
        instruments.set(name, ret);
        return ret;
    };
}
const upDownCounters = cache();
export function getOrCreateUpDownCounter(category, name, opts) {
    return upDownCounters(name, name => getMeter().createUpDownCounter(`zero.${category}.${name}`, typeof opts === 'string' ? { description: opts } : opts));
}
const histograms = cache();
export function getOrCreateHistogram(category, name, opts) {
    return histograms(name, name => {
        const options = typeof opts === 'string'
            ? {
                description: opts,
                unit: 'milliseconds',
            }
            : opts;
        return getMeter().createHistogram(`zero.${category}.${name}`, options);
    });
}
const counters = cache();
export function getOrCreateCounter(category, name, opts) {
    return counters(name, name => getMeter().createCounter(`zero.${category}.${name}`, typeof opts === 'string' ? { description: opts } : opts));
}
const gauges = cache();
export function getOrCreateGauge(category, name, opts) {
    return gauges(name, name => getMeter().createObservableGauge(`zero.${category}.${name}`, typeof opts === 'string' ? { description: opts } : opts));
}
//# sourceMappingURL=metrics.js.map