Asos.OpenTelemetry.Exporter.EventHubs 1.0.7-sampling0023

Prefix Reserved
This is a prerelease version of Asos.OpenTelemetry.Exporter.EventHubs.
dotnet add package Asos.OpenTelemetry.Exporter.EventHubs --version 1.0.7-sampling0023
                    
NuGet\Install-Package Asos.OpenTelemetry.Exporter.EventHubs -Version 1.0.7-sampling0023
                    
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="Asos.OpenTelemetry.Exporter.EventHubs" Version="1.0.7-sampling0023" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asos.OpenTelemetry.Exporter.EventHubs" Version="1.0.7-sampling0023" />
                    
Directory.Packages.props
<PackageReference Include="Asos.OpenTelemetry.Exporter.EventHubs" />
                    
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 Asos.OpenTelemetry.Exporter.EventHubs --version 1.0.7-sampling0023
                    
#r "nuget: Asos.OpenTelemetry.Exporter.EventHubs, 1.0.7-sampling0023"
                    
#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 Asos.OpenTelemetry.Exporter.EventHubs@1.0.7-sampling0023
                    
#: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=Asos.OpenTelemetry.Exporter.EventHubs&version=1.0.7-sampling0023&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Asos.OpenTelemetry.Exporter.EventHubs&version=1.0.7-sampling0023&prerelease
                    
Install as a Cake Tool

πŸ”„ Asos.OpenTelemetry.Exporter.EventHubs

NuGet Downloads

High-performance OpenTelemetry exporter for Azure Event Hubs, enabling direct streaming of OTLP telemetry data to Azure Event Hubs with enterprise-grade authentication and reliability. Perfect for custom telemetry pipelines, data lake ingestion, and multi-tenant observability architectures.

✨ Features

  • πŸš€ Direct EventHubs Streaming: Stream telemetry data directly to Azure Event Hubs
  • πŸ” Enterprise Authentication: SAS key and Managed Identity support with automatic token refresh
  • ⚑ High Performance: Optimized HttpProtobuf serialization with connection pooling
  • πŸ”„ Automatic Token Management: Built-in token caching and renewal
  • πŸ›‘οΈ Production Ready: Comprehensive error handling and retry mechanisms
  • πŸ“Š Multiple Telemetry Types: Support for traces, metrics, and logs
  • πŸŽ›οΈ Flexible Configuration: Easy integration with existing OpenTelemetry setups

πŸ“¦ Installation

dotnet add package Asos.OpenTelemetry.Exporter.EventHubs

πŸš€ Quick Start

using Asos.OpenTelemetry.Exporter.EventHubs;

var eventHubOptions = new EventHubOptions
{
    AuthenticationMode = AuthenticationMode.ManagedIdentity,
    EventHubFqdn = "your-namespace.servicebus.windows.net/your-hub"
};

// For metrics
services.AddOpenTelemetryMetrics(builder => builder
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
    .AddAspNetCoreInstrumentation()
    .AddRuntimeInstrumentation()
    .AddOtlpEventHubExporter(eventHubOptions));

// For traces  
services.AddOpenTelemetryTracing(builder => builder
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
    .AddAspNetCoreInstrumentation()
    .AddOtlpEventHubExporter(eventHubOptions));

SAS Key Authentication

var eventHubOptions = new EventHubOptions
{
    AuthenticationMode = AuthenticationMode.SasKey,
    KeyName = "RootManageSharedAccessKey",
    AccessKey = "your-shared-access-key-here",
    EventHubFqdn = "your-namespace.servicebus.windows.net/your-hub"
};

services.AddOpenTelemetryMetrics(builder => builder
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
    .AddAspNetCoreInstrumentation()
    .AddOtlpEventHubExporter(eventHubOptions));

πŸ—οΈ Complete Examples

ASP.NET Core Web Application

using Asos.OpenTelemetry.Exporter.EventHubs;
using OpenTelemetry.Resources;

var builder = WebApplication.CreateBuilder(args);

