Skip to content

Conversation

@jmdacruz
Copy link

Initial attempt at adding support for extra arguments. For this to work, I had to isolate the code that auto registers the handler in a separate module, so that the export_stats_on_root_logger function can be called manually with the extra argument (without causing collisions on the prometheus registry).

Using extra arguments on logs can be useful for scenarios such as errors on HTTP requests, where you want to group metrics by status code.

Proposed usage (with support for extra):

from logging_prometheus.core import export_stats_on_root_logger
import logging

export_stats_on_root_logger(extra=['mylabel1', 'mylabel2']) # registers a metric with 4 labels (logger, level, mylabel1, mylabel2)

logging.error('message') # increases the count for the metric with mylabel1="unknown" and mylabel2="unknown"

logging.error('ffffff', extra={'mylabel1': 123}) # increases the count for the metric with mylabel1="123" and mylabel2="unknown"

logging.error('ffffff', extra={'mylabel1': 123, 'mylabel2': 'something'}) # increases the count for the metric with mylabel1="123" and mylabel2="something"

Proposed usage (without extra, a.k.a. "classic"):

from logging_prometheus import register

Opens:

  • Modify tests so that both "classic" and "extra" scenarios can be tested, without causing collisions on the prometheus registry

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.

1 participant