aws-otel-lambda icon indicating copy to clipboard operation
aws-otel-lambda copied to clipboard

Rust support

Open ymwjbxxq opened this issue 2 years ago • 3 comments

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

ymwjbxxq avatar Sep 11 '22 13:09 ymwjbxxq

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)
}

frankhorv avatar Sep 22 '22 13:09 frankhorv

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

Cannot compile with opentelemetry = "0.18.0"

It is fine with opentelemetry = "0.17.0"

ymwjbxxq avatar Oct 09 '22 07:10 ymwjbxxq

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

ymwjbxxq avatar Oct 10 '22 08:10 ymwjbxxq

This issue is stale because it has been open 90 days with no activity. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled

github-actions[bot] avatar Jan 08 '23 20:01 github-actions[bot]

This issue was closed because it has been marked as stale for 30 days with no activity.

github-actions[bot] avatar Feb 12 '23 20:02 github-actions[bot]