opentelemetry.exporter.cloud_trace¶
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
# For debugging
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
# Otherwise
from opentelemetry.sdk.trace.export import BatchSpanProcessor
trace.set_tracer_provider(TracerProvider())
cloud_trace_exporter = CloudTraceSpanExporter()
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(cloud_trace_exporter)
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("foo"):
print("Hello world!")
When not debugging, make sure to use
opentelemetry.sdk.trace.export.BatchSpanProcessor
with the
default parameters for performance reasons.
Auto-instrumentation¶
This exporter can also be used with OpenTelemetry auto-instrumentation:
opentelemetry-instrument --traces_exporter gcp_trace <command> <args>
Configuration is supported through environment variables
(opentelemetry.exporter.cloud_trace.environment_variables
) or the corresponding command
line arguments to opentelemetry-instrument
:
opentelemetry-instrument --traces_exporter gcp_trace \
--exporter_gcp_trace_project_id my-project \
<command> <args>
See opentelemetry-instrument --help
for all configuration options.
API¶
Classes
Cloud Trace span exporter for OpenTelemetry. |