Skip to content

Users/mbarbour/update otel extention#634

Open
MattB-msft wants to merge 5 commits into
mainfrom
users/mbarbour/UpdateOTELExtention
Open

Users/mbarbour/update otel extention#634
MattB-msft wants to merge 5 commits into
mainfrom
users/mbarbour/UpdateOTELExtention

Conversation

@MattB-msft

Copy link
Copy Markdown
Member

This pull request enhances the OpenTelemetry (OTEL) integration in the AgentOtelExtension class by improving how HTTP headers are captured and tagged, simplifying telemetry source naming, and enabling Azure Monitor exporter support. The main changes focus on making telemetry more consistent and secure, while also streamlining configuration for Azure monitoring.

Key improvements include:

HTTP Header Extraction and Tagging:

  • Introduced two overloaded ExtractHeadersForOTEL helper methods to consistently extract and tag HTTP request and response headers (excluding "Authorization") as OTEL activity tags. This replaces previous inline logic and ensures headers are always formatted as array tags compatible with OTEL exporters. [1]], [2]], [3]])
  • Updated all relevant tracing and HTTP client enrichment callbacks to use the new ExtractHeadersForOTEL methods, ensuring consistent header tagging for both requests and responses. [1]], [2]])

Telemetry Source Naming Consistency:

  • Standardized usage to AgentsTelemetry.SourceName and AgentsTelemetry.SourceVersion throughout the configuration, removing references to the older AgentTelemetry.ServiceName and AgentTelemetry.ServiceVersion. This ensures all metrics and traces are attributed to the correct source. [1]], [2]])

Azure Monitor Exporter Enablement:

Other Cleanups:

  • Removed commented-out and redundant code related to header tagging and Azure Monitor exporter setup. [1]], [2]])

These changes improve the observability and maintainability of telemetry data in .NET agents, particularly around HTTP traffic and cloud monitoring integration.

@github-actions github-actions Bot added the Samples Changes to Samples label Jun 20, 2026
Removed Azure Monitor exporter configuration and added attributes for service instance ID and telemetry SDK language.
@MattB-msft MattB-msft marked this pull request as ready for review June 20, 2026 23:12
@MattB-msft MattB-msft requested a review from Copilot June 20, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the .NET OTEL sample’s AgentOtelExtension to standardize telemetry source naming and to consistently extract HTTP headers into OTEL activity tags via new helper methods.

Changes:

  • Switched resource/service naming and provider configuration to use AgentsTelemetry.SourceName/SourceVersion.
  • Added ExtractHeadersForOTEL helper overloads and updated ASP.NET Core + HttpClient enrich callbacks to use them.
  • Simplified configured sources/meters and removed older inline header-tagging logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// as "HeaderName=value1,value2" strings. The headers are then added to the activity as an array tag,
/// which is compatible with OpenTelemetry exporters that support array-of-primitive attributes.
/// </remarks>
private static void ExtractHeadersForOTEL(System.Diagnostics.Activity activity, HttpHeaders? request, string tagName)
/// as "HeaderName=value1,value2" strings. The headers are then added to the activity as an array tag,
/// which is compatible with OpenTelemetry exporters that support array-of-primitive attributes.
/// </remarks>
private static void ExtractHeadersForOTEL(System.Diagnostics.Activity activity, IHeaderDictionary? request, string tagName)
Comment thread samples/dotnet/otel/AgentOtelExtension.cs Outdated
Comment thread samples/dotnet/otel/AgentOtelExtension.cs Outdated
Comment on lines 37 to 41
.AddSource(
"Microsoft.AspNetCore",
"System.Net.Http",
AgentsTelemetry.SourceName,
AgentTelemetry.ServiceName
AgentsTelemetry.SourceName
)
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddMeter(AgentsTelemetry.SourceName, AgentTelemetry.ServiceName)
.AddMeter(AgentsTelemetry.SourceName)
Comment on lines 26 to 30
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(
serviceName: AgentTelemetry.ServiceName,
serviceVersion: AgentTelemetry.ServiceVersion
serviceName: AgentsTelemetry.SourceName,
serviceVersion: AgentsTelemetry.SourceVersion
)
MattB-msft and others added 2 commits June 20, 2026 16:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Samples Changes to Samples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants