import { metrics } from "@opentelemetry/api";
let meter;
function getMeter() {
  if (!meter) {
    meter = metrics.getMeter("zero");
  }
  return meter;
}
function cache() {
  const instruments = /* @__PURE__ */ 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();
function getOrCreateUpDownCounter(category, name, opts) {
  return upDownCounters(
    name,
    (name2) => getMeter().createUpDownCounter(
      `zero.${category}.${name2}`,
      { description: opts }
    )
  );
}
const histograms = cache();
function getOrCreateHistogram(category, name, opts) {
  return histograms(name, (name2) => {
    const options = typeof opts === "string" ? {
      description: opts,
      unit: "milliseconds"
    } : opts;
    return getMeter().createHistogram(`zero.${category}.${name2}`, options);
  });
}
const counters = cache();
function getOrCreateCounter(category, name, opts) {
  return counters(
    name,
    (name2) => getMeter().createCounter(
      `zero.${category}.${name2}`,
      typeof opts === "string" ? { description: opts } : opts
    )
  );
}
const gauges = cache();
function getOrCreateGauge(category, name, opts) {
  return gauges(
    name,
    (name2) => getMeter().createObservableGauge(
      `zero.${category}.${name2}`,
      typeof opts === "string" ? { description: opts } : opts
    )
  );
}
export {
  getOrCreateCounter,
  getOrCreateGauge,
  getOrCreateHistogram,
  getOrCreateUpDownCounter
};
//# sourceMappingURL=metrics.js.map
