Repository navigation
MPT-26429 Include extension id in mrok access logs - #101
Conversation
1b7c05f to
937e7df
Compare
| from mrok.types.proxy import ASGIApp, ASGIReceive, ASGISend, Scope | ||
|
|
||
|
|
||
| class TargetMiddleware: |
There was a problem hiding this comment.
Probably TargetContextMiddleware is a bit clearer. wdyt?
| self.logger = logging.getLogger("mrok.proxy") | ||
|
|
||
|
|
||
| class AccessLoggerAdapter(logging.LoggerAdapter): |
There was a problem hiding this comment.
we don't need this. on the side of ziticorn, there is no need to have the extension id in every log record.
| return f"[{self.extra['extension']}] {msg}", kwargs | ||
|
|
||
|
|
||
| class HttpToolsProtocol(UvHttpToolsProtocol): |
There was a problem hiding this comment.
I don't think we need to set this adapter to have the extension id always available.
|
|
||
| from mrok.conf import Settings | ||
|
|
||
| request_target: contextvars.ContextVar[str | None] = contextvars.ContextVar( |
There was a problem hiding this comment.
probably we should create a mrok.frontend.logging module since this is very frontend specific thing.
| return "/healthcheck" not in record.getMessage() | ||
|
|
||
|
|
||
| class TargetContextFilter(logging.Filter): |
There was a problem hiding this comment.
I think a better approach is to use a custom log record factory. The filter in general is better to decide if a record must be included or not.
old_factory = logging.getLogRecordFactory()
def record_factory(*args, **kwargs):
record = old_factory(*args, **kwargs)
record.request_target = request_target.get()
return record
logging.setLogRecordFactory(record_factory)
Then we can use request_target in the format string when we configure a formatter for the frontend access log.
937e7df to
44febf4
Compare
|

No description provided.