-
Notifications
You must be signed in to change notification settings - Fork 2.7k
The scope of the variables registered by this core.ctx.register_var() #12538
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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
Beta Was this translation helpful? Give feedback.