Skip to main content
This API requires the otel feature flag. Add features = ["otel"] to your Cargo.toml:

Overview

The III SDK includes comprehensive OpenTelemetry support for distributed tracing, metrics collection, and structured logging. When the otel feature is enabled, telemetry data is exported to the III Engine over a shared WebSocket connection.

Initialization

init_otel

Initialize OpenTelemetry with the given configuration.
OtelConfig
required
Configuration for OpenTelemetry including service name, metrics settings, etc.
Example:
When using III::set_otel_config() and connect(), OpenTelemetry is automatically initialized. You only need to call init_otel() directly if you’re not using the III client.

shutdown_otel

Shutdown OpenTelemetry and flush all pending data.
Example:
Always call shutdown_otel() or iii.shutdown_async() before your application exits to ensure all telemetry data is flushed.

flush_otel

Flush all pending telemetry data without shutting down.
Example:

is_initialized

Check if OpenTelemetry has been initialized.
Example:

Configuration

OtelConfig

Configuration structure for OpenTelemetry.
Field Defaults:
  • enabled: true (can be overridden by OTEL_ENABLED env var)
  • service_name: "iii-rust-sdk" (can be overridden by OTEL_SERVICE_NAME env var)
  • service_version: SDK version from Cargo.toml
  • service_instance_id: Random UUID
  • engine_ws_url: III client address or ws://localhost:49134
  • metrics_enabled: true
  • metrics_export_interval_ms: 60000 (1 minute)
  • logs_enabled: true
  • shutdown_timeout_ms: 10000 (10 seconds)
  • channel_capacity: 10000
  • fetch_instrumentation_enabled: true

ReconnectionConfig

Configuration for WebSocket reconnection behavior.
Defaults:
  • initial_delay_ms: 1000
  • max_delay_ms: 30000
  • backoff_multiplier: 2.0
  • jitter_factor: 0.3
  • max_retries: None (infinite)
  • max_pending_messages: 1000

Distributed Tracing

get_tracer

Get a tracer for creating spans manually.
Example:

with_span

Execute a function within a traced span with automatic error handling.
&str
required
Name of the span
Option<&str>
W3C traceparent header to set parent context
Option<SpanKind>
Span kind (defaults to Internal)
F
required
Async function to execute within the span
Example:

Automatic Trace Propagation

Trace context is automatically propagated across function calls:

Trace Context Functions

current_trace_id

Get the current trace ID.

current_span_id

Get the current span ID.
Example:

inject_traceparent

Inject current trace context into a W3C traceparent header.

extract_traceparent

Extract trace context from a W3C traceparent header.
Example:

Baggage

Baggage allows you to propagate key-value pairs across service boundaries.

set_baggage_entry

Set a baggage entry.

get_baggage_entry

Get a baggage entry.

get_all_baggage

Get all baggage entries.
Example:

Metrics

get_meter

Get a meter for creating metrics.
Example:

Metric Types

OpenTelemetry provides several metric types: Counter:
Histogram:
Gauge (via UpDownCounter):

HTTP Instrumentation

execute_traced_request

Execute an HTTP request with automatic tracing.
reqwest::Request
required
HTTP request to execute
Example:
HTTP instrumentation automatically injects traceparent and baggage headers into outbound requests.

Logging

When the otel feature is enabled, the Logger automatically emits OpenTelemetry LogRecords:
Log Levels:
  • logger.debug(message, data)
  • logger.info(message, data)
  • logger.warn(message, data)
  • logger.error(message, data)

Complete Example

Resource Attributes

The SDK automatically adds these resource attributes:
  • service.name: Service name from config or OTEL_SERVICE_NAME
  • service.version: Service version from config or SERVICE_VERSION
  • service.instance.id: Service instance ID (UUID)
  • service.namespace: Optional namespace from config
  • telemetry.sdk.name: "iii-rust-sdk"
  • telemetry.sdk.language: "rust"
  • telemetry.sdk.version: SDK version

See Also