Skip to content

Commit

Permalink
Adding unique trace id (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekv authored Aug 30, 2024
1 parent 94f8c41 commit e664878
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion omni_rpc/custom_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

from pythonjsonlogger import jsonlogger

trace_id = None


def get_trace_id():
return uuid.uuid4()


class ContextFilter(logging.Filter):
def filter(self, record):
record.trace_id = get_trace_id()
record.trace_id = trace_id
return True


Expand Down
11 changes: 9 additions & 2 deletions omni_rpc/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from fastapi import FastAPI
from fastapi import Request

from omni_rpc.custom_logging import logger
import omni_rpc.custom_logging as custom_logging
from omni_rpc.routers import proxy_rpc

app = FastAPI()


logger.info("Starting Omni RPC server")
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
custom_logging.trace_id = custom_logging.get_trace_id()
response = await call_next(request)
return response


app.include_router(proxy_rpc.router)

0 comments on commit e664878

Please sign in to comment.