Skip to content

MPT-26429 Include extension id in mrok access logs - #101

Merged
ffaraone merged 1 commit into
mainfrom
MPT-26429-include-extension-info-in-mrok-logs
Oct 14, 2026
Merged

ffaraone merged 1 commit into
mainfrom
MPT-26429-include-extension-info-in-mrok-logs

Conversation

@bdjilka

@bdjilka bdjilka commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@bdjilka
bdjilka force-pushed the MPT-26429-include-extension-info-in-mrok-logs branch 2 times, most recently from 1b7c05f to 937e7df Compare October 9, 2026 20:12
Comment thread mrok/frontend/app.py Fixed
Comment thread mrok/frontend/app.py Fixed
Comment thread mrok/frontend/middleware.py Outdated
from mrok.types.proxy import ASGIApp, ASGIReceive, ASGISend, Scope


class TargetMiddleware:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably TargetContextMiddleware is a bit clearer. wdyt?

Comment thread mrok/proxy/ziticorn.py Outdated
self.logger = logging.getLogger("mrok.proxy")


class AccessLoggerAdapter(logging.LoggerAdapter):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this. on the side of ziticorn, there is no need to have the extension id in every log record.

Comment thread mrok/proxy/ziticorn.py
return f"[{self.extra['extension']}] {msg}", kwargs


class HttpToolsProtocol(UvHttpToolsProtocol):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to set this adapter to have the extension id always available.

Comment thread mrok/logging.py Outdated

from mrok.conf import Settings

request_target: contextvars.ContextVar[str | None] = contextvars.ContextVar(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we should create a mrok.frontend.logging module since this is very frontend specific thing.

Comment thread mrok/logging.py Outdated
return "/healthcheck" not in record.getMessage()


class TargetContextFilter(logging.Filter):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread mrok/logging.py Resolved
@bdjilka
bdjilka force-pushed the MPT-26429-include-extension-info-in-mrok-logs branch from 937e7df to 44febf4 Compare October 12, 2026 20:13
@sonarqubecloud

sonarqubecloud Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

@ffaraone
ffaraone merged commit fdb8ecd into main Oct 14, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants