Microsoft.Extensions.Telemetry.Abstractions 10.10.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);

The TagName attribute can be used to specify a custom tag name for each parameter or property. This is useful when you want to have more control over the naming of tags in your logs.

[LoggerMessage(1, LogLevel.Information, "My custom tag name: {my.custom.tagname}")]
public static partial void LogMyCustomTagName(
    this ILogger logger,
    [TagName("my.custom.tagname")] string name);

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.

Showing the top 20 packages that depend on Microsoft.Extensions.Telemetry.Abstractions.

Packages Downloads
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
122
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
124
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
126
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
129
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
145
Microsoft.Extensions.Resilience
Extensions to the Polly libraries to enrich telemetry with metadata and exception summaries.
149
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
125
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions
132
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
122
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
123
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
124
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
125
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
127
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
128
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
134
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
140

Version Downloads Last updated
10.10.0 15 09/09/2026
10.9.0 18 08/15/2026
10.8.0 25 07/16/2026
10.7.0 24 06/10/2026
10.6.0 32 05/14/2026
10.5.0 32 04/15/2026
10.4.0 42 03/12/2026
10.3.0 41 02/11/2026
10.2.0 47 01/14/2026
10.1.0 45 12/11/2025
10.0.0 73 11/12/2025
9.10.0 72 10/15/2025
9.9.0 96 09/11/2025
9.8.0 93 08/14/2025
9.7.0 102 07/09/2025
9.6.0 120 06/12/2025
9.5.0 107 05/16/2025
9.4.0 126 04/10/2025
9.3.0 115 04/01/2025
9.2.0 128 03/31/2025
9.1.0 108 04/01/2025
9.0.0 108 03/31/2025
9.0.0-preview.9.24507.7 132 04/01/2025
9.0.0-preview.8.24460.1 137 04/01/2025
9.0.0-preview.7.24412.10 131 03/31/2025
9.0.0-preview.6.24353.1 121 04/01/2025
9.0.0-preview.5.24311.7 113 04/01/2025
9.0.0-preview.4.24271.2 122 03/31/2025
9.0.0-preview.3.24209.3 124 04/01/2025
9.0.0-preview.2.24157.4 120 03/31/2025
9.0.0-preview.1.24108.1 148 03/31/2025
8.10.0 124 04/01/2025
8.9.1 112 03/31/2025
8.9.0 113 04/01/2025
8.8.0 112 04/01/2025
8.7.0 115 03/31/2025
8.6.0 107 04/01/2025
8.5.0 112 03/31/2025
8.4.0 119 03/31/2025
8.3.0 119 04/01/2025
8.2.0 139 04/01/2025
8.1.0 100 03/31/2025
8.0.0 111 04/01/2025
8.0.0-rc.2.23510.2 124 04/01/2025
8.0.0-rc.1.23453.1 110 03/31/2025
8.0.0-preview.7.23407.5 122 04/01/2025
8.0.0-preview.6.23360.2 120 04/01/2025
8.0.0-preview.5.23308.3 123 04/01/2025
8.0.0-preview.4.23273.7 115 04/01/2025