Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add missing Prometheus exporter documentation
([#4485](https://github.com/open-telemetry/opentelemetry-python/pull/4485))
- Overwrite logging.config.fileConfig and logging.config.dictConfig to ensure
the OTLP `LogHandler` remains attached to the root logger. Fix a bug that
can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https://github.com/open-telemetry/opentelemetry-python/pull/4636)).
Expand Down
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ thrift~=0.10
wrapt>=1.0.0,<2.0.0
markupsafe~=2.0
protobuf==5.29.5
prometheus-client~=0.22.1
54 changes: 54 additions & 0 deletions docs/exporter/prometheus/prometheus.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
OpenTelemetry Prometheus Exporter
=================================

.. automodule:: opentelemetry.exporter.prometheus
:members:
:undoc-members:
:show-inheritance:

Installation
------------

The OpenTelemetry Prometheus Exporter package is available on PyPI::

pip install opentelemetry-exporter-prometheus

Usage
-----

The Prometheus exporter starts an HTTP server that collects metrics and serializes them to
Prometheus text format on request::

from prometheus_client import start_http_server

from opentelemetry import metrics
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.resources import SERVICE_NAME, Resource

# Service name is required for most backends
resource = Resource(attributes={
SERVICE_NAME: "your-service-name"
})

# Start Prometheus client
start_http_server(port=9464, addr="localhost")
# Initialize PrometheusMetricReader which pulls metrics from the SDK
# on-demand to respond to scrape requests
reader = PrometheusMetricReader()
provider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(provider)

Configuration
-------------

The following environment variables are supported:

* ``OTEL_EXPORTER_PROMETHEUS_HOST`` (default: "localhost"): The host to bind to
* ``OTEL_EXPORTER_PROMETHEUS_PORT`` (default: 9464): The port to bind to

References
----------

* `Prometheus <https://prometheus.io/>`_
* `OpenTelemetry Project <https://opentelemetry.io/>`_