Skip to content

Fix server.address telemetry to use host only per OpenTelemetry semantic conventions#6742

Merged
eiriktsarpalis merged 2 commits intomainfrom
copilot/fix-6741
Aug 22, 2025
Merged

Fix server.address telemetry to use host only per OpenTelemetry semantic conventions#6742
eiriktsarpalis merged 2 commits intomainfrom
copilot/fix-6741

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 22, 2025

OpenTelemetry semantic conventions specify that server.address should contain only the host portion of a URI (e.g., "localhost"), but the current implementation was incorrectly including the full URI with scheme, port, and path (e.g., "http://localhost:12345/something").

Changes made:

  • Updated OpenTelemetryChatClient to use Uri.Host instead of Uri.GetLeftPart(UriPartial.Path) for server address extraction
  • Updated OpenTelemetryEmbeddingGenerator to use Uri.Host instead of Uri.GetLeftPart(UriPartial.Path) for endpoint address extraction
  • Updated corresponding tests to expect "localhost" instead of "http://localhost:12345/something"

Before:

_serverAddress = metadata.ProviderUri?.GetLeftPart(UriPartial.Path);
// Results in: "http://localhost:12345/something"

After:

_serverAddress = metadata.ProviderUri?.Host;
// Results in: "localhost"

This ensures compliance with the OpenTelemetry semantic conventions for server attributes and provides consistent telemetry data that aligns with observability best practices.

Fixes #6741.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1oavsblobprodcus350.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • 37bvsblobprodcus311.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • 6s7vsblobprodcus313.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • 8xbvsblobprodcus382.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • ckzvsblobprodcus347.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • e7bvsblobprodcus348.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • k0ivsblobprodcus356.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • n3kvsblobprodcus335.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • sqdvsblobprodcus333.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/extensions/extensions/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /p:TreatWarningsAsErrors=false /p:ContinuousIntegrationBuild=false /home/REDACTED/work/extensions/extensions/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/extensions/extensions/artifacts/toolset/9.0.0-beta.25415.3.txt (dns block)
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • v53vsblobprodcus320.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • vwvvsblobprodcus334.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)
  • yluvsblobprodcus367.vsblob.vsassets.io
    • Triggering command: dotnet test test/Libraries/Microsoft.Extensions.AI.Tests/Microsoft.Extensions.AI.Tests.csproj -t (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Microsoft Reviewers: Open in CodeFlow

…tic conventions

Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Copilot AI changed the title [WIP] [MEAI] server.address in telemetry is wrong Fix server.address telemetry to use host only per OpenTelemetry semantic conventions Aug 22, 2025
Copilot AI requested a review from JamesNK August 22, 2025 04:50
@JamesNK JamesNK marked this pull request as ready for review August 22, 2025 04:51
Copilot AI review requested due to automatic review settings August 22, 2025 04:51
@JamesNK JamesNK requested a review from a team as a code owner August 22, 2025 04:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes the implementation of server.address telemetry to comply with OpenTelemetry semantic conventions by using only the host portion of URIs instead of the full URI path.

  • Updated telemetry attribute extraction to use Uri.Host instead of Uri.GetLeftPart(UriPartial.Path)
  • Modified corresponding tests to expect "localhost" instead of "http://localhost:12345/something"

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs Updated server address extraction to use host only
src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs Updated endpoint address extraction to use host only
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs Updated test assertion to expect host-only server address
test/Libraries/Microsoft.Extensions.AI.Tests/Embeddings/OpenTelemetryEmbeddingGeneratorTests.cs Updated test assertion to expect host-only server address

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@eiriktsarpalis eiriktsarpalis merged commit 43bde7f into main Aug 22, 2025
6 checks passed
@eiriktsarpalis eiriktsarpalis deleted the copilot/fix-6741 branch August 22, 2025 09:56
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEAI] server.address in telemetry is wrong

4 participants