opentelemetry-gcloud-trace 0.3.0

OpenTelemetry support for Google Cloud Trace
Documentation

Cargo tests and formatting security audit

OpenTelemetry support for Google Cloud Trace

Quick start

Cargo.toml:

[dependencies]
opentelemetry-gcloud-trace = "0.3"

Compatibility matrix

opentelemetry-gcloud-trace version opentelemetry version tracing-opentelemetry
0.3 0.18 0.18
0.2 0.17 0.17

Example code:


use opentelemetry::KeyValue;
use opentelemetry::trace::*;
use opentelemetry_gcloud_trace::*;

let google_project_id = config_env_var("PROJECT_ID")?;

let tracer: opentelemetry::sdk::trace::Tracer = 
  GcpCloudTraceExporterBuilder::new(google_project_id)
    .install_simple() // use install_batch for production/performance reasons
    .await?;

tracer.in_span("doing_work_parent", |cx| {
  // ...
});

All examples available at examples directory.

To run example use with environment variables:

# PROJECT_ID=<your-google-project-id> cargo run --example enable-exporter

Google Cloud Console Example

Performance

For optimal performance, a batch exporter is recommended as the simple exporter will export each span synchronously on drop. You can enable the [rt-tokio], [rt-tokio-current-thread] features and specify a runtime on the pipeline to have a batch exporter configured for you automatically.

[dependencies]
opentelemetry = { version = "*", features = ["rt-tokio"] }
opentelemetry-gcloud-trace = "*"
let google_project_id = config_env_var("PROJECT_ID")?;
let tracer: opentelemetry::sdk::trace::Tracer = GcpCloudTraceExporterBuilder::new(google_project_id)
  .install_batch(
     opentelemetry::runtime::Tokio
   )
  .await?;

Configuration

You can specify trace configuration using with_trace_config:

   GcpCloudTraceExporterBuilder::new(google_project_id).with_trace_config(
      trace::config()
         .with_sampler(Sampler::AlwaysOn)
         .with_id_generator(RandomIdGenerator::default())
   )

Limitations

  • This exporter doesn't support any other runtimes except Tokio.

Licence

Apache Software License (ASL)

Author

Abdulla Abdurakhmanov