Registry /
observability / opentelemetry-exporter-gcp-trace
Install & Compatibility
Where this runs
tested against v1.15.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 73.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 6.2s · import 0.000s · 72MB
72MB installed
● package 72MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GcpTraceExporter
✓ from opentelemetry.exporter.gcp_trace import GcpTraceExporter
TracerProvider
✓ from opentelemetry.sdk.trace import TracerProvider
BatchSpanProcessor
✓ from opentelemetry.sdk.trace.export import BatchSpanProcessor
GcpResourceDetector
✓ from opentelemetry_resourcedetector_gcp import GcpResourceDetector
This quickstart demonstrates how to initialize the `GcpTraceExporter` and integrate it with the OpenTelemetry SDK to send traces to Google Cloud Trace. It includes the recommended `GcpResourceDetector` for automatic resource attribute population and highlights the importance of `provider.shutdown()` for complete trace export.
import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.gcp_trace import GcpTraceExporter
from opentelemetry_resourcedetector_gcp import GcpResourceDetector
# Configure GCP authentication:
# This exporter uses Application Default Credentials (ADC).
# Ensure GOOGLE_APPLICATION_CREDENTIALS environment variable points to a service account key
# or run on a GCP environment (VM, Cloud Run, GKE, etc.) with appropriate permissions.
# For example, to use a local service account file:
# export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"
# 1. Detect GCP resources automatically (highly recommended)
# This helps populate project ID, instance ID, etc., which are crucial for Cloud Trace.
resource = GcpResourceDetector().detect().merge(
Resource.create({"service.name": "my-gcp-python-app"})
)
# 2. Set up the TracerProvider with the detected resource
provider = TracerProvider(resource=resource)
trace.set_tracer_provider(provider)
# 3. Instantiate the GCP Trace Exporter
exporter = GcpTraceExporter()
# 4. Set up a BatchSpanProcessor to send traces efficiently
# Spans are batched and sent asynchronously.
span_processor = BatchSpanProcessor(exporter)
provider.add_span_processor(span_processor)
# 5. Get a tracer and create spans
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("parent-operation-gcp"):
print("Performing some work that will be traced in GCP...")
with tracer.start_as_current_span("child-operation-db"):
print("Simulating a database call...")
with tracer.start_as_current_span("child-operation-api"):
print("Simulating an external API call...")
# 6. Crucially, shut down the provider to ensure all batched spans are exported
# In short-lived scripts, this step is vital. In long-running services, it's typically
# handled gracefully on application shutdown.
provider.shutdown()
print("Traces sent to Google Cloud Trace. Check your GCP project's Trace Explorer.")
Upgrade
Version history
1.15.0latest on PyPI · released Aug 19, 2026
Audit
Dependencies
opentelemetry-sdkrequiredRequired OpenTelemetry SDK for tracing components.
google-cloud-tracerequiredGoogle Cloud Python client library for interacting with the Cloud Trace API.
google-api-corerequiredShared client library for Google APIs.
opentelemetry-resourcedetector-gcpoptionalHighly recommended for automatically populating resource attributes crucial for GCP integration.