Prometheus: receiving and exporting metrics

You can use OpenTelemetry Collector to collect Prometheus metrics using Prometheus receiver and export OpenTelemetry metrics to Prometheus using Promethes exporter.

OpenTelemetry Collector Prometheus

What is OpenTelemetry?

OpenTelemetry is an open source and vendor-neutral API for distributed tracing (including logs and errors) and OpenTelemetry metrics. With OpenTelemetry, you can instrument your application once and then add or change OpenTelemetry-compatible backends without changing the instrumentation.

What is OpenTelemetry Collector?

OpenTelemetry Collector is a proxy between your application and a backend that receives telemetry data, transforms it, and exports the data to various observability platforms, storage systems, or other destinations.

Collector can also act as an agent that pulls telemetry data from monitored systems, for example, Redisopen in new window or host metrics.

OpenTelemetry and Prometheus

OpenTelemetry and Prometheusopen in new window have different data formats, but they can be integrated to work together.

You can configure OpenTelemetry Collector to accept OpenTelemetry data and then export it to Prometheus using the Prometheus remote write protocol.

You can also do the opposite and use OpenTelemetry Collector to pull Prometheus metrics and the export them to OpenTelemetry backendsopen in new window using the OpenTelemetry Protocol.

Prometheus receiver

You can use OpenTelemetry Collector to pull Prometheus metrics using Prometheus receiveropen in new window:

When collecting metrics from Prometheus, OpenTelemetry Collector acts as a Prometheus server itself, scraping metrics from one or more Prometheus exporters, and then processing and exporting the collected metrics to configured destinations, for example, Uptrace APMopen in new window.

    collection_interval: 10s
    endpoint: ''
    metrics_path: '/metrics'
    use_service_account: false
      ca_file: '/path/to/ca'
      cert_file: '/path/to/cert'
      key_file: '/path/to/key'
      insecure_skip_verify: true

      # Copy your project DSN here
      uptrace-dsn: 'https://<token><project_id>'

      receivers: [prometheus_simple]
      exporters: [otlp/uptrace]

Prometheus exporter

OpenTelemetry Collector Prometheus Exporter is a component that allows users to export metrics from the OpenTelemetry Collector to the Prometheus monitoring system.

To use the OpenTelemetry Collector Prometheus Exporteropen in new window, you need to configure it with the desired configuration parameters.

The exporter allows you to add custom labels and metadata to the exported metrics, which can be useful for organizing and categorizing metrics in Prometheus.

    endpoint: ''
    namespace: test-space
      label1: value1
      'another label': spaced value
    send_timestamps: true
    metric_expiration: 180m
      enabled: true

      receivers: [otlp]
      exporters: [prometheus]

Once the exporter is configured and enabled, it will collect metrics from the OpenTelemetry Collector and forward them to the specified Prometheus server. Users can then use Prometheus tools to query, visualize, and alert on the collected metrics.

Sending metrics from Go to Prometheus

OpenTelemetry specifies how to collect, aggregate, and send metrics to backend platforms. Using OpenTelemetry instruments, you can create counter, gauge, and histogram metrics.

The simplest Counter instrument looks like this:

import ""

counter := Meter.SyncInt64().Counter(
	instrument.WithDescription("Just a test counter"),

// Increment the counter.
counter.Add(ctx, 1, attribute.String("foo", "bar"))
counter.Add(ctx, 10, attribute.String("hello", "world"))

To send OpenTelemetry Go metrics to Prometheus, you need to provide a Prometheus target:

import (
	controller ""
	processor ""
	selector ""

func configureOpentelemetry() {
	exporter := configureMetrics()

	http.HandleFunc("/metrics", exporter.ServeHTTP)
	fmt.Println("listenening on http://localhost:8088/metrics")

	go func() {
		_ = http.ListenAndServe(":8088", nil)

func configureMetrics() *prometheus.Exporter {
	config := prometheus.Config{}

	ctrl := controller.New(

	exporter, err := prometheus.New(config, ctrl)
	if err != nil {


	return exporter

And then configure Prometheus to scrape exposed metrics:

  - job_name: 'opentelemetry'
      - targets: ['localhost:8088']

You can find a runnable example at GitHubopen in new window.


Uptrace is an open source APM toolopen in new window that provides monitoring for various frameworks, databases, and cloud platforms, allowing you to monitor the full technology stack.

Uptrace uses OpenTelemetry Collectoropen in new window to collect, process, and export telemetry data from various sources. It supports multiple protocols, formats, and destinations, making it a flexible and scalable solution for monitoring infrastructure.

You can also use OpenTelemetry Kubernetes integration which provides a set of metrics and traces for monitoring Kubernetes clusters. It includes support for different components like nodes, pods, and services.

See also

Last Updated: