-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an Enabled
method to the Logger
#3917
Comments
cc @open-telemetry/specs-logs-approvers @pellared |
otel-rust added a similar method under feature flag - open-telemetry/opentelemetry-rust#1147 |
When is a The idea is that these options are controlled in the log framework being bridged, and that only logs which are enabled make it to the point where the bridge API is called. |
Many (maybe all?) of the Go logging libraries take the other approach. They assume the downstream handlers will tell them if a log will actually be used or not. Having the bridge API respond appropriately is going to be critical here. I still need to look at the links @lalitb posted, but I'm guessing the same is true in other language based on their addition of this. |
Yeah, that is an interesting point. We don't really have any threshold configuration downstream in the SDK or even in the exporters. In fact, we don't seem to have any definition of the OTLP exporter at all (that I can find at least?). |
@jack-berg I think to your point we need to have a way for exporters to be configured for a severity threshold and pass that all the way back up to the API. Otherwise, we're setting users up with a situation where they are going to generate fire-hoses of logs data and have no relief valve. |
@jack-berg to the question of how do you disable logging, (outside of your proposal) the No-Op implementation should disable logging, right? Ideally users of an API can get informed about this backing prior to doing something computationally expensive. |
Certain implementations might want to have "Enabled(level, event_id)", and if they can implement it efficiently, we shouldn't stop them from doing so.
One related thinking - the boolean value MUST be true if the log is enabled. It can be true or false if the log is disabled (this gives room for memory optimization).
Would you elaborate a bit on this? This sounds like the backend cannot change the configuration on-the-fly, which seems to be an important feature (I think it is very common to turn on verbose log for a short period of time without having to restart the application). |
👍 |
Yeah, I've been thinking about this a bit as well. What we want is to support situations, like you say, where the value may change, but also situations where the bridge shouldn't waste extra time rechecking something that won't change. Giving this some thought, I think what we should beak-up the information returned. We should require a bool return value signifying the enabled state, but also allow for an additional return value that states if the value can be cached or not. This second return value can be optional. @reyang what do you think? |
@reyang updated the description. PTAL. |
Yeah. There are some tricks how to make it very efficient. For example, the check can be optimized to just testing a bit (or byte) in the RAM (so each check is just 1~3 CPU cycles), and the memory can be updated asynchronously by the control plane. |
We can remove the caching return value given the caching can live closer to where any dynamic behavior will live. |
Updated. |
Knowing if a
LogRecord
will be dropped prior to performing computationally expensive operations helps developers using the Logs Bridge API avoid wasted and expensive work. To facilitate this, aLogger
should provide a function on aLogger
that users can call to determine if aLogRecord
will be recorded or dropped.Proposal
Enabled
function to theLogger
in the Logs Bridge API.context
(optional): the Context associated with theLogRecord
that will be logged.context
, other dynamic values included in a context (i.e. HTTP header information).severity number
: The Severity Number of theLogRecord
that will be logged.true
when logging is enabled, but may betrue
orfalse
, when logging is disabled (this gives room for memory optimization or indeterminable state).Alternates
Provide a
GetSeverityLevel
functionGetServerityLevel
function to theLogger
in the Logs Bridge API.Logger
will record aLogRecord
forThis approach will lose a lot of easy value gained by including a
context
. Simple look-up of values within the context can often determine if aLogRecord
will be dropped or not. This approach would miss that.Allow language to define their own approach
Instead of prescribing something that all languages should do. Call out that languages may extend the
Logger
to provide some form of this functionality and that the specification will always leave this unspecified so as not to conflict with these implementations.This approach is the opposite of having a specification driven project where all implementation look the same.
Additional context.
Multiple logging libraries in Go provide this optimization1234. If the Go SIG is going to be able to support these critical logging systems we need this functionality in the Logs Bridge API.
Footnotes
https://pkg.go.dev/log/slog#Logger.Enabled ↩
https://pkg.go.dev/go.uber.org/zap#Logger.Level ↩
https://pkg.go.dev/github.com/go-logr/logr#LogSink ↩
https://pkg.go.dev/github.com/sirupsen/logrus#Logger.IsLevelEnabled ↩
The text was updated successfully, but these errors were encountered: