forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleUpDownCounterBuilder.java
More file actions
101 lines (93 loc) · 3.65 KB
/
DoubleUpDownCounterBuilder.java
File metadata and controls
101 lines (93 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.api.metrics;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
* Builder class for {@link DoubleUpDownCounter}.
*
* @since 1.10.0
*/
public interface DoubleUpDownCounterBuilder {
/**
* Sets the description for this instrument.
*
* @param description The description.
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument-description">Instrument
* Description</a>
*/
DoubleUpDownCounterBuilder setDescription(String description);
/**
* Sets the unit of measure for this instrument.
*
* @param unit The unit. Instrument units must be 63 or fewer ASCII characters.
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument-unit">Instrument
* Unit</a>
*/
DoubleUpDownCounterBuilder setUnit(String unit);
/**
* Builds and returns an UpDownCounter instrument with the configuration.
*
* @return The UpDownCounter instrument.
*/
DoubleUpDownCounter build();
/**
* Builds an Asynchronous UpDownCounter instrument with the given callback.
*
* <p>The callback will be called when the instrument is being observed.
*
* <p>Callbacks are expected to abide by the following restrictions:
*
* <ul>
* <li>Run in a finite amount of time.
* <li>Safe to call repeatedly, across multiple threads.
* </ul>
*
* @param callback A callback which observes measurements when invoked.
*/
ObservableDoubleUpDownCounter buildWithCallback(Consumer<ObservableDoubleMeasurement> callback);
/**
* Builds an Asynchronous UpDownCounter instrument with the given callback.
*
* <p>The callback will be called when the instrument is being observed, with {@code obj} passed
* as the first argument. This allows the SDK to hold a weak reference to {@code obj}, enabling
* automatic cleanup when the measured object is garbage collected.
*
* <p>The {@code obj} should be an independently-rooted object that the application holds for its
* own purposes (e.g. a connection pool, service instance, or cache). When the application drops
* its strong reference to {@code obj}, the SDK may automatically remove the callback.
*
* <p>Callbacks are expected to abide by the following restrictions:
*
* <ul>
* <li>Run in a finite amount of time.
* <li>Safe to call repeatedly, across multiple threads.
* </ul>
*
* @param obj The measured object. The callback receives this as its first argument.
* @param callback A callback which observes measurements when invoked.
* @param <T> The type of the measured object.
*/
@SuppressWarnings("InconsistentOverloads")
default <T> ObservableDoubleUpDownCounter buildWithCallback(
T obj, BiConsumer<T, ObservableDoubleMeasurement> callback) {
return buildWithCallback(measurement -> callback.accept(obj, measurement));
}
/**
* Build an observer for this instrument to observe values from a {@link BatchCallback}.
*
* <p>This observer MUST be registered when creating a {@link Meter#batchCallback(Runnable,
* ObservableMeasurement, ObservableMeasurement...) batchCallback}, which records to it. Values
* observed outside registered callbacks are ignored.
*
* @return an observable measurement that batch callbacks use to observe values.
* @since 1.15.0
*/
default ObservableDoubleMeasurement buildObserver() {
return DefaultMeter.getInstance().upDownCounterBuilder("noop").ofDoubles().buildObserver();
}
}