Uniphar.Platform.Telemetry 2.0.55

dotnet add package Uniphar.Platform.Telemetry --version 2.0.55
                    
NuGet\Install-Package Uniphar.Platform.Telemetry -Version 2.0.55
                    
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="Uniphar.Platform.Telemetry" Version="2.0.55" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Uniphar.Platform.Telemetry" Version="2.0.55" />
                    
Directory.Packages.props
<PackageReference Include="Uniphar.Platform.Telemetry" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Uniphar.Platform.Telemetry --version 2.0.55
                    
#r "nuget: Uniphar.Platform.Telemetry, 2.0.55"
                    
#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.
#:package Uniphar.Platform.Telemetry@2.0.55
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Uniphar.Platform.Telemetry&version=2.0.55
                    
Install as a Cake Addin
#tool nuget:?package=Uniphar.Platform.Telemetry&version=2.0.55
                    
Install as a Cake Tool

Uniphar.Platform.Telemetry

Latest Version: Nuget

Uniphar.Platform.Telemetry is a .NET library for enhanced telemetry, logging, and metrics collection. It is designed to be used as a NuGet package in .NET applications to provide structured logging and custom event telemetry.

Features

  • Custom Event Telemetry Client: Send custom events to your telemetry backend with structured data.
  • Ambient Properties Log Enricher: Automatically enriches log records with ambient properties for better traceability.
  • Non-Alerting Exceptions and Logs: Mark expected exceptions (or log explicitly with LogNonAlertingError/LogNonAlertingWarning) so the full log and stack trace stay visible but are tagged telemetry.non_alerting=true for exclusion from alerts.
  • Telemetry Extensions: Extension methods for easier integration with logging and telemetry frameworks.
  • Configurable Dependency Filter: Filter out specific HTTP error codes (401, 403, 409, etc.) from Azure resource dependency telemetry to prevent them from being recorded as failed dependencies in Application Insights.

Installation

Install via NuGet:

Install-Package Uniphar.Platform.Telemetry

Or using the .NET CLI:

dotnet add package Uniphar.Platform.Telemetry

Usage

Prerequisities/Exporters

Depending on the telemetry stack you're targetting, following configurations/environment variables are checked to determine which exporters to enable

  • APPLICATIONINSIGHTS_CONNECTION_STRING - to enable Azure Monitor (or supply directly via WithAppInsightsConnectionString)
  • OTEL_EXPORTER_OTLP_ENDPOINT - to enable OTLP (OpenTelemetry) generic flow

Both can be used at the same time.

Basic Setup

Register OpenTelemetry in your application's startup/configuration:

using Uniphar.Platform.Telemetry;

// Basic registration with default settings (filters out /health paths by default)
builder.RegisterOpenTelemetry("my-application").Build();

Advanced Configuration

Use the fluent API to configure exception filters and path exclusions:

using Uniphar.Platform.Telemetry;

// Mark expected exceptions as non-alerting: full log + stack trace are kept, tagged telemetry.non_alerting=true.
// Only the FIRST matching rule applies, so list the most specific rules first (a rule shadowed by an earlier
// unconditional rule for the same or a base exception type throws when registered).
var exceptionRules = new[]
{
    ExceptionHandlingRule.For<IOException>(
        e => e.Message.Contains("being used by another process"),
        new Dictionary<string, object?> { ["Category"] = "Restart" },
        setToLogLevel: LogLevel.Warning), // Error (default) or Warning
    ExceptionHandlingRule.For<ArgumentException>()
};

// Or log directly as non-alerting (supports message templates)
logger.LogNonAlertingError(ex, "Worker {WorkerId} restarting", workerId);
logger.LogNonAlertingWarning(ex, "Slow restart");

// Define paths to exclude from telemetry (e.g., health checks)
var pathsToFilterOutStartingWith = new[] { "/health", "/metrics", "/status" };

// Register with fluent API
builder.RegisterOpenTelemetry("my-application")
    .WithExceptionsFilters(exceptionRules)
    .WithFilterExclusion(pathsToFilterOutStartingWith)
    .Build();

Console Log Suppression

The Uniphar.Platform.Telemetry package removes all default logging providers (Console, Debug, EventSource) via ClearProviders() when Build() is called, regardless of build configuration. This prevents application logs from writing to stdout/stderr, eliminating duplicate data in ContainerLogsV2/ADX — all telemetry is exported directly via the configured OpenTelemetry exporter(s).

