Skip to content
Open
1 change: 1 addition & 0 deletions .changelog/5123.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-exporter-prometheus`: add support for configuring scope info metric attributes for the Prometheus exporter
42 changes: 41 additions & 1 deletion docs/exporter/prometheus/prometheus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@ Prometheus text format on request::
provider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(provider)

Scope labels
------------

By default, the Prometheus exporter adds instrumentation scope information as
labels on every exported metric. These labels include ``otel_scope_name``,
``otel_scope_version``, and ``otel_scope_schema_url``. Instrumentation scope
attributes are exported with the ``otel_scope_`` prefix::

from prometheus_client import start_http_server

from opentelemetry import metrics
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.sdk.metrics import MeterProvider

start_http_server(port=9464, addr="localhost")
reader = PrometheusMetricReader()
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)

meter = metrics.get_meter(
"checkout",
"1.2.3",
schema_url="https://opentelemetry.io/schemas/1.21.0",
attributes={"region": "us-east-1"},
)
counter = meter.create_counter("orders")
counter.add(1, {"environment": "production"})

The exported metric includes labels such as
``otel_scope_name="checkout"``,
``otel_scope_version="1.2.3"``,
``otel_scope_schema_url="https://opentelemetry.io/schemas/1.21.0"``,
``otel_scope_region="us-east-1"``, and
``environment="production"``.

To omit instrumentation scope labels from exported metrics, set
``without_scope_info`` to ``True``::

reader = PrometheusMetricReader(without_scope_info=True)

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

Expand All @@ -56,4 +96,4 @@ References
----------

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