softwaremill / softwaremill/tapir
Enhancing ServerLog handling of decode failures
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
Inspired by a discussion on the Community Forum: https://softwaremill.community/t/how-to-customize-logging-with-the-server-log-interceptor/361
We need better customization and safety in the default logging of decode failures in ServerLog.
Current Challenges:
- Limited/inconvenient control of the logging level
Users can't easily change the logging level for decode failures (e.g., from debug to warn) if a request is considered "handled and returning a 4xx response". Such errors go todoLogWhenHandled, which is not always intuitive, especially since there's an additionaldoLogAllDecodeFailuresmethod and.logAllDecodeFailures(Boolean)flag that doesn't control such cases. - Customisation of error message
The default message is preformatted as (link)
s"Request: ${showRequest(ctx.request)}, handled by: ${showEndpoint(
ctx.endpoint
)}${took(token)}; decode failure: ${ctx.failure}, on input: ${ctx.failingInput.show}; response: ${showResponse(response)}"
To change this, the user has to write their extension of DefaultServerLog and override decodeFailureHandled.
- Safety of
${crx.failure}
If the failure is of typeDecodeFailure.Error, it has a field calledoriginal: Stringcontaining the full input body. In case of JSON decoding errors, it's the full JSON body, which in many cases shouldn't be printed due to its length and possibly sensitive information.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with server/core/src/main/scala/sttp/tapir/server/interceptor/log/ServerLog.scala, especially doLogWhenHandled, doLogAllDecodeFailures, logAllDecodeFailures, and decodeFailureHandled. Review DefaultServerLog and the linked Community Forum discussion first. Done means decode-failure logging level and message customization are clearer and full input bodies are not logged by default, with the relevant behavior covered by tests if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, backend, observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100