Azure.Monitor.OpenTelemetry.Exporter 1.4.0-beta.2

Prefix Reserved
This is a prerelease version of Azure.Monitor.OpenTelemetry.Exporter.
dotnet add package Azure.Monitor.OpenTelemetry.Exporter --version 1.4.0-beta.2                
NuGet\Install-Package Azure.Monitor.OpenTelemetry.Exporter -Version 1.4.0-beta.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.4.0-beta.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Monitor.OpenTelemetry.Exporter --version 1.4.0-beta.2                
#r "nuget: Azure.Monitor.OpenTelemetry.Exporter, 1.4.0-beta.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Monitor.OpenTelemetry.Exporter as a Cake Addin
#addin nuget:?package=Azure.Monitor.OpenTelemetry.Exporter&version=1.4.0-beta.2&prerelease

// Install Azure.Monitor.OpenTelemetry.Exporter as a Cake Tool
#tool nuget:?package=Azure.Monitor.OpenTelemetry.Exporter&version=1.4.0-beta.2&prerelease                

Azure Monitor Exporter client library for .NET

The OpenTelemetry .NET exporters which send telemetry data to Azure Monitor following the OpenTelemetry Specification.

Getting started

Prerequisites

Migrating from Application Insights SDK

If you are currently using the Application Insights SDK and want to migrate to OpenTelemetry, please follow our migration guide.

Already using OpenTelemetry?

If you are currently using OpenTelemetry and want to send telemetry data to Azure Monitor, please follow our getting started guide.

Install the package

Latest Version: Nuget

Install the Azure Monitor Exporter for OpenTelemetry .NET with NuGet:

dotnet add package Azure.Monitor.OpenTelemetry.Exporter
Nightly builds

Nightly builds are available from this repo's dev feed. These are provided without support and are not intended for production workloads.

Add the Exporter

The following examples demonstrate how to add the AzureMonitorExporter to your OpenTelemetry configuration.

