Skip to content

Conversation

strawgate
Copy link
Collaborator

@strawgate strawgate commented Oct 1, 2025

  • Logging middleware now tracks and logs request duration
  • Logger is now namespaced under fastmcp.middleware.*
  • An error message type is now printed when an exception occurs
  • Timestamp has been removed

Cleaned up the tests a little bit with a helper function for extracting logs from caplog

Closes #1973

Logging middleware now tracks and logs request duration alongside other request information. Duration is measured using time.perf_counter() and displayed in milliseconds, following the same pattern as the existing timing middleware.

Co-authored-by: William Easton <strawgate@users.noreply.github.com>
@strawgate strawgate changed the title Add request duration to logging middleware [Draft] Add request duration to logging middleware Oct 1, 2025
@strawgate
Copy link
Collaborator Author

We should probably also remove the timestamp (or make it optional)

@strawgate strawgate changed the title [Draft] Add request duration to logging middleware Add request duration to logging middleware Oct 4, 2025
@strawgate strawgate changed the title Add request duration to logging middleware Updates to Logging Middleware Oct 4, 2025
@strawgate strawgate requested review from Copilot and jlowin October 4, 2025 02:13
Copy link
Contributor

@Copilot 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 updates the logging middleware to track request duration, update logger namespacing, and improve error handling. The changes align with issue #1973 and enhance the observability of the FastMCP server.

Key changes include:

  • Added request duration tracking using time.perf_counter() and reporting in milliseconds
  • Updated logger names to use the fastmcp.middleware.* namespace pattern
  • Improved error logging to include error type information in structured format

Reviewed Changes

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

File Description
src/fastmcp/server/middleware/logging.py Core logging middleware implementation with duration tracking, updated namespacing, and improved error handling
tests/server/middleware/test_logging.py Updated test suite to validate new duration tracking, logger namespacing, and structured logging improvements

@jlowin jlowin merged commit efc3596 into main Oct 8, 2025
8 checks passed
@jlowin jlowin deleted the claude/issue-1973-20250930-2348-new branch October 8, 2025 12:52
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.

Add request duration to logging middleware
2 participants