poem icon indicating copy to clipboard operation
poem copied to clipboard

How to access `operation_id` in middleware?

Open banool opened this issue 2 years ago • 3 comments

Hey, I have some logging middleware where I'd love to do log based on operation_id, but I don't know how I can access that data from middleware. I can't see anything on request or next that lets me access this information about the endpoint.

Thanks!

banool avatar Jul 28 '22 15:07 banool

I'll add it tomorrow.

sunli829 avatar Jul 28 '22 15:07 sunli829

When I thought about it, I found that this is not easy to achieve, the outer middleware cannot get the operation_id. 😂

sunli829 avatar Aug 01 '22 04:08 sunli829

I see, I wonder if there is some way I can pass it in manually per route then into some middleware? Or get the function name of the handler instead?

Currently I'm using the path but that is a breaking change compared to our previous warp based method.

banool avatar Aug 01 '22 14:08 banool

I've add an example to show how to get the operation-id from the response.

https://github.com/poem-web/poem/tree/master/examples/openapi/log-with-operation-id

sunli829 avatar Aug 12 '22 06:08 sunli829

omg you're such a legend, thanks so much for this, looks like it'll work great. I'll try it out soon, probably on the next poem-openapi release to crates.io, or maybe before that if I get time. Thanks again!!

banool avatar Aug 12 '22 06:08 banool

Used it here: https://github.com/aptos-labs/aptos-core/pull/2781! Still testing but looks good!

banool avatar Aug 12 '22 06:08 banool