Skip to content

opentelemetry-otlp WASM support #3155

@jerome-caucat

Description

@jerome-caucat

I am trying to build a wasm app using the opentelemetry-otlp crate with HTTP transport, but it fails to compile for wasm32-unknown-unknown target due to Send trait requirements.

Environment:

  • Target: wasm32-unknown-unknown
  • opentelemetry-otlp version: 0.30.0
  • Features: ["http-proto", "reqwest-client"] or ["http-proto", "reqwest-blocking-client"]
  • cargo 1.88.0

Errors building opentelemetry-http:

  • error: future cannot be sent between threads safely
  • error[E0277]: Rc<RefCell<wasm_bindgen_futures::Inner>> cannot be sent between threads safely
Build logs
error: future cannot be sent between threads safely
  --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9
   |
86 |         async fn send_bytes(&self, request: Request<Bytes>) -> Result<Response<Bytes>, HttpError> {
   |         ^^^^^ future created by async block is not `Send`
   |
   = help: within `{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}`, the trait `Send` is not implemented for `*mut u8`
note: future is not `Send` as this value is used across an await
  --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:93:40
   |
89 |             let mut response = self.execute(request).await?.error_for_status()?;
   |                 ------------ has type `reqwest::Response` which is not `Send`
...
93 |                 .body(response.bytes().await?)?;
   |                                        ^^^^^ await occurs here, with `mut response` maybe used later
   = note: required for the cast from `Pin<Box<{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}>>` to `Pin<Box<dyn Future<Output = Result<http::Response<bytes::Bytes>, Box<dyn std::error::Error + Send + Sync>>> + Send>>`

error[E0277]: `Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely
   --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9
    |
86  |         async fn send_bytes(&self, request: Request<Bytes>) -> Result<Response<Bytes>, HttpError> {
    |         ^^^^^
    |         |
    |         `Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely
    |         within this `{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}`
    |
    = help: within `{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}`, the trait `Send` is not implemented for `Rc<RefCell<wasm_bindgen_futures::Inner>>`
note: required because it appears within the type `wasm_bindgen_futures::JsFuture`
   --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.50/src/lib.rs:110:12
    |
110 | pub struct JsFuture {
    |            ^^^^^^^^
note: required because it's used within this `async` fn body
   --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/reqwest-0.12.23/src/wasm/mod.rs:34:1
    |
34  | / {
35  | |     use wasm_bindgen_futures::JsFuture;
36  | |
37  | |     let js_val = JsFuture::from(promise).await.map_err(crate::error::wasm)?;
...   |
41  | |         .map_err(|_js_val| "promise resolved to unexpected type".into())
42  | | }
    | |_^
note: required because it's used within this `async` fn body
   --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/reqwest-0.12.23/src/wasm/response.rs:117:54
    |
117 |       pub async fn bytes(self) -> crate::Result<Bytes> {
    |  ______________________________________________________^
118 | |         let p = self
119 | |             .http
120 | |             .body()
...   |
132 | |         Ok(bytes.into())
133 | |     }
    | |_____^
note: required because it's used within this `async` block
   --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9
    |
86  |         async fn send_bytes(&self, request: Request<Bytes>) -> Result<Response<Bytes>, HttpError> {
    |         ^^^^^
    = note: required for the cast from `Pin<Box<{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}>>` to `Pin<Box<dyn Future<Output = Result<http::Response<bytes::Bytes>, Box<dyn std::error::Error + Send + Sync>>> + Send>>`

error: future cannot be sent between threads safely
  --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9
   |
86 |         async fn send_bytes(&self, request: Request<Bytes>) -> Result<Response<Bytes>, HttpError> {
   |         ^^^^^ future created by async block is not `Send`
   |
   = help: the trait `Send` is not implemented for `(dyn FnMut() + 'static)`
note: future is not `Send` as this value is used across an await
  --> /home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:93:40
   |
89 |             let mut response = self.execute(request).await?.error_for_status()?;
   |                 ------------ has type `reqwest::Response` which is not `Send`
...
93 |                 .body(response.bytes().await?)?;
   |                                        ^^^^^ await occurs here, with `mut response` maybe used later
   = note: required for the cast from `Pin<Box<{async block@/home/jeromecaucat/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/opentelemetry-http-0.30.0/src/lib.rs:86:9: 86:14}>>` to `Pin<Box<dyn Future<Output = Result<http::Response<bytes::Bytes>, Box<dyn std::error::Error + Send + Sync>>> + Send>>`

This old PR seems related: #2074

Is WASM target supposed to be supported for opentelemetry-otlp and opentelemetry-http?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions