Skip to content

Conversation

@csmarchbanks
Copy link
Member

Users can disable the automatic creation of _created metrics by
specifying the environment variable PROMETHEUS_DISABLE_CREATED_SERIES.
This is controlled by an environment variable as an end user may not
have control over which registry is being used/when metrics are created.

Alternatively, we could force this to be done on the registry level and filter the metrics out
but that would not help users with custom registries. Happy to hear feedback that another
approach should be taken though.

Closes: #672

Users can disable the automatic creation of _created metrics by
specifying the environment variable PROMETHEUS_DISABLE_CREATED_SERIES.
This is controlled by an environment variable as an end user may not
have control over which registry is being used/when metrics are created.

Signed-off-by: Chris Marchbanks <[email protected]>
@csmarchbanks csmarchbanks merged commit 1aee355 into master Apr 5, 2022
@csmarchbanks csmarchbanks deleted the disable-created-series branch April 5, 2022 20:53
@SuperQ
Copy link
Member

SuperQ commented Apr 5, 2022

It would be useful to have a way that wasn't an environmental side-effect. Something like an explicit default registry method to turn it off. This makes it easier to deploy to fleets of services that share common library patterns.

@csmarchbanks
Copy link
Member Author

I am happy to accept something like that. Making life easier for users both with or without control over the source code is always nice.

@dswarbrick
Copy link

dswarbrick commented May 23, 2023

Another slight rough edge to this: the environment variable needs to be set before importing prometheus_client, since the _get_use_created() is only checked once when the module-level _use_created variable is set.

This means that when trying to manipulate this option from within Python via os.environ, you run into a flake8 lint nag:

import os

# Disable automatic addition of _created series. Must be set before importing prometheus_client.
os.environ["PROMETHEUS_DISABLE_CREATED_SERIES"] = 'true'

from prometheus_client import CollectorRegistry, Counter, Gauge, generate_latest
E402 module level import not at top of file

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.

Add ability to turn off _created metrics

4 participants