ray-project / ray

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
32.82k stars 5.57k forks source link

[Core] Allow library to pass attributes to Ray's structured logger #46598

Open GeneDer opened 1 month ago

GeneDer commented 1 month ago

Description

Currently Ray's structured logger doesn't take any additional attributes from outside of the log record itself. Right now the only way for an actor to log specific attributes is by passing them directly via something like

WorkerActor.remote(serve_logging_context: Dict)

class WorkerActor:
  def __init__(self, serve_logging_context):
    logger.log(..., extra=serve_logging_context) 

It would be nice to allow library to setup those logging context automatically, so the actor doesn't need to know and pass them during logging.

Use case

Endpoints has this usecase where there are actors created outside of Serve. Due to running in different processes, those actor doesn't have serve's request context setup and doesn't know things like request id to help debugging. Right now the workaround is to pass those context explicitly to the created actor and have them logged explicitly as part of the log record. Would be very nice if Serve can just setup those so the loggers in the downstream actors can all contain the context attributes.

rynewang commented 1 month ago

@GeneDer please rate priority: p0, p0.5, p1, p2