You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea proposed here roughly corresponds to the concept of "logging levels", but aims to be separate from a strict logging levels paradigm. Based on a discussion with @jaredcnance.
I want the ability to add large numbers of properties to the MetricsLogger in my code, far more than would be economical to output for execution in production. Then, based on some criteria, like sampling, an error occurring, some sort of "debug" flag, etc., I want to filter down the properties that get flushed. Additionally, I may want to suppress the output entirely.
Proposed solution
Methods on MetricsLogger like set_property() and put_metric() will add an optional keyword argument called tag that takes a string or list of strings.
MetricsLogger will add two properties, pre_filter and filter, that can be set to callables.
pre_filter is called when a method is called with the tag keyword argument. It takes as input the context object, the tags, and the inputs to the method (e.g., property name and value), and returns a boolean indicating whether to actually perform the action or to silently ignore the input
For convenience, pre_filter can be set to a list of tags, equivalent to a callable that matches the given tags against any in the list.
filter is called when the output is being collated. It takes as input the context object and any uncaught error that the metric scope (if there is one) has handled. It returns a boolean or a list of tags. If it returns a boolean, and the value is False, the logging is suppressed. If the boolean is True, all properties/metrics will be included in the output. If it returns a list of tags, the output is filtered to include untagged properties/metrics and any tagged properties/metrics that have at least one tag matching the list.
For convenience, filter can be set to a boolean or a list of tags, equivalent to a callable that returns that value.
If no pre_filter is set, tagged properties/metrics will not be dropped.
If no filter is set, all tagged properties/metrics will be included in the output.
The reason to call it filter rather than post_filter is to encourage its use over pre_filter, which should generally only be used if memory/GC usage is a concern. The delayed action of filter allows decisions on properties to be made with context that may come in later (for example, increased logging verbosity in case of an error).
Use cases
1. "Debug" logging
To simply have a set of verbose properties, I might do the following:
The idea proposed here roughly corresponds to the concept of "logging levels", but aims to be separate from a strict logging levels paradigm. Based on a discussion with @jaredcnance.
I want the ability to add large numbers of properties to the
MetricsLogger
in my code, far more than would be economical to output for execution in production. Then, based on some criteria, like sampling, an error occurring, some sort of "debug" flag, etc., I want to filter down the properties that get flushed. Additionally, I may want to suppress the output entirely.Proposed solution
MetricsLogger
likeset_property()
andput_metric()
will add an optional keyword argument calledtag
that takes a string or list of strings.MetricsLogger
will add two properties,pre_filter
andfilter
, that can be set to callables.pre_filter
is called when a method is called with thetag
keyword argument. It takes as input the context object, the tags, and the inputs to the method (e.g., property name and value), and returns a boolean indicating whether to actually perform the action or to silently ignore the inputFor convenience,
pre_filter
can be set to a list of tags, equivalent to a callable that matches the given tags against any in the list.filter
is called when the output is being collated. It takes as input the context object and any uncaught error that the metric scope (if there is one) has handled. It returns a boolean or a list of tags. If it returns a boolean, and the value is False, the logging is suppressed. If the boolean is True, all properties/metrics will be included in the output. If it returns a list of tags, the output is filtered to include untagged properties/metrics and any tagged properties/metrics that have at least one tag matching the list.For convenience,
filter
can be set to a boolean or a list of tags, equivalent to a callable that returns that value.pre_filter
is set, tagged properties/metrics will not be dropped.filter
is set, all tagged properties/metrics will be included in the output.The reason to call it
filter
rather thanpost_filter
is to encourage its use overpre_filter
, which should generally only be used if memory/GC usage is a concern. The delayed action offilter
allows decisions on properties to be made with context that may come in later (for example, increased logging verbosity in case of an error).Use cases
1. "Debug" logging
To simply have a set of verbose properties, I might do the following:
2. Verbose logging in case of an error
3. Sampling
4. Combined uses
Questions
The text was updated successfully, but these errors were encountered: