Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 8, 2025

This PR adds support for configuring OpenTelemetryChatClient.EnableSensitiveData and automatically registers the Microsoft.Extensions.AI (MEAI) telemetry source with OpenTelemetry when using the Ollama chat client integration.

Changes Made

New Method Overloads

Added new overloads to AddChatClient and AddKeyedChatClient methods that accept an Action<OpenTelemetryChatClient> delegate for configuration:

// Configure EnableSensitiveData for sensitive data logging
builder.AddOllamaApiClient("ollama")
    .AddChatClient(otel => otel.EnableSensitiveData = true);

// Works with keyed services too
builder.AddKeyedOllamaApiClient("key", "ollama")
    .AddKeyedChatClient(otel => otel.EnableSensitiveData = true);

Automatic Telemetry Source Registration

The integration now automatically registers the "Experimental.Microsoft.Extensions.AI" telemetry source with OpenTelemetry when using any of the AddChatClient methods. This enables proper distributed tracing for AI operations without requiring manual configuration.

Enhanced OpenTelemetry Integration

  • Updated CreateInnerChatClient to pass the correct source name to the OpenTelemetryChatClient constructor
  • Added AddTelemetrySource helper method to register the MEAI telemetry source
  • Added OpenTelemetry.Extensions.Hosting package reference for proper OpenTelemetry integration

Exposed DisableTracing Property

  • Changed DisableTracing property on OllamaSharpSettings from internal to public visibility to allow external configuration of tracing behavior

Comprehensive Testing

Added tests covering:

  • Configuring EnableSensitiveData with both keyed and non-keyed clients
  • Custom service key scenarios
  • Backward compatibility (existing methods work unchanged)
  • Default behavior verification

Documentation Updates

Updated the README.md to include examples of how to configure OpenTelemetry settings and explain the automatic telemetry source registration.

Backward Compatibility

All existing method signatures remain unchanged. The new configuration capability is provided through additional overloads, making this a non-breaking change.

Fixes #842.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 9, 2025 00:02
…ta and MEAI telemetry sources

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Copilot AI changed the title [WIP] Update AspireOllamaChatClientExtensions.AddChatClient to allow configuring sensitive data Add support for configuring OpenTelemetryChatClient.EnableSensitiveData and MEAI telemetry sources Sep 9, 2025
Copilot AI requested a review from aaronpowell September 9, 2025 00:26
Copilot finished work on behalf of aaronpowell September 9, 2025 00:26
@davidfowl
Copy link
Contributor

@copilot Expose DisableTracing on OllamaSharpSettings pubicly.

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 9, 2025

@copilot Expose DisableTracing on OllamaSharpSettings pubicly.

Done. Changed the DisableTracing property from internal to public visibility on the OllamaSharpSettings class. (9a3d2c2)

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:

  • dnceng.pkgs.visualstudio.com
    • Triggering command: dotnet build src/CommunityToolkit.Aspire.OllamaSharp/CommunityToolkit.Aspire.OllamaSharp.csproj (dns block)
    • Triggering command: dotnet test tests/CommunityToolkit.Aspire.OllamaSharp.Tests/CommunityToolkit.Aspire.OllamaSharp.Tests.csproj --logger trx --verbosity normal (dns block)

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

Copilot AI changed the title Add support for configuring OpenTelemetryChatClient.EnableSensitiveData and MEAI telemetry sources Add support for configuring OpenTelemetryChatClient.EnableSensitiveData, MEAI telemetry sources, and expose DisableTracing property Sep 9, 2025
Copilot AI requested a review from davidfowl September 9, 2025 05:26
Copilot finished work on behalf of davidfowl September 9, 2025 05:26
@aaronpowell aaronpowell marked this pull request as ready for review September 11, 2025 06:04
Copilot AI review requested due to automatic review settings September 11, 2025 06:04
Copy link
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 enhances the OllamaSharp integration by adding support for configuring OpenTelemetry settings, specifically EnableSensitiveData, and automatically registering Microsoft.Extensions.AI telemetry sources for better distributed tracing.

  • Added new method overloads for AddChatClient and AddKeyedChatClient that accept OpenTelemetry configuration delegates
  • Automatically registers the Microsoft.Extensions.AI telemetry source with OpenTelemetry
  • Exposed the DisableTracing property on OllamaSharpSettings from internal to public visibility

Reviewed Changes

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

