Skip to content

Adopt telemetry and observability features from MCP SDK v0.6#327

Merged
jongalloway merged 7 commits intomainfrom
copilot/adopt-telemetry-features-sdk-v0-6
Jan 28, 2026
Merged

Adopt telemetry and observability features from MCP SDK v0.6#327
jongalloway merged 7 commits intomainfrom
copilot/adopt-telemetry-features-sdk-v0-6

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

Telemetry and Observability Enhancement - COMPLETE ✅

Summary

Successfully adopted telemetry and observability features from MCP C# SDK v0.6.0-preview.1.

Recent Changes (Addressing PR Review Round 2)

  • ✅ Added clarifications that ActivitySource/Meter instances need to be implemented before registration
  • ✅ Commented out AddSource/AddMeter calls with clear notes explaining they're for future implementation
  • ✅ Referenced Future Enhancements section for context

Previous Changes (PR Review Round 1)

  • ✅ Added clarification that appsettings.json files are for development only
  • ✅ Fixed OpenTelemetry AddSource/AddMeter to use exact names (no wildcards)
  • ✅ Made configuration access patterns consistent (section-based approach)
  • ✅ Clarified that cache status requires custom logging
  • ✅ Recommended environment variables for end users

What Was Done

1. Documentation (Primary Deliverable) ✅

Created doc/telemetry.md - comprehensive guide covering:

  • ✓ Built-in SDK telemetry (request duration logging, OpenTelemetry semantic conventions)
  • ✓ Structured logging configuration
  • ✓ Optional OpenTelemetry integration (traces, metrics, OTLP exporters)
  • ✓ Clear notes about what requires implementation vs what's built-in
  • ✓ Performance monitoring best practices
  • ✓ Troubleshooting guide
  • ✓ Privacy and security considerations

Updated existing documentation:

  • doc/performance-baseline.md: Added telemetry-based monitoring section
  • README.md: Added telemetry documentation to index

2. Configuration Files ✅

  • appsettings.json: Default logging with OpenTelemetry placeholders (disabled)
  • appsettings.Development.json: Debug-level logging for development
  • .gitignore: Exclude sensitive production config files

3. Code Changes (Minimal) ✅

  • ServerCapabilities.Telemetry: Changed from false to true
  • ServerCapabilities.cs: Enhanced XML documentation
  • Tests: Updated ServerCapabilitiesTests to expect telemetry enabled

SDK v0.6 Features Documented

The MCP C# SDK v0.6.0-preview.1 provides (automatically):

  • Request Duration Logging: Execution time logged for all request handlers
  • OpenTelemetry Semantic Conventions: Standardized telemetry format
  • Structured Logging: Microsoft.Extensions.Logging integration

Validation ✅

  • ✅ Build: Clean build, 0 warnings
  • ✅ Tests: All ServerCapabilities tests pass (14/14)
  • ✅ Security: CodeQL analysis - 0 alerts
  • ✅ Code Review: All feedback addressed (2 rounds)
  • ✅ Documentation: Accurate and comprehensive

Benefits

✓ Better visibility into tool performance
✓ Standardized metrics compatible with OpenTelemetry ecosystem
✓ Easier debugging of slow/failing operations
✓ Foundation for future observability enhancements
✓ Clear user guidance on what's available now vs future enhancements


Security Summary

✅ No vulnerabilities discovered
✅ Configuration files properly secured (.gitignore)
✅ Privacy considerations documented

Original prompt

This section details on the original issue you should resolve

<issue_title>Adopt telemetry and observability features from SDK v0.6</issue_title>
<issue_description># Overview

Leverage improved telemetry and observability features from MCP C# SDK v0.6.0-preview.1.

New SDK Features

