OpenTelemetry Cloud Trace Exporter

Cloud Trace Span Exporter for OpenTelemetry. Uses Cloud Trace Client’s REST API to export traces and spans for viewing in Cloud Trace.

Usage

from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_tracer_provider(TracerProvider())

cloud_trace_exporter = CloudTraceSpanExporter()
trace.get_tracer_provider().add_span_processor(
    SimpleExportSpanProcessor(cloud_trace_exporter)
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("foo"):
    print("Hello world!")

API

class opentelemetry.exporter.cloud_trace.CloudTraceSpanExporter(project_id=None, client=None)[source]

Bases: opentelemetry.sdk.trace.export.SpanExporter

Cloud Trace span exporter for OpenTelemetry.

Parameters
  • project_id – ID of the cloud project that will receive the traces.

  • client – Cloud Trace client. If not given, will be taken from gcloud default credentials

export(spans)[source]

Export the spans to Cloud Trace.

See: https://cloud.google.com/trace/docs/reference/v2/rest/v2/projects.traces/batchWrite

Parameters

spans (Sequence[Span]) – Tuple of spans to export

Return type

SpanExportResult

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.