Skip to content

Fix SSE gauge leak, config bool handling, and metric error logging#3756

Merged
ChrisJBurns merged 1 commit intomainfrom
otel/fix-telemetry-bugs-b1-b2-b4
Feb 10, 2026
Merged

Fix SSE gauge leak, config bool handling, and metric error logging#3756
ChrisJBurns merged 1 commit intomainfrom
otel/fix-telemetry-bugs-b1-b2-b4

Conversation

@ChrisJBurns
Copy link
Copy Markdown
Collaborator

Summary

Three small telemetry bug fixes identified during OTEL MCP semantic conventions review (#3399):

  • SSE active connections gauge leak: The toolhive_mcp_active_connections gauge with connection_type=sse was incremented in recordSSEConnection but never decremented, growing monotonically. Moved the increment into Handler with a defer decrement so the gauge correctly tracks SSE connection lifecycle.

  • Config file use-legacy-attributes: false silently ignored: Go's zero-value false was indistinguishable from "not set", so setting use-legacy-attributes: false in YAML had no effect — the CLI default true always won. Changed UseLegacyAttributes from bool to *bool in the app config struct so nil (not set) is distinguishable from explicit false.

  • Metric creation errors silently discarded: All four metric instruments in NewHTTPMiddleware used _ := for errors. Now logged at debug level. The OTEL SDK returns no-op instruments on error so there is no runtime risk, but logging aids troubleshooting.

Test plan

  • Existing telemetry middleware tests pass
  • Two new test cases added for UseLegacyAttributes config handling:
    • Config explicitly sets false → correctly applied
    • Config not set (nil) → CLI default true used
  • Linter passes with zero issues

🤖 Generated with Claude Code

- Fix SSE active connections gauge that was incremented but never
  decremented. Move increment into Handler with a defer decrement so
  the gauge correctly tracks SSE connection lifecycle.

- Fix config file `use-legacy-attributes: false` being silently ignored.
  Change UseLegacyAttributes from bool to *bool in app config so nil
  (not set) is distinguishable from explicit false. Add two test cases
  covering both scenarios.

- Log metric creation errors at debug level instead of silently
  discarding them. The OTEL SDK returns no-op instruments on error so
  there is no runtime risk, but logging aids troubleshooting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Feb 10, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.37%. Comparing base (9f28499) to head (be90015).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/telemetry/middleware.go 57.89% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3756      +/-   ##
==========================================
- Coverage   66.38%   66.37%   -0.01%     
==========================================
  Files         427      427              
  Lines       41926    41935       +9     
==========================================
+ Hits        27831    27836       +5     
- Misses      11980    11982       +2     
- Partials     2115     2117       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns ChrisJBurns merged commit cee60fd into main Feb 10, 2026
69 of 71 checks passed
@ChrisJBurns ChrisJBurns deleted the otel/fix-telemetry-bugs-b1-b2-b4 branch February 10, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants