The `opentelemetry-resourcedetector-gcp` library provides support for automatically detecting resource information for applications running on Google Cloud Platform services such as Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Cloud Run, and Cloud Functions. It integrates with the OpenTelemetry Python SDK to enrich telemetry data (traces, metrics, logs) with environment-specific metadata. The current version is 1.11.0a0, with pre-releases happening frequently, indicating active development.
pip install opentelemetry-sdk opentelemetry-resourcedetector-gcpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the OpenTelemetry `TracerProvider` with `GoogleCloudResourceDetector`. The detector runs automatically when `get_aggregated_resources` is called, querying the GCP metadata server to identify the environment and populate standard OpenTelemetry resource attributes. Ensure the code runs within a Google Cloud environment (e.g., GCE, GKE, Cloud Run) for effective detection. The example then creates a basic span, which will inherit the detected resource attributes.
Refer to the `pyproject.toml` or `setup.cfg` of `opentelemetry-resourcedetector-gcp` for the exact `opentelemetry-sdk` version constraints and pin your `opentelemetry-sdk` installation accordingly.
Ensure that the application's network environment allows access to the metadata server. If running outside GCP or in a highly restricted environment, consider manually providing resource attributes or using other appropriate resource detectors.
If `google-auth` functionality is needed for other parts of your application (e.g., interacting with other Google Cloud APIs or using GCP-specific OpenTelemetry exporters), ensure it is installed separately.
Upgrade to `opentelemetry-resourcedetector-gcp` version `1.8.0` or newer to benefit from improved resource creation reliability and shorter metadata connection timeouts.