Skip to content

Conversation

@JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Sep 24, 2025

Resolves #1830

This change replaces all instances of global logger usage in the ToolHive operator with context-aware logging to preserve trace context for better observability.

Changes

  • Updated validateRunConfig() to accept context and use log.FromContext()
  • Updated helper functions in mcpserver_controller.go to use context-aware logging:
    • ensureRequiredEnvVars()
    • serviceForMCPServer()
    • deploymentNeedsUpdate()
    • generateKubernetesOIDCArgs()
    • generateConfigMapOIDCArgs()
  • Removed unused global logger imports
  • Updated function signatures to accept context.Context parameters
  • Fixed all calling sites to pass context
  • Updated test files to accommodate new function signatures
  • Fixed linting issues (line length violations)

Testing

  • All unit tests pass
  • All integration tests pass
  • Linting passes with no issues
  • No regressions introduced

Impact

This change improves observability by ensuring that trace context is properly preserved throughout the operator's logging, making it easier to correlate logs with distributed traces in production environments.

Resolves #1830

This change replaces all instances of global logger usage in the
ToolHive operator with context-aware logging to preserve trace
context for better observability.

Changes:
- Updated validateRunConfig() to accept context and use log.FromContext()
- Updated helper functions in mcpserver_controller.go to use context-aware logging:
  - ensureRequiredEnvVars()
  - serviceForMCPServer()
  - deploymentNeedsUpdate()
  - generateKubernetesOIDCArgs()
  - generateConfigMapOIDCArgs()
- Removed unused global logger imports
- Updated function signatures to accept context.Context parameters
- Fixed all calling sites to pass context
- Updated test files to accommodate new function signatures
- Fixed linting issues (line length violations)

All tests pass and no regressions introduced.
@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 51.42857% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.54%. Comparing base (975da43) to head (7eb0e22).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...d/thv-operator/controllers/mcpserver_controller.go 48.38% 16 Missing ⚠️
...md/thv-operator/controllers/mcpserver_runconfig.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2007      +/-   ##
==========================================
- Coverage   47.58%   47.54%   -0.04%     
==========================================
  Files         232      232              
  Lines       28646    28655       +9     
==========================================
- Hits        13630    13624       -6     
- Misses      13989    14010      +21     
+ Partials     1027     1021       -6     

☔ 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.

Copy link
Collaborator

@dmartinol dmartinol left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Collaborator

@RoddieKieley RoddieKieley left a comment

Choose a reason for hiding this comment

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

Upon a cursory read through it looks good and matches the description. All checks are green so +1

@JAORMX JAORMX merged commit 4af4b8d into main Sep 24, 2025
30 of 31 checks passed
@JAORMX JAORMX deleted the fix/operator-context-aware-logging branch September 24, 2025 12:13
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.

thv-operator: Use logger with relevant context

4 participants