Log level filtering should be configured in your application's appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Azure": "Warning",
      "Azure.Core": "Warning",
      "Azure.Identity": "Warning"
    }
  }
}

Using the Fluent API

The RegisterOpenTelemetry method returns a TelemetryBuilder that allows you to chain configuration methods:

  • .WithExceptionsFilters(IEnumerable<ExceptionHandlingRule>): Mark matching exceptions as non-alerting (logs keep the full stack trace and get telemetry.non_alerting=true; alerts should exclude it). Can only be called once. Rule dimensions never override attributes already on the log, including ambient properties from WithProperties.
  • .WithDiagnosticLogging(bool): Write a [TrackEvent] line to stderr for every custom event, to confirm events are emitted
  • .WithFilterExclusion(IEnumerable<string>): Configure paths to exclude from successful request telemetry (defaults to /health)
  • .WithDependencyFilter(...): Configure HTTP dependency error filtering
  • .WithAppInsightsConnectionString(string): Supply the Application Insights connection string directly, bypassing the default APPLICATIONINSIGHTS_CONNECTION_STRING config/environment variable lookup
  • .Build(): Finalize and apply the telemetry configuration. It must be called last and only once; calling it twice throws, and host startup fails if it was never called

You can chain these methods in any order:

// With exception filters only
builder.RegisterOpenTelemetry("my-application")
    .WithExceptionsFilters(exceptionRules)
    .Build();

// With path exclusions only
builder.RegisterOpenTelemetry("my-application")
    .WithFilterExclusion(new[] { "/health", "/metrics" })
    .Build();

// Combining multiple configurations
builder.RegisterOpenTelemetry("my-application")
    .WithExceptionsFilters(exceptionRules)
    .WithFilterExclusion(new[] { "/health", "/metrics" })
    .WithDependencyFilter()
    .Build();

// Supply the Application Insights connection string directly
builder.RegisterOpenTelemetry("my-application")
    .WithAppInsightsConnectionString("InstrumentationKey=...;IngestionEndpoint=...")
    .Build();

Configurable HTTP Dependency Error Filtering

WithDependencyFilter lets you filter out specific HTTP error codes from Azure resource operations to prevent them from being recorded as failed dependencies in Application Insights. This is useful for scenarios where certain error codes are expected and should not trigger alerts. Calling WithDependencyFilter() without arguments uses DependencyFilterConfiguration.Default (409 for Storage and Service Bus).

Supported Azure Resource Namespaces

Rules target an Azure resource namespace, see AzureResourceNamespaces:

  • Storage (Microsoft.Storage) - Azure Storage (Blob, File Share, Queue, Table)
  • ContainerRegistry (Microsoft.ContainerRegistry) - Azure Container Registry
  • ServiceBus (Microsoft.ServiceBus) - Azure Service Bus
Configuration Examples
var config = new DependencyFilterConfiguration
{
    Rules =
    [
        new DependencyFilterRule
        {
            ResourceNamespace = AzureResourceNamespaces.Storage,
            StatusCodes = [409]
        },
        new DependencyFilterRule
        {
            ResourceNamespace = AzureResourceNamespaces.ContainerRegistry,
            StatusCodes = [401]
        }
    ]
};

builder.RegisterOpenTelemetry("my-application")
    .WithDependencyFilter(config)
    .Build();
How It Works

When a dependency call is made to a supported Azure resource and results in one of the configured HTTP status codes:

  1. The processor reads the Azure resource namespace from the activity's az.namespace (or azure.resource_provider.namespace) tag; activities without it are left alone
  2. It checks if there's a matching filter rule for that namespace
  3. If the activity's status code matches a configured code in the rule, the activity is marked as not recorded. The status code is taken from error.type when it is numeric (e.g. "409"), otherwise from http.response.status_code
  4. This prevents the failed dependency from appearing in your Application Insights telemetry

This is particularly useful for:

  • 409 Conflict: Expected when creating resources that already exist (Blob containers, File shares, etc.)
  • 401 Unauthorized: Expected during authentication retries or token refresh scenarios
  • 403 Forbidden: Expected when checking permissions or during role-based access control flows
Common Scenarios

Scenario 1: Filter all conflict errors from Azure Storage

.WithDependencyFilter(new DependencyFilterConfiguration
{
    Rules = [new() { ResourceNamespace = AzureResourceNamespaces.Storage, StatusCodes = [409] }]
})

