Rust support

3
open
ymwjbxxq
ymwjbxxq
Posted 2 months ago

Rust support #295

Is your feature request related to a problem? Please describe. Currently, Rust is not officially supported https://aws-otel.github.io/docs/getting-started/x-ray

Describe the solution you'd like Need the ability to manual instrument a Lambda with custom runtime (Rust) with X-Ray here

Describe alternatives you've considered None available

Additional context tried using the "aws-otel-collector-arm64-ver-0-56-0" I can see my spans in CloudWatch but I am pretty sure I miss something because I don't see any span in x-ray

fn init_tracer() -> sdkTracer {
    global::set_text_map_propagator(XrayPropagator::

    stdout::new_pipeline()
        .with_trace_config(
            config()
                .with_sampler(Sampler::AlwaysOn)
                .with_id_generator(XrayIdGenerator::default()),
        )
        .install_simple()
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    let tracer = init_tracer();
    
    tracing_subscriber::fmt()
        .with_ansi(false)
        .without_time()
        .with_max_level(tracing_subscriber::filter::LevelFilter::INFO)
        .init();

    let config = aws_config::load_from_env().await;
    let dynamodb_client = aws_sdk_dynamodb::Client::new(&config);

    // other stuff

    lambda_http::run(service_fn(|event: Request| {
      tracer.in_span("root", |cx| {
           my_handler(event, cx)
      })
    })).await?;
   
    global::shutdown_tracer_provider();
    Ok(())
}

pub async fn my_handler(event: Request, ctx: Context) -> Result<impl IntoResponse, Error> {
   ctx.span().add_event("calling dyanmodb", vec![]);
  //dynamodb query
  ctx.spaIt).add_event("doing something else", vec![]);
}

Thanks

frankhorv
frankhorv
Created 2 months ago

I can see the trace spans in X-Ray by using the OTLP exporter and "aws-otel-collector-amd64-ver-0-58-0":

pub(crate) fn opentelemetry_tracer(app_name: &str, version: &str) -> Result<Tracer, TraceError> {
    global::set_text_map_propagator(XrayPropagator::new());

    let environment = match std::env::var("DEPLOYMENT_ENVIRONMENT") {
        Ok(env) => env,
        _ => "development".to_string(),
    };

    opentelemetry_otlp::new_pipeline()
        .tracing()
        .with_exporter(opentelemetry_otlp::new_exporter().tonic().with_env())
        .with_trace_config(
            trace::config()
                .with_resource(Resource::new(vec![
                    KeyValue::new(semcov::resource::SERVICE_NAME.to_string(), app_name.to_string()),
                    KeyValue::new(semcov::resource::SERVICE_VERSION.to_string(), version.to_string()),
                    KeyValue::new(
                        semcov::resource::SERVICE_INSTANCE_ID.to_string(),
                        gethostname::gethostname().to_string_lossy().to_string(),
                    ),
                    KeyValue::new(semcov::resource::SERVICE_NAMESPACE.to_string(), environment.to_string()),
                ]))
                .with_sampler(Sampler::AlwaysOn)
                // Needed in order to convert the trace IDs into an Xray-compatible format
                .with_id_generator(trace::XrayIdGenerator::default()),
        )
        .install_batch(opentelemetry::runtime::Tokio)
}
ymwjbxxq
ymwjbxxq
Created 1 month ago

global::set_text_map_propagator(XrayPropagator::default());

Cannot compile with opentelemetry = "0.18.0"

It is fine with opentelemetry = "0.17.0"

ymwjbxxq
ymwjbxxq
Created 1 month ago

What really strange is:

  • I can see the SpanData in CloudWatch but not in X-RAY
  • Maybe it is stdout::new_pipeline(), but this is what I see from the few examples around