Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics API in azure-core and otel implementation #29086

Merged
merged 25 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

<!-- Identity and opentelemetry tracing are plugin packages and shouldn't be referenced -->
<suppress checks="IllegalImport" files=".*[/\\]com[/\\]azure[/\\]core[/\\]tracing[/\\]opentelemetry[/\\]*"/>
<suppress checks="IllegalImport" files=".*[/\\]com[/\\]azure[/\\]core[/\\]metrics[/\\]opentelemetry[/\\]*"/>
<suppress checks="IllegalImport" files=".*[/\\]com[/\\]azure[/\\]monitor[/\\]opentelemetry[/\\]exporter[/\\]*"/>
<suppress checks="IllegalImport" files=".*[/\\]com[/\\]azure[/\\]identity[/\\]*"/>

Expand Down Expand Up @@ -193,7 +194,9 @@ the main ServiceBusClientBuilder. -->
files="com.azure.core.http.vertx.VertxProvider"/>
<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.monitor.opentelemetry.exporter.AzureMonitorTraceExporter"/>

<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.core.metrics.opentelemetry.OpenTelemetryMetricsOptions"/>

<!-- Suppress external dependency Checkstyle on serialization packages -->
<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.core.serializer.avro.apache.ApacheAvroSerializerBuilder"/>
Expand Down
13 changes: 7 additions & 6 deletions eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,13 @@ com.microsoft.azure:azure-storage;8.0.0
com.microsoft.azure:msal4j;1.12.0
com.microsoft.azure:msal4j-persistence-extension;1.1.0
com.sun.activation:jakarta.activation;1.2.2
io.opentelemetry:opentelemetry-api;1.11.0
io.opentelemetry:opentelemetry-sdk;1.11.0
io.opentelemetry:opentelemetry-exporter-logging;1.11.0
io.opentelemetry:opentelemetry-exporter-jaeger;1.11.0
io.opentelemetry:opentelemetry-sdk-testing;1.11.0
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure;1.11.0-alpha
io.opentelemetry:opentelemetry-api;1.14.0
io.opentelemetry:opentelemetry-sdk;1.14.0
io.opentelemetry:opentelemetry-exporter-logging;1.14.0
io.opentelemetry:opentelemetry-exporter-jaeger;1.14.0
io.opentelemetry:opentelemetry-exporter-otlp;1.14.0
io.opentelemetry:opentelemetry-sdk-testing;1.14.0
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure;1.14.0-alpha
io.projectreactor:reactor-test;3.4.19
junit:junit;4.13.2
commons-cli:commons-cli;1.3
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ com.azure:azure-core-http-netty;1.12.3;1.13.0-beta.1
com.azure:azure-core-http-okhttp;1.11.0;1.12.0-beta.1
com.azure:azure-core-http-vertx;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core-management;1.7.0;1.8.0-beta.1
com.azure:azure-core-metrics-opentelemetry;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-core-serializer-avro-apache;1.0.0-beta.26;1.0.0-beta.27
com.azure:azure-core-serializer-avro-jackson;1.0.0-beta.1;1.0.0-beta.2
Expand Down
12 changes: 6 additions & 6 deletions sdk/attestation/azure-security-attestation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>1.11.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-logging</artifactId>
<version>1.11.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>1.11.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -149,9 +149,9 @@
<bannedDependencies>
<includes>
<include>com.nimbusds:nimbus-jose-jwt:[9.22]</include> <!-- {x-include-update;com.nimbusds:nimbus-jose-jwt;external_dependency} -->
<include>io.opentelemetry:opentelemetry-api:[1.11.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk:[1.11.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-logging:[1.11.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
<include>io.opentelemetry:opentelemetry-api:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-logging:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
</includes>
</bannedDependencies>
</rules>
Expand Down
11 changes: 11 additions & 0 deletions sdk/core/azure-core-metrics-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 1.0.0-beta.1 (Unreleased)

### Features Added

- Initial version

### Breaking Changes

### Bugs Fixed

### Other Changes
131 changes: 131 additions & 0 deletions sdk/core/azure-core-metrics-opentelemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Azure OpenTelemetry Metrics plugin library for Java

This package enables metrics from Azure SDK Java libraries through [OpenTelemetry][OpenTelemetry]. OpenTelemetry is an open source, vendor-agnostic, single distribution of libraries to provide metrics collection and distributed tracing for services.

[Source code][source_code] | [API reference documentation][api_documentation] | [Product
documentation][OpenTelemetry] | [Samples][samples]

## Getting started

### Prerequisites

- A [Java Development Kit (JDK)][jdk_link], version 8 or later.

### Include the package

[//]: # ({x-version-update-start;com.azure:azure-core-metrics-opentelemetry;current})
```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-metrics-opentelemetry</artifactId>
<version>1.0.0-beta.1</version>
</dependency>
```
[//]: # ({x-version-update-end})

## Key concepts

Check out [Metrics in OpenTelemetry](https://opentelemetry.io/docs/concepts/signals/metrics/) for all the details on metrics.

## Examples

The following sections provide several code snippets covering some of the most common client configuration scenarios.

- [Default configuration: agent](#default-configuration-agent)
- [Default configuration: Opentelemtery SDK](#default-configuration-agent)
- [Custom configuration](#custom-configuration)

You can find more samples [here](https://github.com/Azure/azure-sdk-for-java/blob/cb37bdb3067cc800f4b1429fc3d265d66c50f8e7/sdk/core/azure-core-metrics-opentelemetry/src/samples/).

### Default configuration: agent

If you use OpenTelemetry Java agent or Application Insights Java agent version 3.3.0-BETA or higher, no additional Azure SDK configuration is needed.

### Default configuration: OpenTelemetry SDK

Azure SDK uses global OpenTelemetry instance by default. You can use [OpenTelemetry SDK Autoconfigure](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md)
package to configure OpenTelemetry using environment variables (or system properties).

```xml
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
</dependency>
```


```java readme-sample-defaultConfiguration

// configure OpenTelemetry SDK using OpenTelemetry SDK Autoconfigure
AutoConfiguredOpenTelemetrySdk.initialize();

// configure Azure Client, no metric configuration needed
// client will use global OTel configured by OpenTelemetry autoconfigure package.
AzureClient sampleClient = new AzureClientBuilder()
.endpoint("https://my-client.azure.com")
.build();

// use client as usual, if it emits metric, they will be exported
sampleClient.methodCall("get items");

```

### Custom configuration

If you want to pass `MeterProvider` explicitly, you can do it using `MetricsOptions` and passing them to Azure Clients. `MetricsOptions` can also be used to disable metrics from specific client.

```java readme-sample-customConfiguration

// configure OpenTelemetry SDK explicitly per https://opentelemetry.io/docs/instrumentation/java/manual/
SdkMeterProvider meterProvider = SdkMeterProvider.builder()
.registerMetricReader(PeriodicMetricReader.builder(OtlpGrpcMetricExporter.builder().build()).build())
.build();

// Pass OTel meterProvider to MetricsOptions.
MetricsOptions customMetricsOptions = new OpenTelemetryMetricsOptions()
.setProvider(meterProvider);

// configure Azure Client to use customMetricsOptions - it will use meterProvider
// to create meters and instruments
AzureClient sampleClient = new AzureClientBuilder()
.endpoint("https://my-client.azure.com")
.clientOptions(new ClientOptions().setMetricsOptions(customMetricsOptions))
.build();

// use client as usual, if it emits metric, they will be exported
sampleClient.methodCall("get items");

```

## Troubleshooting

### General

For more information on OpenTelemetry, see [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/java/getting-started/) and [OpenTelemetry Java](https://github.com/open-telemetry/opentelemetry-java).

### Enabling Logging

Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite
their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help
locate the root issue. View the [logging][logging] wiki for guidance about enabling logging.

## Next steps

Get started with Azure libraries that are [built using Azure Core](https://azure.github.io/azure-sdk/releases/latest/#java).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla](https://cla.microsoft.com).

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

<!-- Links -->
[api_documentation]: https://aka.ms/java-docs
[context]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core/src/main/java/com/azure/core/util/Context.java
[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
[logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-with-Azure-SDK
[source_code]: https://github.com/Azure/azure-sdk-for-java/blob/cb37bdb3067cc800f4b1429fc3d265d66c50f8e7/sdk/core/azure-core-metrics-opentelemetry/src/

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fcore%2Fazure-core-metrics-opentelemetry%2FREADME.png)
153 changes: 153 additions & 0 deletions sdk/core/azure-core-metrics-opentelemetry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.azure</groupId>
<artifactId>azure-client-sdk-parent</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} -->
<relativePath>../../parents/azure-client-sdk-parent</relativePath>
</parent>

<groupId>com.azure</groupId>
<artifactId>azure-core-metrics-opentelemetry</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core-metrics-opentelemetry;current} -->
lmolkova marked this conversation as resolved.
Show resolved Hide resolved

<name>Microsoft Azure OpenTelemetry metrics plugin</name>
<description>This package contains the OpenTelemetry metrics plugin for Azure client libraries.</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<distributionManagement>
<site>
<id>azure-java-build-docs</id>
<url>${site.url}/site/${project.artifactId}</url>
</site>
</distributionManagement>

<scm>
<url>scm:git:https://github.com/Azure/azure-sdk-for-java</url>
<connection>scm:git:git@github.com:Azure/azure-sdk-for-java.git</connection>
<tag>HEAD</tag>
</scm>

<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.31.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} -->
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version> <!-- {x-version-update;com.google.code.findbugs:jsr305;external_dependency} -->
<scope>provided</scope>
</dependency>

<!--test dependencies -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-testing</artifactId>
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk-testing;external_dependency} -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.11.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core-test;current} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.13.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core-http-netty;current} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version> <!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.22</version> <!-- {x-version-update;org.openjdk.jmh:jmh-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.22</version> <!-- {x-version-update;org.openjdk.jmh:jmh-generator-annprocess;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
<version>1.14.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-exporter-otlp;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
<version>1.14.0-alpha</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk-extension-autoconfigure;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-enforcer-plugin;external_dependency} -->
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>io.opentelemetry:opentelemetry-api:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk-testing:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk-testing;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-logging:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-otlp:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-otlp;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-jaeger:[1.14.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-jaeger;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:[1.14.0-alpha]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk-extension-autoconfigure;external_dependency} -->
</includes>
</bannedDependencies>
</rules>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading