Microsoft.Extensions.Telemetry.Abstractions
8.6.0
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.Extensions.Telemetry.Abstractions --version 8.6.0
NuGet\Install-Package Microsoft.Extensions.Telemetry.Abstractions -Version 8.6.0
<PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="8.6.0" />
paket add Microsoft.Extensions.Telemetry.Abstractions --version 8.6.0
#r "nuget: Microsoft.Extensions.Telemetry.Abstractions, 8.6.0"
// Install Microsoft.Extensions.Telemetry.Abstractions as a Cake Addin #addin nuget:?package=Microsoft.Extensions.Telemetry.Abstractions&version=8.6.0 // Install Microsoft.Extensions.Telemetry.Abstractions as a Cake Tool #tool nuget:?package=Microsoft.Extensions.Telemetry.Abstractions&version=8.6.0
Microsoft.Extensions.Telemetry.Abstractions
This package contains common abstractions for high-level telemetry primitives. Here are the main features it provides:
- Enhanced Logging Capabilities
- Log Enrichment
- Latency Measurement
- HTTP Request Metadata Handling
Install the package
From the command-line:
dotnet add package Microsoft.Extensions.Telemetry.Abstractions
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="[CURRENTVERSION]" />
</ItemGroup>
Usage
Enhanced Logging Capabilities
The package includes a custom logging generator that enhances the default .NET logging capabilities by replacing the default generator. This generator automatically logs the contents of collections and offers advanced logging features, significantly improving the debugging and monitoring process.
[LoggerMessage(1, LogLevel.Information, "These are the contents of my dictionary: {temperature}")]
internal static partial void LogMyDictionary(ILogger<Program> logger, Dictionary<int, string> temperature);
It also adds the LogProperties
attribute which can be applied to an object parameter of a LoggerMessage
method. It introspects the passed-in object and automatically adds tags for all its properties. This leads to more informative logs without the need for manual tagging of each property.
[LoggerMessage(1, LogLevel.Information, "Detected a new temperature: {temperature}")]
internal static partial void LogNewTemperature(ILogger<Program> logger, [LogProperties] Temperature temperature);
internal record Temperature(double value, TemperatureUnit unit);
Log Enrichment
Logging data can be enriched by adding custom log enrichers to the service collection. This can be done using specific implementations or generic types.
// Using a specific implementation
builder.Services.AddLogEnricher(new CustomLogEnricher());
// Using a generic type
builder.Services.AddLogEnricher<AnotherLogEnricher>();
Create custom log enrichers by implementing the ILogEnricher
interface.
public class CustomLogEnricher : ILogEnricher
{
public void Enrich(IEnrichmentTagCollector collector)
{
// Add custom logic to enrich log data
collector.Add("CustomTag", "CustomValue");
}
}
Latency Measurement
To track latency in an application it is possible to register checkpoint, measure, and tag names using the following methods:
builder.Services.RegisterCheckpointNames("databaseQuery", "externalApiCall");
builder.Services.RegisterMeasureNames("responseTime", "processingTime");
builder.Services.RegisterTagNames("userId", "transactionId");
Implement the ILatencyDataExporter
to export latency data. This can be integrated with external systems or logging frameworks.
public class CustomLatencyDataExporter : ILatencyDataExporter
{
public async Task ExportAsync(LatencyData data, CancellationToken cancellationToken)
{
// Export logic here
}
}
Use the latency context to track performance metrics in your application.
public void YourMethod(ILatencyContextProvider contextProvider)
{
var context = contextProvider.CreateContext();
var checkpointToken = context.GetCheckpointToken("databaseQuery");
// Start measuring
context.AddCheckpoint(checkpointToken);
// Perform operations...
// End measuring
context.AddCheckpoint(checkpointToken);
// Optionally, record measures and tags
context.RecordMeasure(context.GetMeasureToken("responseTime"), measureValue);
context.SetTag(context.GetTagToken("userId"), "User123");
}
Http Request Metadata Handling
The IDownstreamDependencyMetadata
interface is designed to capture and store metadata about the downstream dependencies of an HTTP request. This is particularly useful for understanding external service dependencies and their impact on your application's performance and reliability.
The IOutgoingRequestContext
interface provides a mechanism for associating metadata with outgoing HTTP requests. This allows you to enrich outbound requests with additional information that can be used for logging, telemetry, and analysis.
Feedback & Contributing
We welcome feedback and contributions in our GitHub repo.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Compliance.Abstractions (>= 8.6.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.5)
- Microsoft.Extensions.Options (>= 8.0.2)
-
net6.0
- Microsoft.Extensions.Compliance.Abstractions (>= 8.6.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.5)
- Microsoft.Extensions.Options (>= 8.0.2)
-
net8.0
- Microsoft.Extensions.Compliance.Abstractions (>= 8.6.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.5)
- Microsoft.Extensions.Options (>= 8.0.2)
NuGet packages (20)
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Telemetry.Abstractions:
Package | Downloads |
---|---|
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions. |
|
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries. |
|
Microsoft.Extensions.Diagnostics.Testing
Hand-crafted fakes to make telemetry-related testing easier. |
|
Microsoft.Extensions.Diagnostics.ResourceMonitoring
Measures processor and memory usage. |
|
Microsoft.Extensions.Diagnostics.HealthChecks.Common
Health check implementations. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.Extensions.Telemetry.Abstractions:
Repository | Stars |
---|---|
open-telemetry/opentelemetry-dotnet
The OpenTelemetry .NET Client
|
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 28,562 | 11/12/2024 |
9.0.0-preview.9.24507.7 | 23,848 | 10/8/2024 |
9.0.0-preview.8.24460.1 | 25,964 | 9/10/2024 |
9.0.0-preview.7.24412.10 | 9,245 | 8/14/2024 |
9.0.0-preview.6.24353.1 | 8,659 | 7/10/2024 |
9.0.0-preview.5.24311.7 | 6,009 | 6/11/2024 |
9.0.0-preview.4.24271.2 | 9,347 | 5/21/2024 |
9.0.0-preview.3.24209.3 | 16,617 | 4/11/2024 |
9.0.0-preview.2.24157.4 | 4,396 | 3/12/2024 |
9.0.0-preview.1.24108.1 | 3,395 | 2/13/2024 |
8.10.0 | 723,686 | 10/8/2024 |
8.9.1 | 820,125 | 9/6/2024 |
8.9.0 | 57,452 | 9/5/2024 |
8.8.0 | 748,531 | 8/13/2024 |
8.7.0 | 1,096,612 | 7/10/2024 |
8.6.0 | 831,978 | 6/11/2024 |
8.5.0 | 993,368 | 5/14/2024 |
8.4.0 | 1,279,874 | 4/9/2024 |
8.3.0 | 646,293 | 3/12/2024 |
8.2.0 | 1,000,278 | 2/13/2024 |
8.1.0 | 468,033 | 1/9/2024 |
8.0.0 | 1,014,294 | 11/14/2023 |
8.0.0-rc.2.23510.2 | 32,997 | 10/10/2023 |
8.0.0-rc.1.23453.1 | 2,449 | 9/12/2023 |
8.0.0-preview.7.23407.5 | 3,095 | 8/8/2023 |
8.0.0-preview.6.23360.2 | 866 | 7/12/2023 |
8.0.0-preview.5.23308.3 | 2,886 | 6/14/2023 |
8.0.0-preview.4.23273.7 | 3,099 | 5/23/2023 |