- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersbugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on
Description
The utility methods on Context for logging all document **extra as being passed forward to the logger. However, Context.log does not actually allow any additional kwargs to be passed. This results in errors such as
Context.log() got an unexpected keyword argument 
To Reproduce
Any usage of the context methods with extra kwargs will produce the error, for example
await context.info(
    "request finished",
    channel_id=channel_id,
    status=response.get("ok"),
)Expected behavior
The Context.log method is documented with
Args:
  level: Log level (debug, info, warning, error)
  message: Log message
  logger_name: Optional logger name
  **extra: Additional structured data to include
This (and the helper methods) should either be documented as not supporting additional structured data or the log message data needs to be structured, for example, something like this
    async def log(
        self,
        level: Literal["debug", "info", "warning", "error"],
        message: str,
        *,
        logger_name: str | None = None,
        **extra: Any
    ) -> None:
        """Send a log message to the client.
        Args:
            level: Log level (debug, info, warning, error)
            message: Log message
            logger_name: Optional logger name
            **extra: Additional structured data to include
        """
        log_data = {
           "message": message, **extra
        }
        await self.request_context.session.send_log_message(
            level=level, data=log_data, logger=logger_name
        )Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersbugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on