// Configure Event Hub options
var eventHubOptions = new EventHubOptions
{
    AuthenticationMode = AuthenticationMode.ManagedIdentity,
    EventHubFqdn = builder.Configuration.GetValue<string>("EventHubs:TelemetryEndpoint")!
};

// Add OpenTelemetry with Event Hubs export
builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics => metrics
        .SetResourceBuilder(ResourceBuilder.CreateDefault()
            .AddService(builder.Environment.ApplicationName)
            .AddAttributes(new Dictionary<string, object>
            {
                ["environment"] = builder.Environment.EnvironmentName,
                ["version"] = typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown"
            }))
        .AddAspNetCoreInstrumentation()
        .AddRuntimeInstrumentation()
        .AddHttpClientInstrumentation()
        .AddOtlpEventHubExporter(eventHubOptions))
    .WithTracing(tracing => tracing
        .SetResourceBuilder(ResourceBuilder.CreateDefault()
            .AddService(builder.Environment.ApplicationName))
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddEntityFrameworkCoreInstrumentation()
        .AddOtlpEventHubExporter(eventHubOptions));

var app = builder.Build();
app.Run();

Background Service / Worker

using Asos.OpenTelemetry.Exporter.EventHubs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Resources;

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureServices((context, services) =>
{
    var eventHubOptions = new EventHubOptions
    {
        AuthenticationMode = AuthenticationMode.ManagedIdentity,
        EventHubFqdn = context.Configuration.GetValue<string>("EventHubs:TelemetryEndpoint")!
    };

    services.AddOpenTelemetry()
        .WithMetrics(metrics => metrics
            .SetResourceBuilder(ResourceBuilder.CreateDefault()
                .AddService("BackgroundProcessor"))
            .AddRuntimeInstrumentation()
            .AddProcessInstrumentation()
            .AddMeter("BackgroundProcessor.Metrics")
            .AddOtlpEventHubExporter(eventHubOptions))
        .WithTracing(tracing => tracing
            .SetResourceBuilder(ResourceBuilder.CreateDefault()
                .AddService("BackgroundProcessor"))
            .AddSource("BackgroundProcessor.Traces")
            .AddOtlpEventHubExporter(eventHubOptions));

    services.AddHostedService<Worker>();
});

var host = builder.Build();
await host.RunAsync();

Console Application

using Asos.OpenTelemetry.Exporter.EventHubs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Resources;

var services = new ServiceCollection();

var eventHubOptions = new EventHubOptions
{
    AuthenticationMode = AuthenticationMode.SasKey,
    KeyName = Environment.GetEnvironmentVariable("EVENTHUB_KEY_NAME")!,
    AccessKey = Environment.GetEnvironmentVariable("EVENTHUB_ACCESS_KEY")!,
    EventHubFqdn = Environment.GetEnvironmentVariable("EVENTHUB_FQDN")!
};

services.AddOpenTelemetry()
    .WithMetrics(metrics => metrics
        .SetResourceBuilder(ResourceBuilder.CreateDefault()
            .AddService("ConsoleApp"))
        .AddMeter("ConsoleApp.Metrics")
        .AddOtlpEventHubExporter(eventHubOptions));

var serviceProvider = services.BuildServiceProvider();

// Your application logic here
Console.WriteLine("Telemetry streaming to Event Hubs...");
await Task.Delay(5000);

serviceProvider.Dispose();

πŸ” Authentication & Permissions

Managed Identity Setup

Using Azure CLI
# Create a managed identity
az identity create --name myapp-identity --resource-group myResourceGroup

# Get the principal ID
PRINCIPAL_ID=$(az identity show --name myapp-identity --resource-group myResourceGroup --query principalId -o tsv)

# Assign Event Hubs Data Sender role
az role assignment create \
    --assignee $PRINCIPAL_ID \
    --role "Azure Event Hubs Data Sender" \
    --scope /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace-name}

# For App Service or Container Apps, assign the identity
az webapp identity assign --name myapp --resource-group myResourceGroup --identities /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myapp-identity
Using Azure PowerShell
# Create managed identity
$identity = New-AzUserAssignedIdentity -ResourceGroupName "myResourceGroup" -Name "myapp-identity"