Request Duration Logging (#1092)

Log messages now include request duration for LogRequestHandlerCompleted and LogRequestHandlerException, enabling better performance diagnostics.

OpenTelemetry Semantic Conventions (#1139)

Telemetry is now aligned with OpenTelemetry MCP semantic conventions, enabling standardized observability.

Tasks

  • Review current logging configuration in the server
  • Evaluate enabling structured logging for performance metrics
  • Consider adding OpenTelemetry instrumentation for:
    • Tool execution times
    • Resource access patterns
    • Error rates by tool/operation
  • Update doc/performance-baseline.md with telemetry-based metrics if applicable
  • Document how to enable/configure telemetry for users

Benefits

  • Better visibility into tool performance
  • Standardized metrics compatible with OpenTelemetry ecosystem
  • Easier debugging of slow or failing operations

Parent Issue

Part of #322</issue_description>

Comments on the Issue (you are @copilot in this section)


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

Copilot AI and others added 3 commits January 27, 2026 21:27
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
@jongalloway jongalloway marked this pull request as ready for review January 27, 2026 21:36
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
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 pull request adds comprehensive telemetry and observability documentation and enables the telemetry capability flag to leverage the MCP C# SDK v0.6.0-preview.1's built-in telemetry features. The changes primarily consist of documentation with minimal code modifications to enable the telemetry flag.

Changes:

  • Created comprehensive telemetry documentation covering SDK telemetry, structured logging, and OpenTelemetry integration
  • Enabled the ServerCapabilities.Telemetry flag and updated related tests
  • Added example configuration files for logging and OpenTelemetry settings
  • Updated performance baseline documentation with telemetry monitoring guidance

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
doc/telemetry.md New comprehensive telemetry documentation covering SDK v0.6 features, configuration, and best practices
doc/performance-baseline.md Added telemetry-based performance monitoring section with request duration logging examples
README.md Added telemetry documentation link to documentation section
appsettings.json Default logging configuration with disabled OpenTelemetry placeholders for development
appsettings.Development.json Debug-level logging configuration for local development
.gitignore Added exclusions for production and local configuration files
DotNetMcp/Tools/Cli/DotNetCliTools.Misc.cs Changed Telemetry flag from false to true with documentation comment
DotNetMcp/Server/ServerCapabilities.cs Enhanced XML documentation for Telemetry property
DotNetMcp.Tests/Server/ServerCapabilitiesTests.cs Updated test assertions to expect telemetry enabled

Comment thread doc/telemetry.md
}
}
```

Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The documentation mentions using appsettings.json without clarifying the deployment context. The appsettings files at the repository root (appsettings.json, appsettings.Development.json) are not packaged with the NuGet tool (no CopyToOutputDirectory or Pack directive in the .csproj), so they're only available for local development of dotnet-mcp itself.

For end users who install via dnx Community.Mcp.DotNet, these files won't exist. Consider adding clarification:

  1. Note that the repository's appsettings files are for development only
  2. Recommend environment variables as the primary configuration method for end users (since they work regardless of installation method)
  3. If mentioning appsettings.json for end users, clarify they would need to create it in their working directory

For example, add a note after line 82:
"Note: The appsettings files in this repository are for local development. When using the installed tool (via dnx), environment variables are recommended for configuration since they work regardless of installation method. If you prefer configuration files, create appsettings.json in your working directory."

Suggested change
> Note: The `appsettings.json` files in this repository are for local development of dotnet-mcp and are not packaged with the `Community.Mcp.DotNet` tool. When using the installed tool (for example via `dnx`), environment variables are the recommended way to configure logging and other settings, since they work regardless of installation method. If you prefer configuration files, create an `appsettings.json` in your working directory with the desired settings.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added clarification note after line 82 explaining that appsettings files are for development only and recommending environment variables for end users. Fixed in dc0f311.

Comment thread doc/telemetry.md Outdated
Comment on lines +160 to +161
.AddSource("DotNetMcp.*")
.AddSource("ModelContextProtocol.*");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The AddSource method doesn't support wildcard patterns. The code shows .AddSource("DotNetMcp.*") and .AddSource("ModelContextProtocol.*"), but OpenTelemetry's AddSource expects exact ActivitySource names, not wildcard patterns like logging categories.

Unless the codebase creates ActivitySources with these exact literal names (including the ".*"), this configuration won't work as intended. If you want to capture all activities from these namespaces, you would need to explicitly add each ActivitySource name:

tracing
    .AddSource("DotNetMcp")
    .AddSource("ModelContextProtocol")

Or if there are multiple sources, list them explicitly. Wildcard support is not a standard feature of OpenTelemetry's AddSource method.

Suggested change
.AddSource("DotNetMcp.*")
.AddSource("ModelContextProtocol.*");
.AddSource("DotNetMcp")
.AddSource("ModelContextProtocol");

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed - removed wildcard patterns from AddSource. Now using exact names "DotNetMcp" and "ModelContextProtocol". Fixed in dc0f311.

Comment thread doc/telemetry.md Outdated
Comment on lines +188 to +189
.AddMeter("DotNetMcp.*")
.AddMeter("ModelContextProtocol.*");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

Same issue with AddMeter - wildcard patterns are not supported. The code shows .AddMeter("DotNetMcp.*") and .AddMeter("ModelContextProtocol.*"), but AddMeter expects exact meter names.

Change to:

metrics
    .AddMeter("DotNetMcp")
    .AddMeter("ModelContextProtocol")
Suggested change
.AddMeter("DotNetMcp.*")
.AddMeter("ModelContextProtocol.*");
.AddMeter("DotNetMcp")
.AddMeter("ModelContextProtocol");

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed - removed wildcard patterns from AddMeter. Now using exact names "DotNetMcp" and "ModelContextProtocol". Fixed in dc0f311.

Comment thread doc/telemetry.md
Comment on lines +228 to +231
```
info: ModelContextProtocol.Server.McpServer[LogRequestHandlerCompleted]
Request handler completed: resources/read (dotnet://info) in 45ms (cached)
```
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The example log message shows "(cached)" as part of the output, but it's unclear if the MCP SDK v0.6 actually includes caching information in the log messages. The SDK provides request duration logging, but cache status may not be automatically included.

Verify that the SDK actually logs cache status in this format. If it doesn't, either remove "(cached)" from the example or clarify that this would require custom logging in the resource implementation.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated example to remove "(cached)" and added a note clarifying that the SDK logs duration automatically but cache status would require custom logging. Fixed in dc0f311.

Comment thread doc/telemetry.md Outdated
Comment on lines +163 to +170
var consoleExporter = openTelemetryConfig.GetValue<bool>("Traces:ConsoleExporter");
if (consoleExporter)
tracing.AddConsoleExporter();

var otlpEnabled = openTelemetryConfig.GetValue<bool>("Traces:OtlpExporter:Enabled");
if (otlpEnabled)
{
var endpoint = openTelemetryConfig.GetValue<string>("Traces:OtlpExporter:Endpoint");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

Inconsistent configuration access pattern. The code mixes two different approaches:

  1. Line 163: Uses colon notation with GetValue<bool>("Traces:ConsoleExporter")
  2. Line 151: Uses GetSection("Traces").GetValue<bool>("Enabled")

While both work, mixing patterns in the same method reduces code maintainability. For consistency and clarity, use the section-based approach throughout:

var tracesSection = openTelemetryConfig.GetSection("Traces");
var consoleExporter = tracesSection.GetValue<bool>("ConsoleExporter");
var otlpSection = tracesSection.GetSection("OtlpExporter");
var otlpEnabled = otlpSection.GetValue<bool>("Enabled");

The same issue occurs in the metrics configuration section (lines 191, 195, 198).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed - now using consistent section-based configuration access throughout. Changed to use GetSection pattern for all configuration reads in both traces and metrics sections. Fixed in dc0f311.

Comment thread doc/telemetry.md Outdated
Comment on lines +191 to +198
var consoleExporter = openTelemetryConfig.GetValue<bool>("Metrics:ConsoleExporter");
if (consoleExporter)
metrics.AddConsoleExporter();

var otlpEnabled = openTelemetryConfig.GetValue<bool>("Metrics:OtlpExporter:Enabled");
if (otlpEnabled)
{
var endpoint = openTelemetryConfig.GetValue<string>("Metrics:OtlpExporter:Endpoint");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

Inconsistent configuration access pattern in the metrics section. Same issue as the tracing section - mixing colon notation (GetValue<bool>("Metrics:ConsoleExporter")) with section-based access (GetSection("Metrics").GetValue<bool>("Enabled")).

For consistency, use the section-based approach throughout.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed - now using consistent section-based configuration access in the metrics section matching the traces section. Fixed in dc0f311.

Copilot AI changed the title [WIP] Adopt telemetry and observability features from SDK v0.6 Adopt telemetry and observability features from MCP SDK v0.6 Jan 27, 2026
Copilot AI requested a review from jongalloway January 27, 2026 21:47
@jongalloway
Copy link
Copy Markdown
Owner

@copilot review and address comments

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
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

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Comment thread doc/telemetry.md Outdated
Comment on lines +161 to +163
tracing
.AddSource("DotNetMcp")
.AddSource("ModelContextProtocol");
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The OpenTelemetry integration code references ActivitySource names "DotNetMcp" and "ModelContextProtocol" that don't exist in the codebase. The AddSource method subscribes to activities from these named sources, but no ActivitySource instances with these names have been created.

This code example won't capture any traces without implementing the ActivitySources first. Line 335 in the "Future Enhancements" section acknowledges this: "Custom ActivitySource for tool execution spans" is listed as a planned feature.

Consider either:

  1. Removing the .AddSource() calls from the example and adding a comment explaining that ActivitySources would need to be implemented first
  2. Adding a clear note before the code example explaining that this requires implementing ActivitySources in the application code
  3. Moving this to the "Future Enhancements" section as example code for when ActivitySources are implemented
Suggested change
tracing
.AddSource("DotNetMcp")
.AddSource("ModelContextProtocol");
// NOTE: To capture custom spans from your application, you must first create corresponding
// ActivitySource instances (e.g., new ActivitySource("DotNetMcp")) in your code and then
// register them here. For example:
//
// tracing
// .AddSource("DotNetMcp")
// .AddSource("ModelContextProtocol");

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added clear NOTE comments explaining that ActivitySource instances need to be implemented first. The AddSource calls are now commented out with explanation that they're for future use when ActivitySources are implemented (referenced in Future Enhancements section). Fixed in 0a2f6c6.

Comment thread doc/telemetry.md Outdated
Comment on lines +191 to +193
metrics
.AddMeter("DotNetMcp")
.AddMeter("ModelContextProtocol");
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The OpenTelemetry integration code references Meter names "DotNetMcp" and "ModelContextProtocol" that don't exist in the codebase. The AddMeter method subscribes to metrics from these named meters, but no Meter instances with these names have been created.

This code example won't collect any metrics without implementing the Meters first. Line 336 in the "Future Enhancements" section acknowledges this: "Metrics for cache hit/miss rates" is listed as a planned feature.

Consider either:

  1. Removing the .AddMeter() calls from the example and adding a comment explaining that Meters would need to be implemented first
  2. Adding a clear note before the code example explaining that this requires implementing Meters in the application code
  3. Moving this to the "Future Enhancements" section as example code for when Meters are implemented
Suggested change
metrics
.AddMeter("DotNetMcp")
.AddMeter("ModelContextProtocol");
// Register custom OpenTelemetry meters here once they are implemented, for example:
// metrics.AddMeter("DotNetMcp").AddMeter("ModelContextProtocol");

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added clear NOTE comments explaining that Meter instances need to be implemented first. The AddMeter calls are now commented out with explanation that they're for future use when Meters are implemented (referenced in Future Enhancements section). Fixed in 0a2f6c6.

@jongalloway
Copy link
Copy Markdown
Owner

@copilot review and address comments

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
@jongalloway jongalloway merged commit c8ba9cd into main Jan 28, 2026
4 checks passed
@jongalloway jongalloway deleted the copilot/adopt-telemetry-features-sdk-v0-6 branch January 28, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adopt telemetry and observability features from SDK v0.6

3 participants