Scenario 2: Filter authentication errors from external services

.WithDependencyFilter(new DependencyFilterConfiguration
{
    Rules =
    [
        new() { ResourceNamespace = AzureResourceNamespaces.ContainerRegistry, StatusCodes = [401, 403] },
        new() { ResourceNamespace = AzureResourceNamespaces.ServiceBus, StatusCodes = [401] }
    ]
})

Scenario 3: Comprehensive filtering for production environments

.WithDependencyFilter(new DependencyFilterConfiguration
{
    Rules =
    [
        new() { ResourceNamespace = AzureResourceNamespaces.Storage, StatusCodes = [409] },
        new() { ResourceNamespace = AzureResourceNamespaces.ContainerRegistry, StatusCodes = [401, 403, 409] },
        new() { ResourceNamespace = AzureResourceNamespaces.ServiceBus, StatusCodes = [401, 403] }
    ]
})

Using Custom Event Telemetry

How a custom event is emitted depends on the configured exporters:

  • Application Insights only: a log record at LogLevel.Critical (so it is not dropped by log level filtering). Make sure your logging configuration does not filter out Critical.
  • OTLP configured (alone or with Application Insights): both an activity span and a log record at LogLevel.Information.

Example usage in a class (properties with a null value are not emitted):

public class MyClass
{
    private readonly ICustomEventTelemetryClient _telemetry;

    public MyClass(ICustomEventTelemetryClient telemetry)
    {
        _telemetry = telemetry;
    }

    public void DoSomething()
    {
        _telemetry.TrackEvent("DoingSomething", new() { ["Property1"] = "Value" });
    }

    public async Task DoSomethingWithAmbientProperties()
    {
        // Use WithProperties to set ambient properties
        // All telemetry events within the current async context will have these additional properties (which are removed/disposed of after the using block).
        using (_telemetry.WithProperties(new Dictionary<string, string> { ["UserId"] = "12345", ["TenantId"] = "tenant-abc" }))
        {
            // All telemetry tracked within this scope will include UserId and TenantId
            _telemetry.TrackEvent("ProcessStarted", new() { ["Status"] = "Initiated" });
            await ProcessDataAsync();
            _telemetry.TrackEvent("ProcessCompleted", new() { ["Status"] = "Success" });
        }
    }

    private async Task ProcessDataAsync()
    {
        // This event will also include the ambient properties (UserId, TenantId)
        _telemetry.TrackEvent("DataProcessing", new() { ["RecordCount"] = "100" });
        await Task.Delay(100);
    }
}

Building

To build the project:

cd src/Uniphar.Platform.Telemetry
dotnet build

Testing

Unit tests are provided in the Uniphar.Platform.Telemetry.Tests project:

cd src/Uniphar.Platform.Telemetry.Tests
dotnet test

Integration tests (real telemetry sent to Dash0 and queried back) live in Uniphar.Platform.Telemetry.IntegrationTests, see its README. CD runs them before publishing.

Uniphar.Platform.Telemetry.Testing

A separate NuGet package with a Dash0 query client (Dash0TelemetryQueryClient) so your own integration tests can assert that spans and logs, such as non-alerting logs with telemetry.non_alerting=true, arrived in Dash0. See its README.

Project Structure

  • Uniphar.Platform.Telemetry/ - Main library source code
  • Uniphar.Platform.Telemetry.Testing/ - Test helpers package (Dash0 query client)
  • Uniphar.Platform.Telemetry.Tests/ - Unit tests
  • Uniphar.Platform.Telemetry.IntegrationTests/ - Dash0 integration tests

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.55 0 11/26/2026
2.0.50 1,752 11/16/2026
2.0.49 466 11/13/2026
2.0.46 3,227 10/20/2026
2.0.45 706 10/15/2026
2.0.44 473 10/13/2026
2.0.43 11,170 6/23/2026
2.0.42 332 6/19/2026
2.0.41 190 6/19/2026
2.0.40-pre1 316 6/17/2026
2.0.39-pre1 172 6/16/2026
2.0.38-pre1 147 6/16/2026
2.0.37-pre1 270 6/16/2026
2.0.36-pre1 144 6/16/2026
2.0.35-pre1 148 6/15/2026
2.0.34-pre1 144 6/12/2026
2.0.33 683 6/11/2026
2.0.32 192 6/10/2026
2.0.31 227 6/10/2026
2.0.30 180 6/9/2026
Loading failed