# Assign Event Hubs Data Sender role
New-AzRoleAssignment -ObjectId $identity.PrincipalId `
    -RoleDefinitionName "Azure Event Hubs Data Sender" `
    -Scope "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace-name}"

SAS Key Setup

# Get connection string from Event Hub
az eventhubs eventhub authorization-rule keys list \
    --resource-group myResourceGroup \
    --namespace-name myNamespace \
    --eventhub-name myHub \
    --name RootManageSharedAccessKey

βš™οΈ Configuration Options

EventHubOptions Properties

Property Type Required Description
EventHubFqdn string βœ… Fully qualified domain name of the Event Hub endpoint
AuthenticationMode AuthenticationMode βœ… Authentication method (SasKey or ManagedIdentity)
KeyName string ⚠️* SAS key name (required for SAS authentication)
AccessKey string ⚠️* SAS access key (required for SAS authentication)
TokenCacheDurationMinutes int ❌ Token cache duration in minutes (default: 50)

* Required only when using AuthenticationMode.SasKey

Authentication Modes Comparison

Feature SAS Key Managed Identity
Security ⚠️ Key rotation required βœ… Azure-managed
Setup Complexity βœ… Simple ⚠️ Role assignments needed
Local Development βœ… Easy testing ⚠️ Requires Azure auth
Production ⚠️ Key management βœ… Recommended
Audit Trail ⚠️ Limited βœ… Full Azure AD logs

Configuration via appsettings.json

{
  "EventHubs": {
    "TelemetryEndpoint": "telemetry-namespace.servicebus.windows.net/telemetry-hub",
    "AuthenticationMode": "ManagedIdentity"
  },
  "Logging": {
    "LogLevel": {
      "Asos.OpenTelemetry.Exporter.EventHubs": "Information"
    }
  }
}

With configuration binding:

var eventHubOptions = new EventHubOptions();
builder.Configuration.GetSection("EventHubs").Bind(eventHubOptions);

πŸ—οΈ Architecture & Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Application   β”‚    β”‚  OTLP Exporter   β”‚    β”‚  Azure Event    β”‚
β”‚   Telemetry     β”œβ”€β”€β”€β–Ίβ”‚  (HttpProtobuf)  β”œβ”€β”€β”€β–Ίβ”‚     Hubs        β”‚
β”‚  (Traces/Metrics)β”‚    β”‚                  β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ Authentication   β”‚    β”‚   Downstream    β”‚
                       β”‚ Token Manager    β”‚    β”‚  Consumers      β”‚
                       β”‚  (SAS/Managed)   β”‚    β”‚ (Stream Analyticsβ”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  Data Factory)  β”‚
                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🚨 Troubleshooting

Common Issues & Solutions

Authentication Failures

Issue: 401 Unauthorized errors

# Check role assignments
az role assignment list --assignee {principal-id} --all

# Verify Event Hub exists
az eventhubs eventhub show --name {hub-name} --namespace-name {namespace}

Solution:

// Enable detailed logging
builder.Logging.AddFilter("Asos.OpenTelemetry.Exporter.EventHubs", LogLevel.Debug);
Connection Issues

Issue: ServiceUnavailable or timeout errors

// Configure retry options
services.Configure<EventHubOptions>(options =>
{
    options.TokenCacheDurationMinutes = 30; // Reduce cache duration
});

// Add custom HttpClient configuration
services.ConfigureHttpClientDefaults(http =>
{
    http.ConfigureHttpClient(client =>
    {
        client.Timeout = TimeSpan.FromSeconds(30);
    });
});
Token Expiration

Issue: Intermittent 401 errors after running for extended periods

// Monitor token refresh
builder.Logging.AddFilter("Asos.OpenTelemetry.Exporter.EventHubs.Tokens", LogLevel.Information);

Performance Optimization

High-Throughput Scenarios
// Optimize batch settings
services.AddOpenTelemetryMetrics(metrics => metrics
    .AddOtlpEventHubExporter(eventHubOptions, otlpOptions =>
    {
        otlpOptions.BatchExportProcessorOptions.MaxExportBatchSize = 512;
        otlpOptions.BatchExportProcessorOptions.ExportTimeoutMilliseconds = 10000;
        otlpOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds = 2000;
    }));
