All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.metrics.DoubleValueObserver Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2019, 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
 *
 *     http://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.
 */

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import javax.annotation.concurrent.ThreadSafe;

/**
 * {@code ValueObserver} is the asynchronous instrument corresponding to ValueRecorder, used to
 * capture values that are treated as individual observations, recorded with the observe(value)
 * method.
 *
 * 

A {@code ValueObserver} is a good choice in situations where a measurement is expensive to * compute, such that it would be wasteful to compute on every request. * *

Example: * *

{@code
 * class YourClass {
 *
 *   private static final Meter meter = OpenTelemetry.getMeterRegistry().get("my_library_name");
 *   private static final DoubleValueObserver cpuObserver =
 *       meter.
 *           .doubleValueObserverBuilder("cpu_temperature")
 *           .setDescription("System CPU temperature")
 *           .setUnit("ms")
 *           .build();
 *
 *   void init() {
 *     cpuObserver.setCallback(
 *         new DoubleValueObserver.Callback() {
 *          {@literal @}Override
 *           public void update(DoubleResult result) {
 *             // Get system cpu temperature
 *             result.observe(cpuTemperature);
 *           }
 *         });
 *   }
 * }
 * }
* * @since 0.5.0 */ @ThreadSafe public interface DoubleValueObserver extends AsynchronousInstrument { @Override void setCallback(Callback callback); /** Builder class for {@link DoubleValueObserver}. */ interface Builder extends AsynchronousInstrument.Builder { @Override Builder setDescription(String description); @Override Builder setUnit(String unit); @Override Builder setConstantLabels(Labels constantLabels); @Override DoubleValueObserver build(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy