Registry /
gcp / opentelemetry-exporter-gcp-monitoring
Install & Compatibility
Where this runs
tested against v1.15.0a0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 76.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 6.5s · import 0.000s · 75MB
75MB installed
● package 75MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CloudMonitoringMetricsExporter
✓ from opentelemetry.exporter.gcp_monitoring import CloudMonitoringMetricsExporter
✗ from opentelemetry.exporter.gcp_monitoring import CloudMonitoringMetricsExporter
This quickstart demonstrates how to configure the `CloudMonitoringMetricsExporter` to send custom metrics to Google Cloud Monitoring. It sets up a `MeterProvider` with a `PeriodicExportingMetricReader` to automatically export metrics at a defined interval. Ensure your Google Cloud authentication (e.g., `GOOGLE_APPLICATION_CREDENTIALS` environment variable or default application credentials) is properly configured for the exporter to work. Resource attributes are crucial as they map to GCP monitored resource labels.
import os
import time
from opentelemetry import metrics
from opentelemetry.exporter.gcp_monitoring import CloudMonitoringMetricsExporter
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
# Ensure your Google Cloud credentials are set up (e.g., via GOOGLE_APPLICATION_CREDENTIALS)
# os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/your/key.json'
# Configure Resource attributes (these map to GCP MonitoredResource labels)
resource = Resource.create(
{
"service.name": os.environ.get('SERVICE_NAME', 'my-gcp-metrics-service'),
"service.namespace": os.environ.get('SERVICE_NAMESPACE', 'default'),
"service.instance.id": os.environ.get('SERVICE_INSTANCE_ID', 'instance-1'),
}
)
# Configure the exporter and metric reader
exporter = CloudMonitoringMetricsExporter()
reader = PeriodicExportingMetricReader(
exporter,
export_interval_millis=5000, # Export every 5 seconds
export_timeout_millis=30000 # Timeout after 30 seconds
)
meter_provider = MeterProvider(metric_readers=[reader], resource=resource)
metrics.set_meter_provider(meter_provider)
# Create a meter from the global meter provider
meter = metrics.get_meter(__name__)
# Create a counter instrument
counter = meter.create_counter(
"my_app_requests_total",
description="Total number of application requests",
unit="1",
)
# Record some measurements
print("Recording metrics...")
for i in range(5):
counter.add(1, {"http_method": "GET", "http_status": "200"})
counter.add(1, {"http_method": "POST", "http_status": "201"})
print(f" Added metrics batch {i+1}")
time.sleep(2) # Sleep to allow multiple export intervals
print("Metrics sent to Google Cloud Monitoring. Check your dashboard.")
# Flush and shutdown the provider to ensure all metrics are exported
meter_provider.shutdown()
print("Metric provider shut down.")
Upgrade
Version history
1.15.0a0latest on PyPI · released Aug 19, 2026
Audit
Dependencies
opentelemetry-apirequiredCore OpenTelemetry API for defining instrumentation.
opentelemetry-sdkrequiredOpenTelemetry SDK for processing and exporting telemetry data.
google-cloud-monitoringrequiredGoogle Cloud client library for interacting with the Cloud Monitoring API.
google-authrequiredGoogle Authentication Library for Python, used for GCP credential management.