Memory Management
// Configure bounded memory usage
services.Configure<EventHubOptions>(options =>
{
    options.TokenCacheDurationMinutes = 45; // Balance between performance and memory
});

πŸ“Š Monitoring & Observability

Built-in Metrics

The exporter exposes internal metrics for monitoring:

services.AddOpenTelemetryMetrics(metrics => metrics
    .AddMeter("Asos.OpenTelemetry.Exporter.EventHubs") // Internal exporter metrics
    .AddYourApplicationMeters());

Available metrics:

  • eventhubs.export.duration - Export operation duration
  • eventhubs.export.batch_size - Exported batch sizes
  • eventhubs.auth.token_refresh - Token refresh operations
  • eventhubs.export.errors - Export error counts by type

Health Checks

services.AddHealthChecks()
    .AddEventHubsExporter("EventHubsExporter", eventHubOptions);

Application Insights Integration

// Dual export to both Event Hubs and Application Insights
services.AddOpenTelemetryTracing(tracing => tracing
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
    .AddAspNetCoreInstrumentation()
    .AddOtlpEventHubExporter(eventHubOptions)  // Custom pipeline
    .AddApplicationInsightsTraceExporter());   // Standard monitoring

πŸ”§ Advanced Usage

Custom Event Hub Configuration

services.Configure<EventHubOptions>(options =>
{
    options.EventHubFqdn = "custom-namespace.servicebus.windows.net/telemetry-hub";
    options.AuthenticationMode = AuthenticationMode.ManagedIdentity;
    options.TokenCacheDurationMinutes = 45;
    
    // Custom properties for downstream processing
    options.CustomProperties = new Dictionary<string, string>
    {
        ["environment"] = "production",
        ["region"] = "westus2",
        ["version"] = "1.2.3"
    };
});

Multi-tenant Scenarios

// Route different tenants to different Event Hubs
services.AddKeyedSingleton("tenant-a", (sp, key) => new EventHubOptions
{
    AuthenticationMode = AuthenticationMode.ManagedIdentity,
    EventHubFqdn = "tenant-a-namespace.servicebus.windows.net/telemetry"
});

services.AddKeyedSingleton("tenant-b", (sp, key) => new EventHubOptions  
{
    AuthenticationMode = AuthenticationMode.ManagedIdentity,
    EventHubFqdn = "tenant-b-namespace.servicebus.windows.net/telemetry"
});

Integration with Stream Analytics

Event Hubs data can be consumed by Azure Stream Analytics for real-time processing:

-- Stream Analytics Query Example
SELECT 
    ResourceAttributes.['service.name'] as ServiceName,
    SpanName,
    Duration,
    StatusCode,
    System.Timestamp() as ProcessedTime
FROM TelemetryInput
WHERE StatusCode >= 400

🎯 Use Cases & Patterns

Data Lake Ingestion

Stream all telemetry to Event Hubs β†’ Azure Stream Analytics β†’ Azure Data Lake for long-term analytics

Real-time Alerting

Stream critical telemetry β†’ Event Hubs β†’ Azure Functions β†’ Custom alerting logic

Multi-Region Aggregation

Multiple regions β†’ Regional Event Hubs β†’ Central processing β†’ Global dashboards

Compliance & Audit

All telemetry β†’ Event Hubs β†’ Compliant storage with data sovereignty requirements


πŸ“ž Support & Contributing

Built with ❀️ by ASOS Engineering - powering observability for millions of requests daily.

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 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
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
1.0.7-sampling0023 420 7/21/2025
1.0.7-sampling0022 408 7/21/2025
1.0.7-sampling0019 315 7/20/2025
1.0.4 18,238 2/14/2025
1.0.3 21,208 6/13/2024
1.0.2 5,367 4/17/2024
1.0.1 715 4/12/2024
1.0.0 16,110 10/20/2023
0.2.1 1,900 8/22/2023
0.1.2 5,981 9/23/2022
0.1.1 454 9/21/2022