Skip to content

feat: create client span on request send#253

Open
emiliano-at-prima wants to merge 8 commits into
masterfrom
DEVEX-2966/task/no-client-span-is-created-before-making-a-request
Open

feat: create client span on request send#253
emiliano-at-prima wants to merge 8 commits into
masterfrom
DEVEX-2966/task/no-client-span-is-created-before-making-a-request

Conversation

@emiliano-at-prima
Copy link
Copy Markdown
Contributor

@emiliano-at-prima emiliano-at-prima commented May 12, 2026

Still a work in progress, but I need an early feedback because the tracing rust ecosystem is still a bit obscure to me

@emiliano-at-prima emiliano-at-prima force-pushed the DEVEX-2966/task/no-client-span-is-created-before-making-a-request branch from dab02b0 to 4333d7e Compare May 13, 2026 09:59
@emiliano-at-prima emiliano-at-prima force-pushed the DEVEX-2966/task/no-client-span-is-created-before-making-a-request branch from 4333d7e to 57a9fa5 Compare May 13, 2026 12:55
@emiliano-at-prima emiliano-at-prima marked this pull request as ready for review May 13, 2026 13:23
@emiliano-at-prima emiliano-at-prima requested a review from a team as a code owner May 13, 2026 13:23
@cpiemontese cpiemontese requested a review from MaeIsBad May 20, 2026 11:02
cpiemontese
cpiemontese previously approved these changes May 20, 2026
Copy link
Copy Markdown
Contributor

@cpiemontese cpiemontese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODOs aside +1 from me, but with otel in Rust who knows

Copy link
Copy Markdown
Member

@MaeIsBad MaeIsBad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a whole bunch of other attributes, but here are the things I'd like addressed before merging

Comment thread src/request/mod.rs Outdated
// is configurable and defaults to the request method
// TODO: server.address should be probably set after the host is resolved
// and we actually have the server address, we are using the hostname here
#[cfg(feature = "_any_otel_version")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: we should unconditionally support tracing by itself without otel

Comment thread src/request/mod.rs
);

#[cfg(feature = "_any_otel_version")]
let headers = client_span.in_scope(|| self.get_all_headers());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of instrumenting everything manually like this can't we extract the rest of the function into a separate function(or an async {} block) and .instrument that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved that block to a send_request function in 41b083f types look a bit strange but it compiles

Comment thread src/request/mod.rs Outdated
Comment thread src/request/mod.rs Outdated
"http.request.method" = %method.as_str(),
"server.address" = %url.host().map(|h| h.to_string()).unwrap_or_default(),
"server.port" = %url.port_or_known_default().map(|p| p.to_string()).unwrap_or_default(),
"url.full" = %url.as_str(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could include credentials(url.username and url.password), we need to redact those
https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here 99191c6

Comment thread src/request/mod.rs Outdated
.send()
.await?;

let status_code = response.status();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also set http.response.status_code here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in cd8160f

Comment thread src/request/mod.rs Outdated
Comment on lines +174 to +175
// TODO: the span name on [telepoison](https://github.com/primait/telepoison/blob/b65bcc3bf4ee7744a49ae7ffa040302ab5fe3ce4/lib/telepoison.ex#L160)
// is configurable and defaults to the request method
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference here's what the spec has to say(it agrees with the todo comment, I just think it's useful to have)

https://opentelemetry.io/docs/specs/semconv/http/http-spans/#name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still looking for a way to set the span name dynamically with tracing, not sure how to do that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently you cannot, but the opentelemetry exporter should receive otel.name so we are good

Comment thread src/request/mod.rs Outdated
let resp_headers = response.headers().clone();
let resp_vec = response.bytes().await.map(|b| b.to_vec());

Ok::<_, PrimaBridgeError>((status_code, resp_headers, resp_vec))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set the span status to error on error(again per the spec)

https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status

This is not required of us though

Copy link
Copy Markdown
Contributor Author

@emiliano-at-prima emiliano-at-prima May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dbcb2e5

@emiliano-at-prima emiliano-at-prima force-pushed the DEVEX-2966/task/no-client-span-is-created-before-making-a-request branch from d33b4ea to 99191c6 Compare May 22, 2026 07:18
@emiliano-at-prima emiliano-at-prima requested review from a team and MaeIsBad May 22, 2026 07:24
Copy link
Copy Markdown
Member

@MaeIsBad MaeIsBad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have test infra for tracing in this repo, but that's out of scope here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants