Google Cloud Monitoring exporter for OpenTelemetry
Project Links
Meta
Author: Google
Requires Python: >=3.9
Classifiers
Development Status
- 4 - Beta
Intended Audience
- Developers
License
- OSI Approved :: Apache Software License
Programming Language
- Python
- Python :: 3
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
This library provides support for exporting metrics to Google Cloud Monitoring.
To get started with instrumentation in Google Cloud, see Generate traces and metrics with Python.
To learn more about instrumentation and observability, including opinionated recommendations for Google Cloud Observability, visit Instrumentation and observability.
For resource detection and GCP trace context propagation, see opentelemetry-tools-google-cloud. For the Google Cloud Trace exporter, see opentelemetry-exporter-gcp-trace.
Installation
pip install opentelemetry-exporter-gcp-monitoring
Usage
import time
from opentelemetry import metrics
from opentelemetry.exporter.cloud_monitoring import (
CloudMonitoringMetricsExporter,
)
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.sdk.resources import Resource
metrics.set_meter_provider(
MeterProvider(
metric_readers=[
PeriodicExportingMetricReader(
CloudMonitoringMetricsExporter(), export_interval_millis=5000
)
],
resource=Resource.create(
{
"service.name": "basic_metrics",
"service.namespace": "examples",
"service.instance.id": "instance123",
}
),
)
)
meter = metrics.get_meter(__name__)
# Creates metric workload.googleapis.com/request_counter with monitored resource generic_task
requests_counter = meter.create_counter(
name="request_counter",
description="number of requests",
unit="1",
)
staging_labels = {"environment": "staging"}
for i in range(20):
requests_counter.add(25, staging_labels)
time.sleep(5)
References
1.10.0a0
Oct 14, 2025
1.9.0a0
Feb 04, 2025
1.8.0a0
Jan 08, 2025
1.7.0a0
Aug 27, 2024
1.6.0a0
Oct 16, 2023
1.5.0a0
May 17, 2023
1.4.0a0
Dec 05, 2022
1.3.0a0
Apr 21, 2022
1.2.0a0
Apr 05, 2022
1.1.0a0
Jan 13, 2022
1.0.0a0
Apr 22, 2021