Skip to content

Commit a28b0ca

Browse files
yrsuthariemdnetoxrmx
authored
Fix broken link in Prometheus exporter README. Fixes #4399 (#4485)
* Fix broken link in Prometheus exporter README and add missing documentation. Fixes #4399 Signed-off-by: Yogi Suthari <[email protected]> * Update docs/exporter/prometheus/prometheus.rst Co-authored-by: Emídio Neto <[email protected]> * Apply suggestions from code review * Update CHANGELOG.md * Update CHANGELOG.md * Update docs/exporter/prometheus/prometheus.rst * Update docs-requirements.txt --------- Signed-off-by: Yogi Suthari <[email protected]> Co-authored-by: Emídio Neto <[email protected]> Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 9746645 commit a28b0ca

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Add missing Prometheus exporter documentation
11+
([#4485](https://github.com/open-telemetry/opentelemetry-python/pull/4485))
1012
- Overwrite logging.config.fileConfig and logging.config.dictConfig to ensure
1113
the OTLP `LogHandler` remains attached to the root logger. Fix a bug that
1214
can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https://github.com/open-telemetry/opentelemetry-python/pull/4636)).

docs-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ thrift~=0.10
2626
wrapt>=1.0.0,<2.0.0
2727
markupsafe~=2.0
2828
protobuf==5.29.5
29+
prometheus-client~=0.22.1
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
OpenTelemetry Prometheus Exporter
2+
=================================
3+
4+
.. automodule:: opentelemetry.exporter.prometheus
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
Installation
10+
------------
11+
12+
The OpenTelemetry Prometheus Exporter package is available on PyPI::
13+
14+
pip install opentelemetry-exporter-prometheus
15+
16+
Usage
17+
-----
18+
19+
The Prometheus exporter starts an HTTP server that collects metrics and serializes them to
20+
Prometheus text format on request::
21+
22+
from prometheus_client import start_http_server
23+
24+
from opentelemetry import metrics
25+
from opentelemetry.exporter.prometheus import PrometheusMetricReader
26+
from opentelemetry.sdk.metrics import MeterProvider
27+
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
28+
29+
# Service name is required for most backends
30+
resource = Resource(attributes={
31+
SERVICE_NAME: "your-service-name"
32+
})
33+
34+
# Start Prometheus client
35+
start_http_server(port=9464, addr="localhost")
36+
# Initialize PrometheusMetricReader which pulls metrics from the SDK
37+
# on-demand to respond to scrape requests
38+
reader = PrometheusMetricReader()
39+
provider = MeterProvider(resource=resource, metric_readers=[reader])
40+
metrics.set_meter_provider(provider)
41+
42+
Configuration
43+
-------------
44+
45+
The following environment variables are supported:
46+
47+
* ``OTEL_EXPORTER_PROMETHEUS_HOST`` (default: "localhost"): The host to bind to
48+
* ``OTEL_EXPORTER_PROMETHEUS_PORT`` (default: 9464): The port to bind to
49+
50+
References
51+
----------
52+
53+
* `Prometheus <https://prometheus.io/>`_
54+
* `OpenTelemetry Project <https://opentelemetry.io/>`_

0 commit comments

Comments
 (0)