UNPKG

@openfga/sdk

Version:

JavaScript and Node.js SDK for OpenFGA

60 lines (59 loc) 2.18 kB
"use strict"; /** * JavaScript and Node.js SDK for OpenFGA * * API version: 1.x * Website: https://openfga.dev * Documentation: https://openfga.dev/docs * Support: https://openfga.dev/community * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) * * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricRecorder = exports.TelemetryMetric = void 0; const api_1 = require("@opentelemetry/api"); var TelemetryMetric; (function (TelemetryMetric) { TelemetryMetric["CounterCredentialsRequest"] = "counterCredentialsRequest"; TelemetryMetric["HistogramRequestDuration"] = "histogramRequestDuration"; TelemetryMetric["HistogramQueryDuration"] = "histogramQueryDuration"; })(TelemetryMetric || (exports.TelemetryMetric = TelemetryMetric = {})); class MetricRecorder { constructor() { this._meter = null; this._counters = {}; this._histograms = {}; } meter() { if (!this._meter) { this._meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.3"); } return this._meter; } counter(counter, value, attributes) { if (!this._counters[counter.name]) { this._counters[counter.name] = this.meter().createCounter(counter.name, { description: counter.description, unit: counter.unit, }); } if (value !== undefined) { this._counters[counter.name].add(value, attributes); } return this._counters[counter.name]; } histogram(histogram, value, attributes) { if (!this._histograms[histogram.name]) { this._histograms[histogram.name] = this.meter().createHistogram(histogram.name, { description: histogram.description, unit: histogram.unit, }); } if (value !== undefined) { this._histograms[histogram.name].record(value, attributes); } return this._histograms[histogram.name]; } } exports.MetricRecorder = MetricRecorder;