Skip to content

Commit

Permalink
Add Azure Monitor Autoconfigure library (#42713)
Browse files Browse the repository at this point in the history
* Add Azure Monitor Autoconfigure library
  • Loading branch information
jeanbisutti authored Nov 7, 2024
1 parent 24f9588 commit 5a69f58
Show file tree
Hide file tree
Showing 237 changed files with 28,116 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@
# PRLabel: %OpenTelemetry
/sdk/monitor/azure-monitor-opentelemetry-exporter/ @trask @ramthi @heyams @jeanbisutti @harsimar

# PRLabel: %OpenTelemetry
/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/ @trask @ramthi @heyams @jeanbisutti @harsimar

# ServiceLabel: %Network
# ServiceOwners: @aznetsuppgithub

Expand Down
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"sdk/maps/azure-maps-search/**",
"sdk/monitor/azure-monitor-query/**",
"sdk/monitor/azure-monitor-opentelemetry-exporter/**",
"sdk/monitor/azure-monitor-opentelemetry-autoconfigure/**",
"sdk/monitor/test-resources.json",
"sdk/modelsrepository/azure-iot-modelsrepository/**",
"sdk/parents/azure-client-sdk-parent/**",
Expand Down
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ omitted_paths:
- sdk/*/azure-*/samples/*
- sdk/authorization/microsoft-azure-authentication-msi-token-provider/*
- sdk/*/azure-monitor-opentelemetry-exporter/*/samples/*
- sdk/*/azure-monitor-opentelemetry-autoconfigure/*/samples/*
- sdk/boms/spring-cloud-azure-dependencies/*
- sdk/spring/*
- "sdk/spring/*/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.monitor.opentelemetry.exporter.AzureMonitorExporterOptions"/>

<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.monitor.opentelemetry.autoconfigure.AzureMonitorAutoConfigure.java"/>

<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
files="com.azure.monitor.opentelemetry.autoconfigure.AzureMonitorAutoConfigureOptions"/>

<!-- JavadocInlineTagCheck Suppression for now, which need code owner's attention -->
<suppress checks="com.azure.tools.checkstyle.checks.JavadocInlineTagCheck"
files="com.azure.security.keyvault.keys.(KeyClient|KeyAsyncClient).java"/>
Expand Down
7 changes: 4 additions & 3 deletions eng/scripts/aggregate_javadoc_configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Group;Azure Mixed Reality Remote Rendering;com.azure.mixedreality.remoterenderin
Group;Azure Monitor - Ingestion;com.azure.monitor.ingestion*
Group;Azure Monitor - Logs and Metrics query;com.azure.monitor.query*
Group;Azure Monitor - OpenTelemetry Exporter;com.azure.monitor.opentelemetry.exporter*
Group;Azure Monitor - Azure Monitor OpenTelemetry SDK Autoconfigure Distro;com.azure.monitor.opentelemetry.autoconfigure*
Group;Azure Personalizer;com.azure.ai.personalizer*
Group;Azure Purview Administration;com.azure.analytics.purview.administration*
Group;Azure Purview Catalog;com.azure.analytics.purview.catalog*
Expand All @@ -65,7 +66,7 @@ Group;Azure Text Analytics;com.azure.ai.textanalytics*
Group;Azure Web Pub Sub;com.azure.messaging.webpubsub*

# Adds the following links to external javadocs
# Link;URL
# Link;URL
Link;https://docs.oracle.com/javase/8/docs/api/
Link;https://projectreactor.io/docs/core/release/api/
Link;https://projectreactor.io/docs/netty/release/api/
Expand All @@ -85,7 +86,7 @@ OfflineLink;https://fasterxml.github.io/jackson-core/javadoc/2.12/;eng/javadoc-p
OfflineLink;https://netty.io/4.1/api/;eng/javadoc-package-lists/netty/
OfflineLink;https://avro.apache.org/docs/current/api/java/;eng/javadoc-package-lists/apache-avro/

# Adds the following packages to excludedPackages section
# Adds the following packages to excludedPackages section
# ExcludePackage;Package
ExcludePackage;*.impl*
ExcludePackage;*.implementation*
Expand All @@ -96,7 +97,7 @@ ExcludePackage;com.azure.endtoend
ExcludePackage;com.azure.perf*
ExcludePackage;com.azure.storage.internal.avro*

# Adds the following files to sourceFileExcludes section
# Adds the following files to sourceFileExcludes section
# ExcludeFile;FilePath
ExcludeFile;com/azure/cosmos/*BridgeInternal.java
ExcludeFile;com/azure/cosmos/models/*BridgeInternal.java
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 @@ -165,6 +165,7 @@ com.azure:azure-messaging-webpubsub-client;1.0.8;1.1.0-beta.1
com.azure:azure-mixedreality-authentication;1.2.29;1.3.0-beta.1
com.azure:azure-mixedreality-remoterendering;1.1.34;1.2.0-beta.1
com.azure:azure-monitor-opentelemetry-exporter;1.0.0-beta.31;1.0.0-beta.32
com.azure:azure-monitor-opentelemetry-autoconfigure;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-monitor-ingestion;1.2.6;1.3.0-beta.1
com.azure:azure-monitor-ingestion-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-monitor-query;1.5.3;1.6.0-beta.1
Expand Down
11 changes: 11 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry-autoconfigure/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
205 changes: 205 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry-autoconfigure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Azure Monitor OpenTelemetry SDK Autoconfigure Distro for Application Insights in Java applications client library for Java

This client library provides support for exporting OpenTelemetry data to Azure Monitor. This package assumes your
application is already instrumented with the [OpenTelemetry SDK][opentelemetry_sdk] following the [OpenTelemetry
Specification][opentelemetry_specification].

[Source code][source_code] | [Package (Maven)][package_mvn] | [API reference documentation][api_reference_doc] | [Product Documentation][product_documentation] | [Samples][sample_readme]

## Getting started

### Prerequisites

- [Java Development Kit (JDK) with version 8 or above][jdk]
- [Azure Subscription][azure_subscription]
- [Application Insights resource][application_insights_resource]

For more information, please read [introduction to Application Insights][application_insights_intro].

### Include the dependency

Add the [Azure Monitor OpenTelemetry SDK Autoconfigure Distro](https://central.sonatype.com/artifact/com.azure/azure-monitor-opentelemetry-autoconfigure) dependency.

### Authentication

#### Get the connection string from the portal

In order to export telemetry data to Azure Monitor, you will need the instrumentation key to your [Application
Insights resource][application_insights_resource]. To get your instrumentation key, go to [Azure Portal][azure_portal],
search for your resource. On the overview page of your resource, you will find the instrumentation key in the top
right corner.


### Setup the Azure Monitor OpenTelemetry SDK Autoconfigure Distro

If you have set the Application Insights connection string with the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable, you can configure OpenTelemetry SDK auto-configuration for Azure in the following way:

```java readme-sample-autoconfigure-env-variable
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorAutoConfigure.customize(sdkBuilder);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();
```

You can also set the connection string in the code:
```java readme-sample-autoconfigure
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorAutoConfigure.customize(sdkBuilder, "{connection-string}");
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();
```

## Examples

The following sections provide code samples using the Azure Monitor OpenTelemetry SDK Autoconfigure Distro and OpenTelemetry SDK.

The following example shows how create a span:

```java readme-sample-create-span
AutoConfiguredOpenTelemetrySdkBuilder otelSdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();

AzureMonitorAutoConfigure.customize(otelSdkBuilder, "{connection-string}");

OpenTelemetry openTelemetry = otelSdkBuilder.build().getOpenTelemetrySdk();
Tracer tracer = openTelemetry.getTracer("Sample");

Span span = tracer.spanBuilder("spanName").startSpan();

// Make the span the current span
try (Scope scope = span.makeCurrent()) {
// Your application logic here
applicationLogic();
} catch (Throwable t) {
span.recordException(t);
throw t;
} finally {
span.end();
}
```
The following example demonstrates how to add a span processor to the OpenTelemetry SDK autoconfiguration.

```java readme-sample-span-processor
private static final AttributeKey<String> ATTRIBUTE_KEY = AttributeKey.stringKey("attributeKey");

public void spanProcessor() {
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();

AzureMonitorAutoConfigure.customize(sdkBuilder);

SpanProcessor spanProcessor = new SpanProcessor() {

@Override
public void onStart(Context context, ReadWriteSpan span) {
span.setAttribute(ATTRIBUTE_KEY, "attributeValue");
}

@Override
public boolean isStartRequired() {
return true;
}

@Override
public void onEnd(ReadableSpan readableSpan) {
}

@Override
public boolean isEndRequired() {
return false;
}
};

sdkBuilder.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) -> sdkTracerProviderBuilder
.addSpanProcessor(spanProcessor));
}
```
More advanced examples with OpenTelemetry APIs:
* [Advanced examples - 1][advanced_examples_1]
* [Advanced examples - 2][advanced_examples_2]
* [Event Hubs example][event_hubs_example]

## Key concepts

Some key concepts for the Azure Monitor OpenTelemetry SDK Autoconfigure Distro include:

* [OpenTelemetry][opentelemetry_spec]: OpenTelemetry is a set of libraries used to collect and export telemetry data
(metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.

* [Instrumentation][instrumentation_library]: The ability to call the OpenTelemetry API directly by any application is
facilitated by instrumentation. A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.

* [Trace][trace_concept]: Trace refers to distributed tracing. It can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship.

* [Tracer Provider][tracer_provider]: Provides a `Tracer` for use by the given instrumentation library.

* [Span Processor][span_processor]: A span processor allows hooks for SDK's `Span` start and end method invocations. Follow the link for more information.

* [Sampling][sampler_ref]: Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.

For more information on the OpenTelemetry project, please review the [OpenTelemetry Specifications][opentelemetry_specification].


## Troubleshooting

### Enabling Logging

You can leverage [Azure SDK logging](logging].

Examples:
* [Log4j][log4j]
* [Logback][logback]

Learn more about [OpenTelemetry SDK logging][logging_otel_sdk].

## Next steps
Learn more about [OpenTelemetry][opentelemetry_io]

## Contributing

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

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][coc]. For more information see the
[Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments.

<!-- LINKS -->
[jdk]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor
[source_code]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src
[azure_subscription]: https://azure.microsoft.com/free/
[api_reference_doc]: https://docs.microsoft.com/azure/azure-monitor/overview
[package_mvn]: https://central.sonatype.com/artifact/com.azure/azure-monitor-opentelemetry-autoconfigure
[product_documentation]: https://docs.microsoft.com/azure/azure-monitor/overview
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_portal]: https://portal.azure.com
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential
[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain
[logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-in-Azure-SDK
[log4j]: https://github.com/Azure-Samples/ApplicationInsights-Java-Samples/blob/9a7344eeb44525dfc83df3a1bd59460b8a7d93c6/opentelemetry-api/exporter/TrackTrace/Log4j2/src/main/resources/log4j2.xml#L16
[logback]: https://github.com/Azure-Samples/ApplicationInsights-Java-Samples/blob/9a7344eeb44525dfc83df3a1bd59460b8a7d93c6/opentelemetry-api/exporter/TrackTrace/Logback/src/main/resources/logback.xml#L22
[logging_otel_sdk]: https://opentelemetry.io/docs/languages/java/sdk/#internal-logging
[opentelemetry_specification]: https://github.com/open-telemetry/opentelemetry-specification
[application_insights_resource]: https://docs.microsoft.com/azure/azure-monitor/app/create-new-resource
[application_insights_intro]: https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview
[azure_portal]: https://ms.portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/microsoft.insights%2Fcomponents
[opentelemetry_io]: https://opentelemetry.io/
[span_data]: https://opentelemetry.lightstep.com/spans
[sample_readme]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/samples
[opentelemetry_spec]: https://opentelemetry.io/
[instrumentation_library]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#instrumentation-libraries
[tracer_provider]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#tracer-provider
[span_processor]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-processor
[sampler_ref]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling
[trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace
[advanced_examples_1]: https://github.com/Azure-Samples/ApplicationInsights-Java-Samples/tree/main/opentelemetry-api/exporter/
[advanced_examples_2]: https://github.com/open-telemetry/opentelemetry-java-examples/tree/main/sdk-usage/src/main/java/io/opentelemetry/sdk/example
[event_hubs_example]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/samples/java/com/azure/monitor/opentelemetry/autoconfigure/EventHubsAzureMonitorExporterSample.java
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:[email protected]
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%monitor%2Fazure-monitor-opentelemetry-autoconfigure%2FREADME.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/monitor/azure-monitor-opentelemetry-exporter",
"Tag": "java/monitor/azure-monitor-opentelemetry-exporter_558a81e425"
}
Loading

0 comments on commit 5a69f58

Please sign in to comment.