{"library":"opentelemetry-exporter-prometheus-remote-write","title":"Prometheus Remote Write Metrics Exporter for OpenTelemetry","description":"The OpenTelemetry Prometheus Remote Write Metrics Exporter allows Python applications to export OpenTelemetry metrics data directly to a Prometheus Remote Write endpoint. It is part of the `opentelemetry-python-contrib` repository and is currently in beta (0.62b0), with breaking changes possible between minor versions. The project maintains a regular release cadence, often in sync with the broader OpenTelemetry Python Contrib releases.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install opentelemetry-exporter-prometheus-remote-write"],"cli":null},"imports":["from opentelemetry.exporter.prometheus_remote_write import PrometheusRemoteWriteMetricsExporter","from opentelemetry.sdk.metrics import MeterProvider","from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport time\nfrom opentelemetry import metrics\nfrom opentelemetry.sdk.metrics import MeterProvider\nfrom opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader\nfrom opentelemetry.exporter.prometheus_remote_write import PrometheusRemoteWriteMetricsExporter\n\n# Configure the Prometheus Remote Write exporter\n# The endpoint should point to your Prometheus-compatible remote write receiver\n# e.g., Prometheus with remote_write enabled, Mimir, Thanos, Cortex.\n# Use os.environ.get for sensitive info like API keys/tokens if headers are needed.\nexporter = PrometheusRemoteWriteMetricsExporter(\n    endpoint=os.environ.get('OTEL_PROMETHEUS_REMOTE_WRITE_ENDPOINT', 'http://localhost:9090/api/v1/write'),\n    # headers={'Authorization': f'Bearer {os.environ.get(\"PROMETHEUS_API_TOKEN\", \"\")}'},\n    timeout=30\n)\n\n# Configure the MeterProvider with a PeriodicExportingMetricReader\n# The reader exports metrics to the exporter at a specified interval (default 60s).\nreader = PeriodicExportingMetricReader(exporter, export_interval_millis=5000) # Export every 5 seconds for demonstration\nmeter_provider = MeterProvider(metric_readers=[reader])\n\n# Set the global MeterProvider (optional, but good practice)\nmetrics.set_meter_provider(meter_provider)\n\n# Get a meter from the provider\nmeter = metrics.get_meter(__name__)\n\n# Create a counter\nrequest_counter = meter.create_counter(\n    \"http_requests_total\",\n    description=\"Total number of HTTP requests\",\n    unit=\"1\"\n)\n\n# Record some observations\nprint(\"Recording metrics...\")\nrequest_counter.add(1, {\"method\": \"GET\", \"path\": \"/home\"})\ntime.sleep(1) # Give some time for the reader to potentially queue for export\nrequest_counter.add(2, {\"method\": \"POST\", \"path\": \"/data\"})\ntime.sleep(1) # More time\nrequest_counter.add(1, {\"method\": \"GET\", \"path\": \"/home\"})\n\nprint(\"Metrics recorded. Waiting for export...\")\n# In a real application, you'd keep the application running\n# For this example, we'll wait a bit longer to ensure export happens.\ntime.sleep(6) # Wait for at least one export cycle (5 seconds + buffer)\n\n# Shutdown the meter provider to ensure all buffered metrics are exported gracefully\n# This is crucial in short-lived applications or before exiting.\nprint(\"Shutting down MeterProvider...\")\nmeter_provider.shutdown()\nprint(\"Application finished.\")\n","lang":"python","description":"This quickstart demonstrates how to configure the Prometheus Remote Write exporter with a `MeterProvider` and a `PeriodicExportingMetricReader`. It creates a simple counter and adds observations, then gracefully shuts down the provider to ensure all metrics are exported. Remember to adjust the `endpoint` to your actual Prometheus remote write receiver.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.62b1","pypi_latest":"0.62b1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3.5,"avg_import_s":1.12,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.02,"mem_mb":21.7,"disk_size":"32.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.6,"import_time_s":0.67,"mem_mb":20.4,"disk_size":"33M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.53,"mem_mb":23,"disk_size":"35.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.4,"import_time_s":1.01,"mem_mb":21.8,"disk_size":"36M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.73,"mem_mb":23,"disk_size":"27.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":1.32,"mem_mb":21.9,"disk_size":"28M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.31,"mem_mb":24,"disk_size":"26.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.2,"import_time_s":0.96,"mem_mb":22.8,"disk_size":"27M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.92,"mem_mb":21.2,"disk_size":"31.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-prometheus-remote-write","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.1,"import_time_s":0.77,"mem_mb":20,"disk_size":"32M"}]}}