Skip to main content

Google Cloud Monitoring exporter for OpenTelemetry

Project description

https://badge.fury.io/py/opentelemetry-exporter-gcp-monitoring.svg Documentation Status

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry_exporter_gcp_monitoring-1.11.0a0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_exporter_gcp_monitoring-1.11.0a0.tar.gz
Algorithm Hash digest
SHA256 386276eddbbd978a6f30fafd3397975beeb02a1302bdad554185242a8e2c343c
MD5 70ae5f8407ffefccc134f4e61cc324de
BLAKE2b-256 3f48d1c7d2380bb1754d1eb6a011a2e0de08c6868cb6c0f34bcda0444fa0d614

See more details on using hashes here.

File details

Details for the file opentelemetry_exporter_gcp_monitoring-1.11.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_exporter_gcp_monitoring-1.11.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6740cba61b2f9555274829fe87a58447b64d0378f1067a4faebb4f5b364ca22
MD5 d6e2b9334b675e5e9ba95684cf61bfe4
BLAKE2b-256 8c8c03a6e73e270a9c890dbd6cc1c47c83d86b8a8a974a9168d92e043c6277cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page