It's important to keep the TracerProvider, MeterProvider, and LoggerFactory instances active throughout the process lifetime. These must be properly disposed when your application is shutting down to flush any remaining telemetry items.

  • Traces

    var tracerProvider = Sdk.CreateTracerProviderBuilder()
        .AddAzureMonitorTraceExporter(options => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000")
        .Build();
    

    For a complete example see TraceDemo.cs.

  • Metrics

    var meterProvider = Sdk.CreateMeterProviderBuilder()
        .AddAzureMonitorMetricExporter(options => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000")
        .Build();
    

    For a complete example see MetricDemo.cs.

  • Logs

    var loggerFactory = LoggerFactory.Create(builder =>
    {
        builder.AddOpenTelemetry(logging =>
        {
            logging.AddAzureMonitorLogExporter(options => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");
        });
    });
    

    For a complete example see LogDemo.cs.

Authenticate the client

Azure Active Directory (AAD) authentication is an optional feature that can be used with the Azure Monitor Exporter. This is made easy with the Azure Identity library, which provides support for authenticating Azure SDK clients with their corresponding Azure services.

There are two options to enable AAD authentication. Note that if both have been set AzureMonitorExporterOptions will take precedence.

  1. Set your Credential to the AzureMonitorExporterOptions.

    var credential = new DefaultAzureCredential();
    
    var tracerProvider = Sdk.CreateTracerProviderBuilder()
        .AddAzureMonitorTraceExporter(options =>
        {
            options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
            options.Credential = credential;
        })
        .Build();
    
  2. Provide your Credential to the AddAzureMonitorExporter method.

    var credential = new DefaultAzureCredential();
    
    var tracerProvider = Sdk.CreateTracerProviderBuilder()
        .AddAzureMonitorTraceExporter(options => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000", credential)
        .Build();
    

Key concepts

Some key concepts for .NET include:

  • Overview of .NET distributed tracing: Distributed tracing is a diagnostic technique that helps engineers localize failures and performance issues within applications, especially those that may be distributed across multiple machines or processes.

  • Overview of Logging in .NET: .NET supports a logging API that works with a variety of built-in and third-party logging providers.

Some key concepts for Azure Monitor include:

  • IP Addresses used by Azure Monitor: This exporter sends traces to the configured Azure Monitor Resource using HTTPS. You might need to know IP addresses if the app or infrastructure that you're monitoring is hosted behind a firewall.

Some key concepts for OpenTelemetry include:

  • OpenTelemetry: 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: 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.

  • Tracing Signal: 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.

  • Sampling: 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.

  • Metric Signal: OpenTelemetry allows to record raw measurements or metrics with predefined aggregation and a set of attributes (dimensions).

  • Log Signal: A recording of an event. Typically the record includes a timestamp indicating when the event happened as well as other data that describes what happened, where it happened, etc.

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

Examples

Refer to Program.cs for a complete demo.

Log Scopes

Log scopes allow you to add additional properties to the logs generated by your application. Although the Azure Monitor Exporter does support scopes, this feature is off by default in OpenTelemetry. To leverage log scopes, you must explicitly enable them.

To include the scope with your logs, set OpenTelemetryLoggerOptions.IncludeScopes to true in your application's configuration:

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(logging =>
    {
        logging.AddAzureMonitorLogExporter(options => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");
        logging.IncludeScopes = true;
    });
});

When using ILogger scopes, use a List<KeyValuePair<string, object?>> or IReadOnlyList<KeyValue<string, object?>> as the state for best performance. All logs written within the context of the scope will include the specified information. Azure Monitor will add these scope values to the Log's CustomProperties.

List<KeyValuePair<string, object?>> scope =
[
    new("scopeKey", "scopeValue")
];

using (logger.BeginScope(scope))
{
    logger.LogInformation("Example message.");
}

In scenarios involving multiple scopes or a single scope with multiple key-value pairs, if duplicate keys are present, only the first occurrence of the key-value pair from the outermost scope will be recorded. However, when the same key is utilized both within a logging scope and directly in the log statement, the value specified in the log message template will take precedence.

Troubleshooting

The Azure Monitor exporter uses EventSource for its own internal logging. The exporter logs are available to any EventListener by opting into the source named "OpenTelemetry-AzureMonitor-Exporter".

OpenTelemetry also provides it's own self-diagnostics feature to collect internal logs. An example of this is available in our demo project here.

Next steps

For more information on Azure SDK, please refer to this website

Contributing

See CONTRIBUTING.md for details on contribution process.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on Azure.Monitor.OpenTelemetry.Exporter:

Package Downloads
Azure.Monitor.OpenTelemetry.AspNetCore

An OpenTelemetry .NET distro that exports to Azure Monitor

Altinn.App.Api

This class library holds all the API controllers used by a standard Altinn 3 App.

Genocs.Tracing

The tracing library to use Azure Service Bus.

Aksio.Cratis.Kernel.Server

Package Description

Reimaginate.Test.Framework

Package Description

GitHub repositories (13)

Showing the top 5 popular GitHub repositories that depend on Azure.Monitor.OpenTelemetry.Exporter:

Repository Stars
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
microsoft/dotnet-podcasts
.NET reference application shown at .NET Conf featuring ASP.NET Core, Blazor, .NET MAUI, Microservices, Orleans, Playwright, and more!
Squidex/squidex
Headless CMS and Content Managment Hub
phongnguyend/Practical.CleanArchitecture
Full-stack .Net 8 Clean Architecture (Microservices, Modular Monolith, Monolith), Blazor, Angular 18, React 18, Vue 3, BFF with YARP, Domain-Driven Design, CQRS, SOLID, Asp.Net Core Identity Custom Storage, OpenID Connect, Entity Framework Core, OpenTelemetry, SignalR, Hosted Services, Health Checks, Rate Limiting, Cloud Services (Azure, AWS, GCP).
Version Downloads Last updated
1.4.0-beta.2 15,866 10/11/2024
1.4.0-beta.1 58,116 7/16/2024
1.3.0 2,426,721 6/10/2024
1.3.0-beta.2 51,518 5/16/2024
1.3.0-beta.1 149,544 2/8/2024
1.2.0 2,052,910 1/24/2024
1.1.0 810,800 11/29/2023
1.0.0 1,066,119 9/20/2023
1.0.0-beta.14 190,375 8/9/2023
1.0.0-beta.13 240,904 7/14/2023
1.0.0-beta.12 152,880 6/6/2023
1.0.0-beta.11 446,238 5/10/2023
1.0.0-beta.10 105,559 4/11/2023
1.0.0-beta.9 204,347 3/14/2023
1.0.0-beta.8 49,207 3/7/2023
1.0.0-beta.7 102,194 2/6/2023
1.0.0-beta.6 117,796 1/9/2023
1.0.0-beta.5 92,769 11/3/2022
1.0.0-beta.4 400,797 10/6/2022
1.0.0-beta.3 1,164,141 10/5/2021
1.0.0-beta.2 122,362 3/5/2021