No project description provided
Project description
Workaround to use prometheus_client multiprocess mode (for e.g. gunicorn, celery) with opentelemetry, where this model currently is not supported, and not even employing an additional otel collector currently solves this.
This package provides a customized MeterProvider, that uses the native prometheus_client metrics implementations, and thus their mechanisms for exporting/exposition (and not the opentelemetry ones).
Usage
See Multiprocess Mode Documentation for details on how to operate this.
Set environment variable PROMETHEUS_MULTIPROC_DIR to a directory where prometheus_client can store its metrics state files (that are shared between processes via mmap).
Configure opentelemetry meter provider:
from opentelemetry.sdk.extension.prometheus_multiprocess import PrometheusMeterProvider import opentelemetry.metrics provider = PrometheusMeterProvider() opentelemetry.metrics.set_meter_provider(provider)
Set up prometheus metrics exposition, for example:
registry = prometheus_client.CollectorRegistry() prometheus_client.multiprocess.MultiProcessCollector(registry) prometheus_client.start_http_server(8080, registry=registry)
(The package also provides a MultiProcessRegistry to streamline this setup.)
Use opentelemetry metrics like normal:
meter = opentelemetry.metrics.get_meter('mypackage', 'myversion') HTTP_DURATION = metrics.create_histogram('http.client.duration', unit='ms') from timeit import default_timer start = default_timer() # perform request here duration = (default_timer() - start) * 1000 HTTP_DURATION.record(duration, {'http.response.status_code': 200})
Changelog
1.1.0 (2024-06-25)
Changes
naming: Conform to prometheus metric name and unit conventions (naming)
1.0.0 (2024-04-26)
Changes
Initial release (initial)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for opentelemetry_sdk_extension_prometheus_multiprocess-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0674fcd4646c283b40aa68851044298f34f79d7ea3961e7eaea35d6ca0fb69de |
|
MD5 | d6069b5fbb0ee0bec16ab08243ccfd7b |
|
BLAKE2b-256 | 4aa977b07ce57fb7d71506f8149df795ac44b547468e607b19a3326b54e0a879 |
Hashes for opentelemetry_sdk_extension_prometheus_multiprocess-1.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b9618f08efc2441c1f28ac315c7c55ed352729f8ea798a66434b1d2f7718c8 |
|
MD5 | 800f209ae39187493a7b9f93bec4dbfa |
|
BLAKE2b-256 | 55b3920efd40c2abba930f7345170994f86e59409637724c3cb55a1b6539676e |