Google Cloud resource detector 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 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
Oct 14, 2025
1.10.0a0
Feb 04, 2025
1.9.0a0
Jan 08, 2025
1.8.0a0
Aug 27, 2024
1.7.0a0
Oct 16, 2023
1.6.0a0
May 17, 2023
1.5.0a0
Dec 05, 2022
1.4.0a0
Apr 21, 2022
1.3.0a0
Apr 05, 2022
1.2.0a0
Jan 13, 2022
1.1.0a0
Apr 22, 2021
1.0.0a0
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
(~=1.30)
opentelemetry-api
(~=1.30)
opentelemetry-sdk
(~=2.24)
requests
(~=4.0)
typing_extensions