diff --git a/prometheus_client/__init__.py b/prometheus_client/__init__.py index 1224ad85..84a7ba82 100644 --- a/prometheus_client/__init__.py +++ b/prometheus_client/__init__.py @@ -11,7 +11,10 @@ write_to_textfile, ) from .gc_collector import GC_COLLECTOR, GCCollector -from .metrics import Counter, Enum, Gauge, Histogram, Info, Summary +from .metrics import ( + Counter, disable_created_metrics, enable_created_metrics, Enum, Gauge, + Histogram, Info, Summary, +) from .metrics_core import Metric from .platform_collector import PLATFORM_COLLECTOR, PlatformCollector from .process_collector import PROCESS_COLLECTOR, ProcessCollector @@ -27,6 +30,8 @@ 'Histogram', 'Info', 'Enum', + 'enable_created_metrics', + 'disable_created_metrics', 'CONTENT_TYPE_LATEST', 'generate_latest', 'MetricsHandler', diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index dfe694db..7e5b030a 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -70,6 +70,18 @@ def _get_use_created() -> bool: _use_created = _get_use_created() +def disable_created_metrics(): + """Disable exporting _created metrics on counters, histograms, and summaries.""" + global _use_created + _use_created = False + + +def enable_created_metrics(): + """Enable exporting _created metrics on counters, histograms, and summaries.""" + global _use_created + _use_created = True + + class MetricWrapperBase(Collector): _type: Optional[str] = None _reserved_labelnames: Sequence[str] = ()