Crates.io | instana_opentelemetry_sdk |
lib.rs | instana_opentelemetry_sdk |
version | 1.0.0 |
created_at | 2025-09-04 18:21:59.033353+00 |
updated_at | 2025-09-04 18:21:59.033353+00 |
description | This library provides an OpenTelemetry Rust SDK which supports exporter, propagation and serialization. It allows you to send OpenTelemetry trace data to Instana for monitoring and observability. |
homepage | https://github.com/instana/instana-opentelemetry-rust |
repository | https://github.com/instana/instana-opentelemetry-rust |
max_upload_size | |
id | 1824597 |
size | 187,803 |
This library provides an OpenTelemetry Rust SDK which supports exporter, propagation and serialization. It allows you to send OpenTelemetry trace data to Instana for monitoring and observability.
Add the following to your Cargo.toml
:
[dependencies]
instana_opentelemetry_sdk = "1.0.0"
use instana_opentelemetry_sdk::exporter::exporter::{Exporter, Options};
use opentelemetry_sdk::trace::SpanExporter;
use opentelemetry_sdk::Resource;
use opentelemetry::KeyValue;
// Create exporter with builder pattern (recommended approach)
let exporter = Exporter::builder()
.build()
.expect("Failed to create instana exporter");
// Create with custom options
let options = Options {
endpoint: format!(
"http://{}:{}/com.instana.plugin.generic.rawtrace",
host, port
),
hostname: "my-host".to_string(),
service: "my-service".to_string(),
..Default::default()
};
// Create exporter with custom options and service
let exporter = Exporter::builder()
.with_options(options)
.with_service(Resource::new(vec![KeyValue::new("service.name", "my-service")]))
.build()
.expect("Failed to create instana exporter");
use instana_opentelemetry_sdk::propagator::Propagator;
use opentelemetry::global;
use opentelemetry::propagation::TextMapPropagator;
// Create and register the Instana propagator
let propagator = Propagator::new();
global::set_text_map_propagator(propagator);
The composite propagator allows you to use multiple propagation formats simultaneously:
use instana_opentelemetry_sdk::composite::CompositePropagator;
use instana_opentelemetry_sdk::propagator::Propagator;
use opentelemetry::global;
use opentelemetry::propagation::{TextMapPropagator, TraceContextPropagator};
// Create a composite propagator with both Instana and W3C TraceContext formats
let propagators: Vec<Box<dyn TextMapPropagator + Send + Sync>> = vec![
Box::new(Propagator::new()),
Box::new(TraceContextPropagator::new()),
];
let composite_propagator = CompositePropagator::new(propagators);
global::set_text_map_propagator(composite_propagator);
The exporter uses the following environment variables:
INSTANA_AGENT_HOST
: The hostname of the Instana agent (default: "localhost")INSTANA_AGENT_PORT
: The port of the Instana agent (default: "42699")The Options
struct provides configuration options for Exporter
:
Field | Description | Default |
---|---|---|
endpoint |
The URL endpoint for the Instana agent | http://{INSTANA_AGENT_HOST}:{INSTANA_AGENT_PORT}/com.instana.plugin.generic.rawtrace |
hostname |
The hostname to report | Empty string |
source_address |
The source address to report | Empty string |
service |
The service name to report | Empty string |
headers |
Additional HTTP headers to include in requests | Content-Type: application/json |
The Instana propagator handles the following HTTP headers:
X-INSTANA-T
: The trace ID (16 or 32 hex characters)X-INSTANA-S
: The parent span ID (16 hex characters)X-INSTANA-L
: The sampling level (0 or 1)These headers are translated to and from the OpenTelemetry SpanContext
.
X-INSTANA-T (trace ID): A string of either 16 or 32 characters from the alphabet 0-9a-f
, representing either a 64 bit or 128 bit ID. If the propagator receives a value shorter than 32 characters when extracting headers, it will left-pad the string with "0" to length 32.
X-INSTANA-S (parent span ID): A string of 16 characters from the alphabet 0-9a-f
, representing a 64 bit ID.
X-INSTANA-L (sampling level): The only valid values are 1
(sampled) and 0
(not sampled).
The project includes working examples that demonstrate how to use the Instana exporter in real-world scenarios:
Two interconnected services that demonstrate distributed tracing:
To run the examples:
cd examples
./run_servers.sh
Then visit:
For more details, see the Examples Documentation.
The exporter includes several components for serializing OpenTelemetry spans to Instana's format:
SpanData
with methods for accessing span dataApache-2.0