Skip to content
Discussion options

You must be logged in to vote

I'm currently working on the same situation... this seems to work so far:

"""Instrumentation for registering requests and responses."""

import logging
from typing import Callable

from fastapi import Request, Response
from fastapi.routing import APIRoute

logger = logging.getLogger(__name__)


class LoggingRoute(APIRoute):  # noqa
    def get_route_handler(self) -> Callable:  # noqa
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:  # noqa
            logger.warning("====REQUEST SCOPE====")
            logger.warning(request.scope)
            logger.warning("=====================")

            logger.warning

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
5 participants
Converted from issue

This discussion was converted from issue #3877 on February 27, 2023 22:29.