Skip to main content

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.2 (2024-11-07)

Changes

  • otel: Update to otel 1.28 API (otel)

1.1.1 (2024-11-07)

Changes

  • Accept kw to make otel API forward-compatible (fwcompat)

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


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

File details

Details for the file opentelemetry_sdk_extension_prometheus_multiprocess-1.1.2.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_sdk_extension_prometheus_multiprocess-1.1.2.tar.gz
Algorithm Hash digest
SHA256 8b1d3e2e27439f9c82e18a36ec7c1d51d3abd776569148608bf8346a73cbc3c7
MD5 8934af070921f61b22287d5b86c2a85a
BLAKE2b-256 af5597a8a0d41d8e5e35f2a1e7c9ec849f3a934c5cb760667dbaf0f9fb60a3f4

See more details on using hashes here.

File details

Details for the file opentelemetry_sdk_extension_prometheus_multiprocess-1.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_sdk_extension_prometheus_multiprocess-1.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3953482dffd4c1843429a9d412620a75b0aa1d5ded0404c3909f7d9bcaf02d6b
MD5 5beb1e8b5b46076450ee5b2ea86f36e8
BLAKE2b-256 3722a9eb739979ba81ddc6207157c9d95392198060d6fce0ed1cd1eef905890f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page