-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tracing Middleware (opentracing) #982
Comments
Glancing at https://crates.io/search?q=opentracing I don't see any opentracing middleware for Rocket, and the Rust libraries for opentracing itself look stale. If you or anyone else were to implement it in a resuable way, it might be accepted into |
Exactly as @jebrosen states. Happy to accept a PR, but it's not something the project itself should take on. As such, closing out. |
Did anyone do something? I'm in a desperate need of something that will attach requestIDs to rocket status responses etc. |
Thanks. about the request ids, they will probably need to be created. |
I never used actix, so what you mean with |
I never used actix as well, but I know it's pretty similar to rocket so I figured that I might take a look at the library in order to get some ideas for how to implement a similar middleware for rocket. /// `TracingLogger` is a middleware to capture structured diagnostic when processing an HTTP request.
/// Check the crate-level documentation for an in-depth introduction.
///
/// `TracingLogger` is designed as a drop-in replacement of [`actix-web`]'s [`Logger`].
|
Bottom line of what I'm trying to say is that if someone from the rocket team is willing to help me writing this fairing then I'll try to tackle this. |
I've done some reading about fairings and I think the minimum satisfying implementation comes down to enriching the Request with a |
Well the Is there a need of the |
I read about #[derive(Clone, Copy, Debug)]
pub struct RequestId(Uuid);
impl RequestId {
pub(crate) fn generate() -> Self {
Self(Uuid::new_v4())
}
}
pub struct RequestIdFairing;
impl Fairing for RequestIdFairing {
fn info(&self) -> Info {
Info {
name: "Request ID Attacher",
kind: Kind::Request | Kind::Response,
}
}
fn on_request(&self, request: &mut Request, _: &Data) {
request.local_cache(|| RequestId::generate());
}
fn on_response(&self, request: &Request, response: &mut Response) {
let request_id = request.local_cache(|| RequestId); // it's not clear what should I specify here to retrieve the request_id I've stored in the on_request method
response.set_raw_header("request_id", request_id.0);
}
} So the Idea with this fairing is that every request will get a request_id attached and then, in response, will retrieve this id and attach it to the response as well. But it's not working currently because clearly the retrieval is wrong:
I think after this works, there is indeed no need for a logger, but just to connect it to a tracing subscriber somehow. |
Well, I've made it work with this: pub struct RequestIdFairing;
impl Fairing for RequestIdFairing {
fn info(&self) -> Info {
Info {
name: "Request ID Attacher",
kind: Kind::Request | Kind::Response,
}
}
fn on_request(&self, request: &mut Request, _: &Data) {
request.local_cache(|| RequestId::generate());
}
fn on_response(&self, request: &Request, response: &mut Response) {
let request_id = request.local_cache(|| RequestId::generate());
response.set_raw_header("request_id", request_id.0.to_string());
}
} I also have a request guard with |
Due to some further questions and comment I have created the following repository https://github.com/somehowchris/rocket-tracing-fairing-example might it be of any help? |
Thanks, the repo is helpful indeed. I posted an issue there. |
@somehowchris thanks so much for putting that together! I've been recently working on instrumenting a high throughput rocket frontend and have had issues with tracing the async tasks without having access to the root spans. At a quick glance i'm not sure if your method will solve what I was seeing but i'll probably poke at it a bit sometime soon. |
Is there any opentracing middleware available for Rocket?
I know that middlewares have been added since #55 has been closed but before putting in some work create this middleware, I'd like to understand if there's any implementation available or
contrib
repository of sorts.The text was updated successfully, but these errors were encountered: