-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7556 from OpenLiberty/staging
Publish 24009 topics
- Loading branch information
Showing
26 changed files
with
1,200 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2022 IBM Corporation and others. | ||
// Licensed under Creative Commons Attribution-NoDerivatives | ||
// 4.0 International (CC BY-ND 4.0) | ||
// https://creativecommons.org/licenses/by-nd/4.0/ | ||
// | ||
// Contributors: | ||
// IBM Corporation | ||
// | ||
:page-description: | ||
:seo-description: | ||
:page-layout: general-reference | ||
:page-type: general | ||
= Define custom MicroProfile Telemetry metrics | ||
|
||
You can use the OpenTelemetry metrics API to define custom metrics in your application code. When you enable the MicroProfile Telemetry feature 2.0 or later, you can then collect and emit these metrics to customize the observability of your application. | ||
|
||
For more information about collecting and emitting metrics with MicroProfile Telemetry, see xref:microprofile-telemetry.adoc#metrics[Configuring Open Liberty to use MicroProfile Telemetry to collect metrics]. | ||
|
||
For more information about OpenTelemetry metrics, see the link:https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-api/1.39.0/io/opentelemetry/api/metrics/package-summary.html[OpenTelemetry metrics API documentation]. | ||
|
||
Before you can use MicroProfile Telemetry to define custom metrics metrics, you must enable MicroProfile Telemetry in your development environment by editing your runtime configuration. You must also add the OpenTelemetry API and annotations as a dependency on your build path. For more information, see xref:prepare-mptelemetry.adoc[Prepare your development environment for MicroProfile Telemetry]. | ||
|
||
The following example defines a custom counter metric: | ||
|
||
[source,java] | ||
---- | ||
class WithCounter { | ||
@Inject | ||
Meter meter; | ||
private LongCounter counter; | ||
@PostConstruct | ||
public void init() { | ||
counter = meter | ||
.counterBuilder("new_subscriptions") | ||
.setDescription("Number of new subscriptions") | ||
.setUnit("1") | ||
.build(); | ||
} | ||
void subscribe(String plan) { | ||
counter.add(1, | ||
Attributes.of(AttributeKey.stringKey("plan"), plan)); | ||
} | ||
} | ||
---- | ||
|
||
In this example, `Meter` is used to define an instrument, in this case a Counter. Application code then can record measurement values along with other attributes. Measurement aggregations are computed separately for each unique combination of attributes. | ||
|
||
For a full list of available metrics, see link:https://opentelemetry.io/docs/specs/otel/metrics/api/#meter-operations[Meter operations] in the OpenTelemetry documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.