Show a summary per file
File Description
AspireOllamaChatClientExtensions.cs Added new method overloads for OpenTelemetry configuration and automatic telemetry source registration
OllamaSharpSettings.cs Changed DisableTracing property visibility from internal to public
CommunityToolkit.Aspire.OllamaSharp.csproj Added OpenTelemetry.Extensions.Hosting package reference
README.md Added documentation for OpenTelemetry configuration
OllamaSharpIChatClientTests.cs Added comprehensive tests for new OpenTelemetry configuration functionality

@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
CommunityToolkit.Aspire.EventStore 100% 100% 46
CommunityToolkit.Aspire.GoFeatureFlag 100% 97% 74
CommunityToolkit.Aspire.Hosting.ActiveMQ 79% 40% 100
CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.Adminer 73% 50% 20
CommunityToolkit.Aspire.Hosting.Azure.Dapr 63% 47% 982
CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis 97% 88% 36
CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder 100% 100% 22
CommunityToolkit.Aspire.Hosting.Bun 82% 71% 54
CommunityToolkit.Aspire.Hosting.Dapr 62% 50% 878
CommunityToolkit.Aspire.Hosting.DbGate 94% 50% 18
CommunityToolkit.Aspire.Hosting.Deno 84% 75% 72
CommunityToolkit.Aspire.Hosting.EventStore 94% 100% 18
CommunityToolkit.Aspire.Hosting.GoFeatureFlag 93% 50% 18
CommunityToolkit.Aspire.Hosting.Golang 87% 70% 28
CommunityToolkit.Aspire.Hosting.Java 69% 72% 120
CommunityToolkit.Aspire.Hosting.k6 58% 12% 20
CommunityToolkit.Aspire.Hosting.LavinMQ 78% 50% 18
CommunityToolkit.Aspire.Hosting.LavinMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.MailPit 91% 50% 14
CommunityToolkit.Aspire.Hosting.McpInspector 89% 55% 148
CommunityToolkit.Aspire.Hosting.Meilisearch 73% 57% 50
CommunityToolkit.Aspire.Hosting.Minio 93% 75% 48
CommunityToolkit.Aspire.Hosting.MongoDB.Extensions 96% 83% 36
CommunityToolkit.Aspire.Hosting.MySql.Extensions 100% 88% 78
CommunityToolkit.Aspire.Hosting.Ngrok 52% 35% 82
CommunityToolkit.Aspire.Hosting.NodeJS.Extensions 97% 78% 286
CommunityToolkit.Aspire.Hosting.Ollama 67% 70% 174
CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector 66% 53% 89
CommunityToolkit.Aspire.Hosting.PapercutSmtp 92% 50% 10
CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions 99% 89% 84
CommunityToolkit.Aspire.Hosting.Python.Extensions 68% 55% 90
CommunityToolkit.Aspire.Hosting.RavenDB 63% 49% 136
CommunityToolkit.Aspire.Hosting.Redis.Extensions 100% 71% 48
CommunityToolkit.Aspire.Hosting.Rust 94% 83% 16
CommunityToolkit.Aspire.Hosting.Solr 96% 100% 14
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects 76% 64% 154
CommunityToolkit.Aspire.Hosting.Sqlite 99% 89% 42
CommunityToolkit.Aspire.Hosting.SqlServer.Extensions 100% 87% 78
CommunityToolkit.Aspire.Hosting.SurrealDb 54% 37% 234
CommunityToolkit.Aspire.MassTransit.RabbitMQ 100% 100% 30
CommunityToolkit.Aspire.Meilisearch 97% 92% 68
CommunityToolkit.Aspire.Microsoft.Data.Sqlite 89% 85% 52
CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite 50% 50% 88
CommunityToolkit.Aspire.Minio.Client 73% 59% 88
CommunityToolkit.Aspire.OllamaSharp 77% 71% 132
CommunityToolkit.Aspire.RavenDB.Client 60% 53% 237
CommunityToolkit.Aspire.SurrealDb 79% 63% 78
Summary 72% (8312 / 11543) 59% (2583 / 4398) 5236

Minimum allowed line rate is 60%

@aaronpowell
Copy link
Member

@davidfowl @JamesNK is this looking like what you were expecting with the new API?

FullStackChef pushed a commit to FullStackChef/CommunityToolkit-Aspire that referenced this pull request Sep 26, 2025
…ta, MEAI telemetry sources, and expose DisableTracing property (CommunityToolkit#846)

* Initial plan

* Add support for configuring OpenTelemetryChatClient.EnableSensitiveData and MEAI telemetry sources

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* Update documentation for OpenTelemetry configuration support

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* Expose DisableTracing property on OllamaSharpSettings publicly

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: Aaron Powell <me@aaron-powell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update AspireOllamaChatClientExtensions.AddChatClient to allow configuring sensitive data

3 participants