opentelemetry-resourcedetector-gcp 1.10.0a0


pip install opentelemetry-resourcedetector-gcp

  Latest version

Released: Oct 14, 2025

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
https://badge.fury.io/py/opentelemetry-resourcedetector-gcp.svg Documentation Status

This library provides support for detecting GCP resources like GCE, GKE, etc.

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.

Installation

pip install opentelemetry-resourcedetector-gcp

Usage

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry import trace
from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID, Resource

# This will use the GooglecloudResourceDetector under the covers.
resource = Resource.create(
    attributes={
        # Use the PID as the service.instance.id to avoid duplicate timeseries
        # from different Gunicorn worker processes.
        SERVICE_INSTANCE_ID: f"worker-{os.getpid()}",
    }
)
traceProvider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(OTLPSpanExporter())
traceProvider.add_span_processor(processor)
trace.set_tracer_provider(traceProvider)

References

Extras: None
Dependencies:
opentelemetry-api (~=1.30)
opentelemetry-sdk (~=1.30)
requests (~=2.24)
typing_extensions (~=4.0)