|
1 | 1 | ## Prometheus |
2 | 2 |
|
3 | | -To send your metric data to [Prometheus](https://prometheus.io/), you can either: |
4 | | -- [Enable Prometheus' OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver) |
5 | | -and use the [OTLP exporter](#otlp) (best practice), |
| 3 | +To send your metric data to [Prometheus](https://prometheus.io/), you can |
| 4 | +either: |
| 5 | + |
6 | 6 | - [Enable Prometheus' OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver) |
7 | | -and [push Prometheus to the metrics endpoint directly](#push-metrics-directly) (for development or testing purposes), or |
8 | | -- Use the Prometheus exporter, a `MetricReader` that starts an HTTP server that collects metrics and serializes to Prometheus text format on request. |
| 7 | + and use the [OTLP exporter](#otlp) (best practice), or |
| 8 | +- Use the Prometheus exporter, a `MetricReader` that starts an HTTP server that |
| 9 | + collects metrics and serializes to Prometheus text format on request. |
9 | 10 |
|
10 | 11 | ### Backend setup {#prometheus-setup} |
11 | 12 |
|
12 | | -For [OTLP Exporter](#otlp-dependencies) or [Prometheus exporter](#prometheus-dependencies): |
13 | | - |
14 | | - To run a Prometheus server backend and begin scraping metrics, see the [Prometheus getting started guide](https://prometheus.io/docs/prometheus/latest/getting_started/). To enable the OTLP Receiver, see the [Prometheus guide for enabling the OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver). |
15 | | - |
16 | | -For pushing to a metrics endpoint directly: |
17 | | - |
18 | | - Follow the [example prometheus.yml configuration in this Prometheus guide](https://prometheus.io/docs/guides/opentelemetry/#configuring-prometheus). |
19 | | - |
20 | | -Once you have Prometheus set up, you can set up the OTLP Exporter, Prometheus exporter, or push to a metrics endpoint directly. |
21 | | - |
22 | | -### Push to metrics endpoint {#push-metrics-directly} |
23 | | -This section explains how to configure your application to send metrics directly to a Prometheus endpoint. |
24 | | - |
25 | | -#### Use environment variables |
26 | | -You can configure OpenTelemetry SDKs and instrumentation libraries with [standard environment variables](/docs/languages/sdk-configuration/). Set the environment variables before starting your application. The following OpenTelemetry variables are needed to send OpenTelemetry metrics to a Prometheus server on localhost: |
27 | | - |
28 | | -```bash |
29 | | -export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf |
30 | | -export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:9090/api/v1/otlp |
31 | | -``` |
32 | | -The OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variable is treated as a base URL. The `/v1/metrics` path is appended as defined by the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.50.0/specification/protocol/exporter.md#endpoint-urls-for-otlphttp). |
33 | | - |
34 | | -Turn off traces and logs when using Prometheus if you only need metrics: |
35 | | - |
36 | | -```bash |
37 | | -export OTEL_TRACES_EXPORTER=none |
38 | | -export OTEL_LOGS_EXPORTER=none |
39 | | -``` |
40 | | - |
41 | | -The default push interval for OpenTelemetry metrics is 60 seconds. The following sets a 15-second interval for more responsive monitoring and faster alerting speed. Shorter intervals may increase network and processing overhead. |
42 | | - |
43 | | -```bash |
44 | | -export OTEL_METRIC_EXPORT_INTERVAL=15000 |
45 | | -``` |
46 | | - |
47 | | -If your instrumentation library does not provide `service.name` and `service.instance.id` out-of-the-box, it is highly recommended to set them. Without these attributes, it becomes difficult to reliably identify services or distinguish between instances, making debugging and aggregation significantly harder. The example below assumes that the `uuidgen` command is available on your system. |
48 | | - |
49 | | -```bash |
50 | | -export OTEL_SERVICE_NAME="my-example-service" |
51 | | -export OTEL_RESOURCE_ATTRIBUTES="service.instance.id=$(uuidgen)" |
52 | | -``` |
53 | | - |
54 | | -> [!NOTE] |
55 | | -> |
56 | | -> Make sure that `service.instance.id` is unique for each instance, |
57 | | -> and that a new `service.instance.id` is generated whenever a resource attribute changes. |
58 | | -> The [recommended way](/docs/specs/semconv/resource/service/#service-instance) |
59 | | -> is to generate a new UUID on each startup of an instance. |
| 13 | +To run a Prometheus server backend and begin scraping metrics, see the |
| 14 | +[Prometheus getting started guide](https://prometheus.io/docs/prometheus/latest/getting_started/). |
60 | 15 |
|
61 | | -#### Configure telemetry |
62 | | -Update your OpenTelemetry Configuration to use the same `exporter` and `reader` from the [OTLP](#otlp-dependencies) setup. If the environment variables are set up and loaded correctly, the OpenTelemetry SDK reads them automatically. |
| 16 | +To enable the OTLP Receiver, see the |
| 17 | +[Prometheus guide for enabling the OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver). |
0 commit comments