Skip to content

Instrument Otel metrics#300

Open
Shweta-Deshpande wants to merge 2 commits intomainfrom
TFECO-11698
Open

Instrument Otel metrics#300
Shweta-Deshpande wants to merge 2 commits intomainfrom
TFECO-11698

Conversation

@Shweta-Deshpande
Copy link
Collaborator

This PR adds OpenTelemetry metrics instrumentation to the MCP server so we can observe tool-call volume, latency, and failures in Streamable HTTP mode.

  • Added metrics config and recording logic in pkg/client/metrics.go
  • Added OTel metrics setup/initialization in cmd/terraform-mcp-server/main.go
  • Wired metrics into server tool-call hooks in cmd/terraform-mcp-server/main.go
  • Passed metrics config through server startup paths (HTTP mode uses configured metrics; stdio remains with empty config)
  • Added unit tests for metrics behavior:
    pkg/client/metrics_test.go
    cmd/terraform-mcp-server/metrics_test.go

Metrics Added:
mcp_tool_calls_total (Counter)
mcp_tool_errors_total (Counter)
mcp_tool_duration_seconds (Histogram)

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@Shweta-Deshpande Shweta-Deshpande requested a review from a team as a code owner March 24, 2026 18:20
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