Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The scope of the variables registered by this core.ctx.register_var() #12538

Answered by dosubot bot
renshunhang asked this question in Q&A
Discussion options

What is the scope of the variables registered by the core.ctx.register_var() method? Does it take effect for each request, or does it apply to all requests?
For each request, I registered many variables using the register_var method in order to report these values to the log_format defined for loki-logger.

You must be logged in to vote

Variables registered by core.ctx.register_var() are scoped per request—their values are computed based on the current request context and are not shared globally across requests. This makes them suitable for logging dynamic, request-specific data in plugins like loki-logger, especially when used in log_format fields reference.

However, there is a known bug in the loki-logger plugin: if log_labels are configured globally or the same config table is reused across requests, label values can leak between requests due to in-place mutation. To avoid this, configure loki-logger per route or service and avoid sharing mutable config tables. The log_format fields themselves are built per request a...

Replies: 1 comment

Comment options

Variables registered by core.ctx.register_var() are scoped per request—their values are computed based on the current request context and are not shared globally across requests. This makes them suitable for logging dynamic, request-specific data in plugins like loki-logger, especially when used in log_format fields reference.

However, there is a known bug in the loki-logger plugin: if log_labels are configured globally or the same config table is reused across requests, label values can leak between requests due to in-place mutation. To avoid this, configure loki-logger per route or service and avoid sharing mutable config tables. The log_format fields themselves are built per request and are less likely to leak values reference.

In summary: register_var variables are per-request, but be careful with loki-logger log_labels configuration to prevent cross-request data leakage.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other Chat with Dosu Join Discord Share on X

You must be logged in to vote
0 replies
Answer selected by renshunhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /