OpenTelemetry and Azure Monitor Exporter support#578
OpenTelemetry and Azure Monitor Exporter support#578rossgrambo wants to merge 6 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for using OpenTelemetry with Azure Monitor Exporter as an alternative to Application Insights for feature flag telemetry. The implementation uses structured logging instead of direct TelemetryClient calls, making it more flexible and aligned with modern .NET logging patterns.
Key changes:
- New
Microsoft.FeatureManagement.Telemetry.AzureMonitorpackage with OpenTelemetry-based telemetry - New test project
Tests.FeatureManagement.Telemetry.AzureMonitorwith comprehensive test coverage - New example application
VariantAndAzureMonitorDemodemonstrating the usage
Reviewed changes
Copilot reviewed 38 out of 91 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Microsoft.FeatureManagement.Telemetry.AzureMonitor/*.cs |
Core implementation of Azure Monitor telemetry using OpenTelemetry processors and structured logging |
src/Microsoft.FeatureManagement.Telemetry.AzureMonitor/*.csproj |
Package configuration with OpenTelemetry dependencies |
tests/Tests.FeatureManagement.Telemetry.AzureMonitor/*.cs |
Test suite covering telemetry logging and processor ordering |
examples/VariantAndAzureMonitorDemo/* |
Demo application showing migration from Application Insights to Azure Monitor |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return; | ||
| } | ||
|
|
||
| string targetingId = activity.Baggage.FirstOrDefault(t => t.Key == TargetingIdKey).Value; |
There was a problem hiding this comment.
Based on https://opentelemetry.io/docs/specs/semconv/feature-flags/feature-flags-events/#evaluation-event shouldn't this value already be a tag hence u could use that instead of baggage
There was a problem hiding this comment.
This code is solving a different problem. The idea is that we need to get the TargetingId onto other activities besides the feature evaluation event. For example
Incoming API Request (Activity 1 - TargetingHttpContextMiddleware sets TargetingId as baggage)
| Feature Evaluation event happens (TargetingId added as ActivityEvent tag)
| Request to other API (Activity 2)
| Response from other API (Activity 2 end - processor promotes baggage to tag)
| misc code
Returned result (Activity 1 end - processor promotes baggage to tag)
Now the Azure Monitor exporter will emit Activity 2 to the "dependencies" table (since it was an outgoing request) and include the custom dimension "TargetingId". Activity 1 is emitted to the "requests" table (with it's targeting id as well)
| /// <summary> | ||
| /// Listens to <see cref="Activity"/> events from feature management and sends them to Azure Monitor via structured logging. | ||
| /// </summary> | ||
| internal sealed class AzureMonitorEventPublisher : IDisposable |
There was a problem hiding this comment.
Wouldn't it be easier to implement this as otel processor/exporter?
There was a problem hiding this comment.
Good question.
The primary reason I went this route is that this pattern is already established and working in the ApplicationInsights event publisher. Additionally- we have better control over sampling here since the feature flag evaluation events can't be sampled for reliable results.
But yes, we could rewrite this as a processor in the future.
| return; | ||
| } | ||
|
|
||
| string targetingId = Activity.Current?.Baggage.FirstOrDefault(t => t.Key == TargetingIdKey).Value; |
There was a problem hiding this comment.
Based on https://opentelemetry.io/docs/specs/semconv/feature-flags/feature-flags-events/#evaluation-event shouldn't this value already be a tag hence u could use that instead of baggage
Why this PR?
This change adds support for using OpenTelemetry with Azure Monitor Exporter instead of Application Insights.
Visible Changes
Microsoft.FeatureManagement.Telemetry.AzureMonitor. This package looks very similar toMicrosoft.FeatureManagement.Telemetry.ApplicationInsightsand works similarly.VariantAndAzureMonitorDemo. It is a clone of VariantAndTelemetry demo but uses OTel and Azure Monitor.Migrating from .ApplicationInsights to .AzureMonitor
Package
Builder extension
Emitting events
*Note: Even better, use High-performance logging, like the
LoggerExtension.csin the example.