actix-web-opentelemetry icon indicating copy to clipboard operation
actix-web-opentelemetry copied to clipboard

No spans are emitted

Open alanwest opened this issue 5 months ago • 2 comments

I am trying to use actix-web-opentelemetry with the latest version of opentelemetry-rust. I am sending data to a local OpenTelemetry collector. I've modified the client/server example from this repository very slightly updating it to the latest version of opentelemetry-rust and configuring it to export to my local collector.

When I run the example from this repo it works just fine. However, when I run the same example outside of this repo, it does not work.

Steps to reproduce:

  1. Create a collector config file named otelcol-contrib-config.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  batch:

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug]
  1. Run the collector
docker run --rm \
    -p 4317:4317 \
    -v .:/etc/otelcol-contrib \
    otel/opentelemetry-collector-contrib:0.102.1 \
    --config=/etc/otelcol-contrib/otelcol-contrib-config.yaml
  1. Create the rust application

Cargo.toml

[package]
name = "no_span"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-web = "4.8.0"
actix-web-opentelemetry = "0.18.0"
opentelemetry = "0.24.0"
opentelemetry-otlp = "0.17.0"
opentelemetry_sdk = { version = "0.24.1", features = ["rt-tokio-current-thread"] }

main.rs

use actix_web::{web, App, HttpRequest, HttpServer};
use actix_web_opentelemetry::RequestTracing;
use opentelemetry::{global, KeyValue};
use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime::TokioCurrentThread, Resource, trace};

async fn index(_req: HttpRequest, _path: actix_web::web::Path<String>) -> &'static str {
    "Hello world!"
}

#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    global::set_text_map_propagator(TraceContextPropagator::new());

    let service_name_resource = Resource::new(vec![KeyValue::new(
        "service.name",
        "actix_server"
    )]);

    let tracer_provider = opentelemetry_otlp::new_pipeline()
        .tracing()
        .with_exporter(opentelemetry_otlp::new_exporter().tonic())
        .with_trace_config(
            trace::Config::default()
                .with_resource(service_name_resource)
        )
        .install_batch(TokioCurrentThread)
        .expect("pipeline install error");

    HttpServer::new(move || {
            App::new()
                .wrap(RequestTracing::new())
                .service(web::resource("/users/{id}").to(index))
        })
        .bind("127.0.0.1:8080")?
        .run()
        .await?;

    global::set_tracer_provider(tracer_provider);

    global::shutdown_tracer_provider();

    Ok(())
}
  1. Run the application and hit http://localhost/users/1. No span is exported.

alanwest avatar Sep 04 '24 20:09 alanwest