"use strict"; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchObservableResultImpl = exports.ObservableResultImpl = void 0; const api = require("@opentelemetry/api"); const metrics = require("@opentelemetry/api-metrics"); const HashMap_1 = require("./state/HashMap"); const Instruments_1 = require("./Instruments"); /** * The class implements {@link metrics.ObservableResult} interface. */ class ObservableResultImpl { constructor(_descriptor) { this._descriptor = _descriptor; /** * @internal */ this._buffer = new HashMap_1.AttributeHashMap(); } /** * Observe a measurement of the value associated with the given attributes. */ observe(value, attributes = {}) { if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) { api.diag.warn(`INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.`); value = Math.trunc(value); } this._buffer.set(attributes, value); } } exports.ObservableResultImpl = ObservableResultImpl; /** * The class implements {@link metrics.BatchObservableCallback} interface. */ class BatchObservableResultImpl { constructor() { /** * @internal */ this._buffer = new Map(); } /** * Observe a measurement of the value associated with the given attributes. */ observe(metric, value, attributes = {}) { if (!(0, Instruments_1.isObservableInstrument)(metric)) { return; } let map = this._buffer.get(metric); if (map == null) { map = new HashMap_1.AttributeHashMap(); this._buffer.set(metric, map); } if (metric._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) { api.diag.warn(`INT value type cannot accept a floating-point value for ${metric._descriptor.name}, ignoring the fractional digits.`); value = Math.trunc(value); } map.set(attributes, value); } } exports.BatchObservableResultImpl = BatchObservableResultImpl; //# sourceMappingURL=ObservableResult.js.map