Registry / gcp / opentelemetry-exporter-gcp-monitoring

opentelemetry-exporter-gcp-monitoring

JSON →
library1.15.0a0pypypi✓ verified 24d ago

The `opentelemetry-exporter-gcp-monitoring` library provides an OpenTelemetry Python exporter for sending metrics to Google Cloud Monitoring. It is part of the `opentelemetry-operations-python` project, ensuring compatibility with other Google Cloud OpenTelemetry components. The current version is 1.11.0a0 and the project maintains a regular release cadence with frequent updates.

pip install opentelemetry-exporter-gcp-monitoring
INSTALL
IMPORT
SIG · OPENTELEMETRY-EXPO
O
opentelemetry-exporter-gcp-monitoring
gcppythonv1.15.0a0
Install
6.5s avg
Import
Disk
75MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 76.3MB
glibc
py 3.103.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.")
Debug
Known issues
breakingVersion 1.11.0a0 introduced an upper bound on `opentelemetry-sdk` due to potential breaking changes related to logging exporters. If you are also using OpenTelemetry logging components, ensure careful version management to avoid conflicts.
fix
Review the exact version constraints and ensure your `opentelemetry-sdk` version is within the specified bounds for all OpenTelemetry components you are using.
affects: 1.11.0a0+
gotchaProper Google Cloud authentication is required for the exporter to send metrics. The library relies on `google-auth` to find credentials, typically through `GOOGLE_APPLICATION_CREDENTIALS` environment variable, `gcloud` CLI defaults, or service account attached to the VM/environment.
fix
Configure your Google Cloud credentials correctly in your environment (e.g., `export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json` or `gcloud auth application-default login`).
affects: All versions
gotchaOpenTelemetry Resource attributes are mapped to Google Cloud Monitoring MonitoredResource labels. Incorrect or missing critical resource attributes (e.g., `service.name`, `service.namespace`) can lead to metrics not appearing or being incorrectly categorized in Cloud Monitoring.
fix
Always define a `Resource` with meaningful attributes that align with GCP's monitored resource types and labels. Consult GCP documentation for standard resource types.
affects: 1.4.0+
gotchaThe `PeriodicExportingMetricReader` exports metrics at a specified interval. If your application exits before an export interval completes or before a manual `shutdown()` or `force_flush()` call, recent metrics may not be sent to Cloud Monitoring.
fix
For short-lived applications or on application shutdown, ensure you call `meter_provider.shutdown()` or `meter_provider.force_flush()` to guarantee all buffered metrics are exported. For long-running apps, configure an appropriate `export_interval_millis`.
affects: All versions
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.
Agent activity
36 hits · last 30 days
node
30
OpenAI (training)
2
Resources