OpenTelemetry GCP Trace Exporter

Export OpenTelemetry spans directly to Google Cloud Trace from your Python services.

SDK
PyPI
v1.14.0
83stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
66/100Good
Development Activity72
Maintenance64
Community48
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality82
Innovation72
Learning Curve78

The OpenTelemetry GCP Trace Exporter connects OpenTelemetry-instrumented Python applications to Google Cloud Trace, translating collected spans into the Cloud Trace REST API format and shipping them for viewing in the Google Cloud Console. It plugs into the standard OpenTelemetry tracer provider as a span exporter, so any code already instrumented with OpenTelemetry can send its distributed traces to GCP with only a few lines of setup.

Maintained by Google as part of the opentelemetry-operations-python project, the exporter supports both manual instrumentation via BatchSpanProcessor and zero-code auto-instrumentation through the opentelemetry-instrument CLI. It handles authentication through Application Default Credentials and integrates cleanly with GCP resource detection for accurate service attribution.

What You Get

  • A drop-in CloudTraceSpanExporter that works with any OpenTelemetry tracer provider
  • Support for both BatchSpanProcessor (production) and SimpleSpanProcessor (debugging)
  • Zero-code auto-instrumentation via the opentelemetry-instrument CLI with the gcp_trace exporter
  • Application Default Credentials authentication and GCP resource detection integration
  • Environment-variable configuration for project ID and exporter behavior

Common Use Cases

  • Sending distributed traces from Python microservices to Google Cloud Trace
  • Diagnosing request latency across GKE, Cloud Run, and App Engine workloads
  • Adding tracing to existing OpenTelemetry-instrumented apps without switching backends

Under The Hood

Architecture - The exporter centers on CloudTraceSpanExporter in src/opentelemetry/exporter/cloud_trace/__init__.py, which implements OpenTelemetry’s SpanExporter interface. When a span processor flushes finished spans, the exporter maps OpenTelemetry’s span model (context, attributes, events, status) onto Cloud Trace’s protobuf span representation and calls the Cloud Trace client’s REST API to batch-write them. Configuration flows through environment_variables.py, and project resolution defers to Application Default Credentials and GCP resource detection.

Tech Stack - Written in Python (>=3.9) and packaged with setuptools via a setup.cfg/setup.py pair. Core dependencies are google-cloud-trace ~= 1.1 for the API client, opentelemetry-api and opentelemetry-sdk ~= 1.30 for the tracing model, and opentelemetry-resourcedetector-gcp for resource attribution. It registers OpenTelemetry entry points for both the traces exporter and environment-variable discovery.

Code Quality - The package ships a py.typed marker and typed source, and includes a dedicated tests directory covering the exporter, integration behavior, and auto-instrumentation (test_cloud_trace_exporter.py, test_integration_cloud_trace_exporter.py, test_cloud_trace_auto_instrument.py). As a Google-maintained project it carries consistent Apache-license headers, tox-based CI, and a clear module layout under a single namespace package.

API Design - The public surface is intentionally minimal: instantiate CloudTraceSpanExporter(), hand it to a BatchSpanProcessor, and attach that to the tracer provider. The README and module docstrings document both the manual path and the zero-code opentelemetry-instrument --traces_exporter gcp_trace path, so getting started requires only a handful of lines and no bespoke configuration for the common case.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search