Microsoft.Extensions.Telemetry 9.0.0-preview.3.24209.3

Prefix Reserved
This is a prerelease version of Microsoft.Extensions.Telemetry.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Microsoft.Extensions.Telemetry --version 9.0.0-preview.3.24209.3                
NuGet\Install-Package Microsoft.Extensions.Telemetry -Version 9.0.0-preview.3.24209.3                
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="Microsoft.Extensions.Telemetry" Version="9.0.0-preview.3.24209.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.Extensions.Telemetry --version 9.0.0-preview.3.24209.3                
#r "nuget: Microsoft.Extensions.Telemetry, 9.0.0-preview.3.24209.3"                
#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 Microsoft.Extensions.Telemetry as a Cake Addin
#addin nuget:?package=Microsoft.Extensions.Telemetry&version=9.0.0-preview.3.24209.3&prerelease

// Install Microsoft.Extensions.Telemetry as a Cake Tool
#tool nuget:?package=Microsoft.Extensions.Telemetry&version=9.0.0-preview.3.24209.3&prerelease                

Microsoft.Extensions.Telemetry

This library provides advanced logging and telemetry enrichment capabilities for .NET applications. It allows for detailed and configurable enrichment of log entries, along with enhanced latency monitoring and logging features. It is built for applications needing sophisticated telemetry and logging insights.

Install the package

From the command-line:

dotnet add package Microsoft.Extensions.Telemetry

Or directly in the C# project file:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.Telemetry" Version="[CURRENTVERSION]" />
</ItemGroup>

Usage

Service Log Enrichment

Enriches logs with application-specific information based on ApplicationMetadata information. The bellow calls will add the service log enricher to the service collection.

// Add service log enricher with default settings
builder.Services.AddServiceLogEnricher();

// Or configure with options
builder.Services.AddServiceLogEnricher(options =>
{
    options.ApplicationName = true;
    options.BuildVersion = true;
    options.DeploymentRing = true;
    options.EnvironmentName = true;
});

Latency Monitoring

Provides tools for latency data collection and export. The bellow example uses the built-in Console exporter, but custom exporters can be created by implementing the ILatencyDataExporter interface.

// Add latency console data exporter with configuration
builder.Services.AddConsoleLatencyDataExporter(options =>
{
    options.OutputCheckpoints = true;
    options.OutputMeasures = true;
    options.OutputTags = true;
});

In order for the latency data to be exported, a call to ILatencyDataExporter.ExportAsync() is required. This can either be called manually, or by using the Request Latency Middleware inside the Microsoft.AspNetCore.Diagnostics.Middleware package by adding:

// Add Latency Context
builder.Services.AddLatencyContext();

// Add Checkpoints, Measures, Tags
builder.Services.RegisterCheckpointNames("databaseQuery", "externalApiCall");
builder.Services.RegisterMeasureNames("responseTime", "processingTime");
builder.Services.RegisterTagNames("userId", "transactionId");

// Add Console Latency exporter.
builder.Services.AddConsoleLatencyDataExporter();
// Optionally add custom exporters.
builder.Services.AddSingleton<ILatencyDataExporter, MyCustomExporter>();

// Add Request latency telemetry.
builder.Services.AddRequestLatencyTelemetry();

// ...

// Add Request Latency Middleware which will automatically call ExportAsync on all registered latency exporters.
app.UseRequestLatencyTelemetry();

Logging Enhancements

Offers additional logging capabilities like stack trace capturing, exception message inclusion, and log redaction.

// Enable log enrichment.
builder.Logging.EnableEnrichment(options =>
{
    options.CaptureStackTraces = true;
    options.IncludeExceptionMessage = true;
    options.MaxStackTraceLength = 500;
    options.UseFileInfoForStackTraces = true;
});

builder.Services.AddServiceLogEnricher(); // <- This call is required in order for the enricher to be added into the service collection.

// Enable log redaction
builder.Logging.EnableRedaction(options =>
{
    options.ApplyDiscriminator = true;
});

builder.Services.AddRedaction(); // <- This call is required in order for the redactor provider to be added into the service collection.

Feedback & Contributing

We welcome feedback and contributions in our GitHub repo.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Telemetry:

Package Downloads
Microsoft.Extensions.Http.Diagnostics

Telemetry support for HTTP Client.

Neon.Service

Service library supporting application deployment as containers as well as in-process for testing

Tanka.GraphQL.Server

GraphQL Query, Mutation and Subscription library

Microsoft.AspNetCore.Diagnostics.Middleware

ASP.NET Core middleware for collecting high-quality telemetry.

Neon.Temporal

Useful classes and extensions for Temporal

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Microsoft.Extensions.Telemetry:

Repository Stars
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
Version Downloads Last updated
9.0.0 27,047 11/12/2024
9.0.0-preview.9.24507.7 20,877 10/8/2024
9.0.0-preview.8.24460.1 16,752 9/10/2024
9.0.0-preview.7.24412.10 5,732 8/14/2024
9.0.0-preview.6.24353.1 4,834 7/10/2024
9.0.0-preview.5.24311.7 5,063 6/11/2024
9.0.0-preview.4.24271.2 6,157 5/21/2024
9.0.0-preview.3.24209.3 7,634 4/11/2024
9.0.0-preview.2.24157.4 3,461 3/12/2024
9.0.0-preview.1.24108.1 2,021 2/13/2024
8.10.0 596,062 10/8/2024
8.9.1 670,902 9/6/2024
8.9.0 42,173 9/5/2024
8.8.0 606,722 8/13/2024
8.7.0 889,727 7/10/2024
8.6.0 658,235 6/11/2024
8.5.0 779,716 5/14/2024
8.4.0 1,169,512 4/9/2024
8.3.0 514,975 3/12/2024
8.2.0 862,808 2/13/2024
8.1.0 386,468 1/9/2024
8.0.0 902,001 11/14/2023
8.0.0-rc.2.23510.2 5,154 10/10/2023
8.0.0-rc.1.23453.1 1,784 9/12/2023
8.0.0-preview.7.23407.5 1,323 8/8/2023
8.0.0-preview.6.23360.2 732 7/12/2023
8.0.0-preview.5.23308.3 2,857 6/14/2023
8.0.0-preview.4.23273.7 2,689 5/23/2023