Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misuse of span.record in tracing middleware #797

Open
tombanksme opened this issue Apr 5, 2024 · 2 comments
Open

Misuse of span.record in tracing middleware #797

tombanksme opened this issue Apr 5, 2024 · 2 comments
Labels
question Further information is requested

Comments

@tombanksme
Copy link

tombanksme commented Apr 5, 2024

Hello,
I was looking through the poem source code and noticed an issue in the tracing middleware.

The tracing docs say:

Note: The fields associated with a span are part of its Metadata. The Metadata describing a particular span is constructed statically when the span is created and cannot be extended later to add new fields. Therefore, you cannot record a value for a field that was not specified when the span was created:

Source

It appears that poem violates that rule in the tracing middleware.

I've not actually validated this is an issue; just something I ran into on another project.

I'm fairly new to Rust and the Tracing crate so I might be mistaken. I'm happy to raise a pull request for the fix.

@tombanksme tombanksme added the question Further information is requested label Apr 5, 2024
@tombanksme
Copy link
Author

tombanksme commented Apr 5, 2024

Just had a chance to take a look and I don't think the PathPattern extraction for the tracing middleware works at all.

Using with(Tracing) creates a TracingEndpoint<Route> where TracingEndpoint::call is called first and then it passes the request onto Route::call. PathPattern is added to the request by Route::call so it doesn't exist when TracingEndpoint::call is called.

Does anyone have ideas of how we could fix this?

The only solution I can think of is to change the signature of Endpoint::call from fn call(&self, mut req: Request) to fn call(&self, &mut req: Request) so that we can read from the request after calling Route::call although I dread to think what other issues this change would cause.

@sunli829
Copy link
Collaborator

  1. 'PathPattern' exists only with 'Route'.

let pattern = match matches.data.pattern.strip_suffix("/*--poem-rest") {

  1. It just prepared span before, but actually use it here.

.instrument(span)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants