Skip to content

Add PSR-3 compliant exception context when logging exceptions#300

Open
svenmuennich wants to merge 1 commit intomodelcontextprotocol:mainfrom
pickware:fix/psr3-exception-logging
Open

Add PSR-3 compliant exception context when logging exceptions#300
svenmuennich wants to merge 1 commit intomodelcontextprotocol:mainfrom
pickware:fix/psr3-exception-logging

Conversation

@svenmuennich
Copy link
Copy Markdown

This PR consistently adds caught exceptions to the logging context as exception, following the standard defined by PSR-3.

Motivation and Context

Previously almost no caught exceptions where included in the context passed to respective PSR logging calls, making it very hard for downstream tooling to e.g. filter certain errors from reporting.

How Has This Been Tested?

Added unit test coverage for inclusion of exceptions in logging.

Breaking Changes

n/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

I decided to include objects of type Throwable in the logging, even though PSR-3 only covers objects of types Exception. My reasoning was based on the following statement in the spec:

Implementors MUST still verify that the 'exception' key is actually an Exception before using it as such, as it MAY contain anything.

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