-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Docs: Modify Prometheus exporters section under Language APIs & SDKs #9570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tiffany76
merged 14 commits into
open-telemetry:main
from
Wineshuga:docs/link-prom-setup
Apr 20, 2026
+15
−37
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
77837ac
Add redirect to Prometheus docs
Wineshuga 616f5ac
Add OTLP -> Promtheus config
Wineshuga 495239f
Merge branch 'main' into docs/link-prom-setup
theletterf 589b0f8
Apply suggestions from code review on style guide
Wineshuga 86dcca0
Add introductory sentence between headings
Wineshuga 6da1928
Apply code review suggestions on improving structure
Wineshuga 3161257
Clean up Prometheus setup options list
Wineshuga ae3c7e0
remove language-specific reference and clarify OTLP metrics endpoint …
Wineshuga 42d003f
replace directional language with "following"
Wineshuga b49f52a
add rationale for key OpenTelemetry configuration recommendations
Wineshuga b33dff2
update semantic conventions link to official spec URL
Wineshuga 04968d5
remove 'Note'
Wineshuga 312700f
remove otlp-promtheus content
Wineshuga 4d5fdc7
Results from /fix directive
otelbot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 54 additions & 33 deletions
87
content/en/docs/languages/_includes/exporters/prometheus-setup.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,64 @@ | ||
| ## Prometheus | ||
|
|
||
| To send your metric data to [Prometheus](https://prometheus.io/), you can either | ||
| [enable Prometheus' OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver) | ||
| and use the [OTLP exporter](#otlp) or you can use the Prometheus exporter, a | ||
| `MetricReader` that starts an HTTP server that collects metrics and serialize to | ||
| Prometheus text format on request. | ||
| To send your metric data to [Prometheus](https://prometheus.io/), you can either: | ||
| - [Enable Prometheus' OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver) | ||
| and use the [OTLP exporter](#otlp) (best practice), | ||
| - [Enable Prometheus' OTLP Receiver](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver) | ||
| and [push Prometheus to the metrics endpoint directly](#push-metrics-directly) (for development or testing purposes), or | ||
| - Use the Prometheus exporter, a `MetricReader` that starts an HTTP server that collects metrics and serializes to Prometheus text format on request. | ||
|
|
||
| ### Backend Setup {#prometheus-setup} | ||
| ### Backend setup {#prometheus-setup} | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > If you have Prometheus or a Prometheus-compatible backend already set up, you | ||
| > can skip this section and setup the [Prometheus](#prometheus-dependencies) or | ||
| > [OTLP](#otlp-dependencies) exporter dependencies for your application. | ||
|
|
||
| You can run [Prometheus](https://prometheus.io) in a docker container, | ||
| accessible on port `9090` by following these instructions: | ||
|
|
||
| Create a file called `prometheus.yml` with the following content: | ||
|
|
||
| ```yaml | ||
| scrape_configs: | ||
| - job_name: dice-service | ||
| scrape_interval: 5s | ||
| static_configs: | ||
| - targets: [host.docker.internal:9464] | ||
| For [OTLP Exporter](#otlp-dependencies) or [Prometheus exporter](#prometheus-dependencies): | ||
|
|
||
| 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). | ||
|
|
||
| For pushing to a metrics endpoint directly: | ||
|
|
||
| Follow the [example prometheus.yml configuration in this Prometheus guide](https://prometheus.io/docs/guides/opentelemetry/#configuring-prometheus). | ||
|
|
||
| Once you have Prometheus set up, you can set up the OTLP Exporter, Prometheus exporter, or push to a metrics endpoint directly. | ||
|
|
||
| ### Push to metrics endpoint {#push-metrics-directly} | ||
| This section explains how to configure your application to send metrics directly to a Prometheus endpoint. | ||
|
|
||
| #### Use environment variables | ||
| You can configure OpenTelemetry SDKs and instrumentation libraries with [standard environment variables](/docs/languages/sdk-configuration/). Set the environment variables before starting your application. Below are the OpenTelemetry variables needed to send OpenTelemetry metrics to a Prometheus server on localhost: | ||
|
|
||
| ```bash | ||
| export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf | ||
| export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:9090/api/v1/otlp | ||
| ``` | ||
| Note: | ||
|
|
||
|
Wineshuga marked this conversation as resolved.
Outdated
|
||
| - The [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.50.0/specification/protocol/exporter.md#endpoint-urls-for-otlphttp) states that the OTEL_EXPORTER_OTLP_METRICS_ENDPOINT env var must be used as a base URL. The signal `/v1/metrics` is automatically appended | ||
| - See also: [opentelemetry-python #2443](https://github.com/open-telemetry/opentelemetry-python/issues/2443) | ||
|
Wineshuga marked this conversation as resolved.
Outdated
|
||
|
|
||
| Run Prometheus in a docker container with the UI accessible on port `9090`: | ||
| Turn off traces and logs: | ||
|
tiffany76 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```shell | ||
| docker run --rm -v ${PWD}/prometheus.yml:/prometheus/prometheus.yml -p 9090:9090 prom/prometheus --web.enable-otlp-receiver | ||
| ```bash | ||
| export OTEL_TRACES_EXPORTER=none | ||
| export OTEL_LOGS_EXPORTER=none | ||
| ``` | ||
|
|
||
| The default push interval for OpenTelemetry metrics is 60 seconds. The following will set a 15-second push interval: | ||
|
tiffany76 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```bash | ||
| export OTEL_METRIC_EXPORT_INTERVAL=15000 | ||
| ``` | ||
|
|
||
| If your instrumentation library does not provide `service.name` and `service.instance.id` out-of-the-box, it is highly recommended to set them. The example below assumes that the `uuidgen` command is available on your system. | ||
|
tiffany76 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```bash | ||
| export OTEL_SERVICE_NAME="my-example-service" | ||
| export OTEL_RESOURCE_ATTRIBUTES="service.instance.id=$(uuidgen)" | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > When using Prometheus' OTLP Receiver, make sure that you set the OTLP endpoint | ||
| > for metrics in your application to `http://localhost:9090/api/v1/otlp`. | ||
| > | ||
| > Not all docker environments support `host.docker.internal`. In some cases you | ||
| > may need to replace `host.docker.internal` with `localhost` or the IP address | ||
| > of your machine. | ||
| > Make sure that `service.instance.id` is unique for each instance, | ||
|
tiffany76 marked this conversation as resolved.
Outdated
|
||
| > and that a new `service.instance.id` is generated whenever a resource attribute changes. | ||
| > The [recommended way](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/resource) | ||
|
tiffany76 marked this conversation as resolved.
Outdated
|
||
| > is to generate a new UUID on each startup of an instance. | ||
|
|
||
| #### Configure telemetry | ||
| 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. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.