Skip to content

Commit d60903a

Browse files
[AzureMonitorOpenTelemetryDistro] Update Readme (#34650)
* Update Readme * Update * Application Insights * Rename package, API * PR feedback. * Fix issue caused with merge * Update * Update AAD section * Update
1 parent f288f55 commit d60903a

File tree

1 file changed

+82
-0
lines changed
  • sdk/monitor/Azure.Monitor.OpenTelemetry

1 file changed

+82
-0
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,101 @@
11
# Azure Monitor Distro client library for .NET
22

3+
The Azure Monitor Distro is a client library that sends telemetry data to Azure Monitor following the OpenTelemetry Specification. This library can be used to instrument your ASP.NET Core applications to collect and send telemetry data to Azure Monitor for analysis and monitoring, powering experiences in Application Insights.
4+
35
## Getting started
46

57
### Prerequisites
68

9+
- **Azure Subscription:** To use Azure services, including Azure Monitor Distro, you'll need a subscription. If you do not have an existing Azure account, you may sign up for a [free trial](https://azure.microsoft.com/free/dotnet/) or use your [Visual Studio Subscription](https://visualstudio.microsoft.com/subscriptions/) benefits when you [create an account](https://azure.microsoft.com/account).
10+
- **Azure Application Insights Connection String:** To send telemetry data to the monitoring service you'll need connection string from Azure Application Insights. If you are not familiar with creating Azure resources, you may wish to follow the step-by-step guide for [Create an Application Insights resource](https://docs.microsoft.com/azure/azure-monitor/app/create-new-resource) and [copy the connection string](https://docs.microsoft.com/azure/azure-monitor/app/sdk-connection-string?tabs=net#find-your-connection-string).
11+
- **ASP.NET Core App:** An ASP.NET Core application is required to instrument it with Azure Monitor Distro. You can either bring your own app or follow the [Get started with ASP.NET Core MVC](https://docs.microsoft.com/aspnet/core/tutorials/first-mvc-app/start-mvc) to create a new one.
12+
713
### Install the package
814

15+
Install the Azure Monitor Distro for .NET from [NuGet](https://www.nuget.org/):
16+
17+
```dotnetcli
18+
dotnet add package Azure.Monitor.OpenTelemetry --prerelease
19+
```
20+
21+
#### Nightly builds
22+
23+
Nightly builds are available from this repo's [dev feed](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#nuget-package-dev-feed).
24+
These are provided without support and are not intended for production workloads.
25+
26+
### Enabling Azure Monitor OpenTelemetry in your application
27+
28+
The following examples demonstrate how to integrate the Azure Monitor Distro into your application.
29+
30+
#### Example 1
31+
32+
To enable Azure Monitor Distro, add `AddAzureMonitor()` to your `Program.cs` file and set the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable to the connection string from your Application Insights resource.
33+
34+
```C#
35+
// This method gets called by the runtime. Use this method to add services to the container.
36+
var builder = WebApplication.CreateBuilder(args);
37+
38+
// The following line enables Azure Monitor Distro.
39+
builder.Services.AddAzureMonitor();
40+
41+
// This code adds other services for your application.
42+
builder.Services.AddMvc();
43+
44+
var app = builder.Build();
45+
```
46+
47+
#### Example 2
48+
49+
To enable Azure Monitor Distro with a hard-coded connection string, add `AddAzureMonitor()` to your `Program.cs` with the `AzureMonitorOptions` containing the connection string.
50+
51+
```C#
52+
// This method gets called by the runtime. Use this method to add services to the container.
53+
var builder = WebApplication.CreateBuilder(args);
54+
55+
// The following line enables Azure Monitor Distro with hard-coded connection string.
56+
builder.Services.AddAzureMonitor(o => o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");
57+
58+
// This code adds other services for your application.
59+
builder.Services.AddMvc();
60+
61+
var app = builder.Build();
62+
```
63+
64+
Note that in the examples above, `AddAzureMonitor` is added to the `IServiceCollection` in the `Program.cs` file. You can also add it in the `ConfigureServices` method of your `Startup.cs` file.
65+
966
### Authenticate the client
1067

68+
Azure Active Directory (AAD) authentication is an optional feature that can be used with Azure Monitor Distro. To enable AAD authentication, set the `Credential` property in `AzureMonitorOptions`. This is made easy with the [Azure Identity library][identity], which provides support for authenticating Azure SDK clients with their corresponding Azure services.
69+
70+
```C#
71+
// Call AddAzureMonitor and set Credential to authenticate through Active Directory.
72+
builder.Services.AddAzureMonitor(o =>
73+
{
74+
o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
75+
o.Credential = new DefaultAzureCredential();
76+
});
77+
```
78+
79+
With this configuration, the Azure Monitor Distro will use the credentials of the currently logged-in user or of the service principal to authenticate and send telemetry data to Azure Monitor.
80+
81+
Note that the `Credential` property is optional. If it is not set, Azure Monitor Distro will use the Instrumentation Key from the Connection String to send data to Azure Monitor.
82+
1183
## Key concepts
1284

85+
The Azure Monitor Distro uses instrumentation libraries from the .NET OpenTelemetry SDK to provide a convenient and easy way to export telemetry data to Azure Monitor.
86+
1387
## Examples
1488

89+
Refer to [`Program.cs`](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/monitor/Azure.Monitor.OpenTelemetry/tests/Azure.Monitor.OpenTelemetry.Demo/Program.cs) for a complete demo.
90+
1591
## Troubleshooting
1692

93+
The Azure Monitor Distro uses EventSource for its own internal logging. The logs are available to any EventListener by opting into the source named "OpenTelemetry-AzureMonitor-Exporter".
94+
95+
OpenTelemetry also provides it's own [self-diagnostics feature](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/README.md#troubleshooting) to collect internal logs.
96+
An example of this is available in our demo project [here](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Demo/OTEL_DIAGNOSTICS.json).
97+
98+
1799
## Next steps
18100

19101
For more information on Azure SDK, please refer to [this website](https://azure.github.io/azure-sdk/)

0 commit comments

Comments
 (0)