Skip to content

Commit 7577ef2

Browse files
Update the QUICKSTART with more metrics. (#1167)
* Update the QUICKSTART with more metrics. * Use CPU usage for the Observer example.
1 parent 12fa581 commit 7577ef2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

QUICKSTART.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ business metric such as transactions.
251251
All metrics can be annotated with labels: additional qualifiers that help describe what
252252
subdivision of the measurements the metric represents.
253253

254-
The following is an example of metric usage:
254+
The following is an example of counter usage:
255255

256256
```java
257257
// Gets or creates a named meter instance
@@ -271,6 +271,32 @@ BoundLongCounter someWorkCounter = counter.bind("Key", "SomeWork");
271271
// Record data
272272
someWorkCounter.add(123);
273273

274+
// Alternatively, the user can use the unbounded counter and explicitly
275+
// specify the labels set at call-time:
276+
counter.add(123, "Key", "SomeWork");
277+
```
278+
279+
`Observer` is an additional instrument supporting an asynchronous API and
280+
collecting metric data on demand, once per collection interval.
281+
282+
The following is an example of observer usage:
283+
284+
```java
285+
// Build observer e.g. LongObserver
286+
LongObserver observer = meter
287+
.observerLongBuilder("cpu_usage")
288+
.setDescription("CPU Usage")
289+
.setUnit("ms")
290+
.build();
291+
292+
observer.setCallback(
293+
new LongObserver.Callback<LongObserver.ResultLongObserver>() {
294+
@Override
295+
public void update(ResultLongObserver result) {
296+
// long getCpuUsage()
297+
result.observe(getCpuUsage(), "Key", "SomeWork");
298+
}
299+
});
274300
```
275301

276302
## Tracing SDK Configuration

0 commit comments

Comments
 (0)