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

How to access operation_id in middleware? #351

Closed
banool opened this issue Jul 28, 2022 · 6 comments
Closed

How to access operation_id in middleware? #351

banool opened this issue Jul 28, 2022 · 6 comments
Labels
question Further information is requested

Comments

@banool
Copy link
Contributor

banool commented Jul 28, 2022

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 banool added the question Further information is requested label Jul 28, 2022
@sunli829
Copy link
Collaborator

I'll add it tomorrow.

@sunli829
Copy link
Collaborator

sunli829 commented Aug 1, 2022

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

@banool
Copy link
Contributor Author

banool commented Aug 1, 2022

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.

@sunli829
Copy link
Collaborator

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

@banool
Copy link
Contributor Author

banool commented Aug 12, 2022

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
Copy link
Contributor Author

banool commented Aug 12, 2022

Used it here: aptos-labs/aptos-core#2781! Still testing but looks good!

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