softwaremill / softwaremill/tapir

Enhancing ServerLog handling of decode failures

Open
#3,488 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. 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 to doLogWhenHandled, which is not always intuitive, especially since there's an additional doLogAllDecodeFailures method and .logAllDecodeFailures(Boolean) flag that doesn't control such cases.
  2. 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.

  1. Safety of ${crx.failure}
    If the failure is of type DecodeFailure.Error, it has a field called original: String containing 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.