{"library":"opentelemetry-resourcedetector-gcp","title":"Google Cloud Resource Detector for OpenTelemetry","description":"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.","status":"active","version":"1.11.0a0","language":"en","source_language":"en","source_url":"https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/tree/main/opentelemetry-resourcedetector-gcp","tags":["opentelemetry","gcp","google cloud","resource detection","observability","telemetry"],"install":[{"cmd":"pip install opentelemetry-sdk opentelemetry-resourcedetector-gcp","lang":"bash","label":"Install core SDK and GCP resource detector"}],"dependencies":[{"reason":"Provides the core OpenTelemetry SDK components, including `Resource` and `ResourceDetector` base classes, necessary for using resource detectors.","package":"opentelemetry-sdk"},{"reason":"Provides the OpenTelemetry API definitions for traces, metrics, and logs, which are typically used in conjunction with resource detection.","package":"opentelemetry-api"}],"imports":[{"symbol":"GoogleCloudResourceDetector","correct":"from opentelemetry.resourcedetector.gcp_resource_detector import GoogleCloudResourceDetector"},{"note":"Used to combine the GCP detector with other potential resource detectors.","symbol":"get_aggregated_resources","correct":"from opentelemetry.sdk.resources import get_aggregated_resources"}],"quickstart":{"code":"import os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import get_aggregated_resources\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.resourcedetector.gcp_resource_detector import GoogleCloudResourceDetector\n\n# The detector automatically queries the GCP metadata server.\n# Ensure your application is running in a GCP environment for full detection.\nresource = get_aggregated_resources(\n    [GoogleCloudResourceDetector(raise_on_error=True)]\n)\n\n# Create a TracerProvider with the detected resource\ntracer_provider = TracerProvider(resource=resource)\ntrace.set_tracer_provider(tracer_provider)\n\n# For demonstration, export to console. In a real application, use a GCP exporter.\nspan_processor = SimpleSpanProcessor(ConsoleSpanExporter())\ntracer_provider.add_span_processor(span_processor)\n\ntracer = trace.get_tracer(__name__)\n\nwith tracer.start_as_current_span(\"my-gcp-operation\") as span:\n    span.set_attribute(\"custom.attribute\", \"value\")\n    print(f\"Span created with detected resource attributes: {resource.attributes}\")\n    # In a real application, this would be exported to Cloud Trace or another backend\n\nprint(\"Resource detection example complete.\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Version `1.11.0` introduced an upper bound on `opentelemetry-sdk` due to logging breaking changes. Using an `opentelemetry-sdk` version newer than the specified upper bound might lead to runtime errors or unexpected behavior related to logging.","severity":"breaking","affected_versions":">=1.11.0"},{"fix":"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.","message":"The `GoogleCloudResourceDetector` relies on accessing the GCP metadata server (typically at `http://metadata.google.internal`). If the application is running in an environment with restricted network access, firewalls, or outside of GCP, the detection may fail or time out.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"In `v1.3.0`, the explicit `google-auth` dependency for resource detection was removed. While this streamlines the detector, users expecting `google-auth` to be a direct dependency of the resource detector itself for other reasons might be surprised. It implies the detector primarily relies on the metadata server rather than explicit `google-auth` library calls for identity.","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Upgrade to `opentelemetry-resourcedetector-gcp` version `1.8.0` or newer to benefit from improved resource creation reliability and shorter metadata connection timeouts.","message":"Prior to `v1.8.0`, there were issues with the reliable creation of resources within the detector and potentially long timeouts when reading metadata. Users on older versions might experience incomplete resource attributes or delays in startup.","severity":"gotcha","affected_versions":"<1.8.0"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}