Skip to content

Conversation

@pamelafox
Copy link
Contributor

OTel improvements to deployed MCP:

  • Adds an explicit option for AppInsights vs Logfire vs None for OTel export
  • Adds an env var for Logfire token that can proprogate to prod
  • Migrates the middleware to use new MCP semantic conventions
  • New README sections

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 OpenTelemetry (OTel) configuration for the deployed MCP server by introducing a unified approach to telemetry platform selection and implementing MCP semantic conventions for better observability.

Key Changes:

  • Introduces OPENTELEMETRY_PLATFORM environment variable to explicitly choose between AppInsights, Logfire, or no telemetry export
  • Migrates OpenTelemetry middleware to follow MCP semantic conventions (PR #2083) with standardized span naming and GenAI attributes
  • Adds infrastructure support for Logfire token as a secure environment variable

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
servers/opentelemetry_middleware.py Implements MCP semantic conventions with new span naming pattern "{method} {target}", adds GenAI attributes (gen_ai.tool.name, gen_ai.prompt.name), and includes safe JSON serialization helper
servers/deployed_mcp.py Updates telemetry configuration to use OPENTELEMETRY_PLATFORM env var, changes get_expenses_data from @mcp.resource to @mcp.tool, removes enable_cross_partition_query parameter, and simplifies import
servers/auth_mcp.py Updates to use OPENTELEMETRY_PLATFORM for consistent telemetry configuration and renames csv_content to expense_summary
servers/basic_mcp_http.py Changes logging level from INFO to WARNING and updates transport from "http" to "streamable-http"
infra/write_env.sh Adds LOGFIRE_TOKEN (conditional) and OPENTELEMETRY_PLATFORM to environment file generation
infra/write_env.ps1 PowerShell equivalent of write_env.sh changes for Windows environments
infra/server.bicep Adds openTelemetryPlatform parameter with validation, logfireToken secure parameter, and conditional environment variables/secrets
infra/main.parameters.json Replaces useMonitoring with openTelemetryPlatform parameter and adds logfireToken
infra/main.bicep Replaces useMonitoring boolean with openTelemetryPlatform enum, derives useAppInsights, and propagates new parameters throughout infrastructure
agents/langchainv1_github.py Updates example query to be more specific (requests 5 repositories with bulleted list)
agents/agentframework_learn.py Removes unnecessary Authorization header from MCPStreamableHTTPTool initialization
agents/agentframework_http.py Restructures environment loading to only call load_dotenv when not in production
README.md Adds new sections for using deployed MCP server with GitHub Copilot, running server locally, viewing traces in Application Insights, and viewing traces in Logfire

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



@mcp.resource("resource://expenses")
@mcp.tool
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The decorator was changed from @mcp.resource to @mcp.tool for this function in deployed_mcp.py, but remains as @mcp.resource in basic_mcp_http.py. This creates an inconsistency between the two server implementations. Consider whether get_expenses_data should be a resource or a tool, and ensure both files use the same decorator type for consistency.

Suggested change
@mcp.tool
@mcp.resource

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

Choose a reason for hiding this comment

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

Thats because we're explicitly showing resources in the first session, when we use basic. But my experience with the deployed servers is that resources dont get called often, so I changed them to tools to be more useful.

expenses_data = []

async for item in cosmos_container.query_items(query=query, enable_cross_partition_query=True):
async for item in cosmos_container.query_items(query=query):
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The removal of 'enable_cross_partition_query=True' may cause the query to fail if the Cosmos DB container is partitioned. Without this parameter, Cosmos DB queries are limited to a single partition. If the container uses a partition key (which is common in production), this query should either specify the partition key or include enable_cross_partition_query=True to query across all partitions.

Suggested change
async for item in cosmos_container.query_items(query=query):
async for item in cosmos_container.query_items(query=query, enable_cross_partition_query=True):

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

Choose a reason for hiding this comment

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

Hm I think this comment is based off outdated knowledge. This is what Opus says:
"Looking at the Azure Cosmos DB Python SDK documentation, enable_cross_partition_query is no longer needed in the modern SDK. The parameter was deprecated and is now the default behavior - cross-partition queries are automatically enabled. So you removed it because it's unnecessary with the current version of the azure-cosmos SDK.

The SDK automatically handles cross-partition queries without requiring this flag, making the code cleaner."

I believe I verified this change.

@pamelafox pamelafox merged commit 6eec09a into Azure-Samples:main Dec 16, 2025
2 checks passed
@pamelafox pamelafox deleted the mcptweaksotel branch December 16, 2025 17:10
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.

1 participant