Users/mbarbour/update otel extention#634
Open
MattB-msft wants to merge 5 commits into
Open
Conversation
Removed Azure Monitor exporter configuration and added attributes for service instance ID and telemetry SDK language.
Contributor
There was a problem hiding this comment.
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
ExtractHeadersForOTELhelper 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 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 | ||
| ) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the OpenTelemetry (OTEL) integration in the
AgentOtelExtensionclass 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:
ExtractHeadersForOTELhelper 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]])ExtractHeadersForOTELmethods, ensuring consistent header tagging for both requests and responses. [1]], [2]])Telemetry Source Naming Consistency:
AgentsTelemetry.SourceNameandAgentsTelemetry.SourceVersionthroughout the configuration, removing references to the olderAgentTelemetry.ServiceNameandAgentTelemetry.ServiceVersion. This ensures all metrics and traces are attributed to the correct source. [1]], [2]])Azure Monitor Exporter Enablement:
APPLICATIONINSIGHTS_CONNECTION_STRINGis present in configuration, making integration with Azure monitoring seamless. ([samples/dotnet/otel/AgentOtelExtension.csL107-R165])Other Cleanups:
These changes improve the observability and maintainability of telemetry data in .NET agents, particularly around HTTP traffic and cloud monitoring integration.