import { metrics } from "@opentelemetry/api";
//#region ../zero-cache/src/observability/metrics.ts
var 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;
	};
}
var upDownCounters = cache();
function getOrCreateUpDownCounter(category, name, opts) {
	return upDownCounters(name, (name) => getMeter().createUpDownCounter(`zero.${category}.${name}`, typeof opts === "string" ? { description: opts } : opts));
}
var histograms = cache();
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);
	});
}
var counters = cache();
function getOrCreateCounter(category, name, opts) {
	return counters(name, (name) => getMeter().createCounter(`zero.${category}.${name}`, typeof opts === "string" ? { description: opts } : opts));
}
var gauges = cache();
function getOrCreateGauge(category, name, opts) {
	return gauges(name, (name) => getMeter().createObservableGauge(`zero.${category}.${name}`, typeof opts === "string" ? { description: opts } : opts));
}
//#endregion
export { getOrCreateCounter, getOrCreateGauge, getOrCreateHistogram, getOrCreateUpDownCounter };

//# sourceMappingURL=metrics.js.map