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

Init tracing #28

Merged
merged 18 commits into from
Aug 25, 2023
Merged

Init tracing #28

merged 18 commits into from
Aug 25, 2023

Conversation

gorm-issuu
Copy link
Contributor

No description provided.

kanin/Cargo.toml Outdated Show resolved Hide resolved
@@ -79,7 +80,11 @@ where
// Requests are handled and replied to concurrently.
// This allows each handler task to process multiple requests at once.
tasks.push(tokio::spawn(async move {
handle_request(req, handler, channel, should_reply).await;
let req_id = ReqId::extract(&mut req).await.expect("infallible");
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I think if we're extracting a req_id for every request anyway, shouldn't we just extract it as part of Request::new and store it in the request? Then the Extract impl for ReqId can also be simplified to just take the stored ReqId from the request directly.

Or instead of storing it, at least just have a method on Request that gets the ReqId from the delivery inside, then the Extract impl could use that. But if we extract it every time anyway, maybe storing it isn't so bad? Any handler with an RPC client would be able to avoid extracting it twice then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I def agree with that. Seems wild to extract it every time. Also a lot easier on the eyes to just write req.req_id().

Comment on lines 108 to 112
let app_id = properties
.as_ref()
.and_then(|p| p.app_id().as_ref())
.map(|app_id| app_id.as_str())
.unwrap_or("<unknown>");
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of similar but I feel this should be a method in Request, so this can just be req.app_id().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's definitely prettier ;)

kanin/src/app/task.rs Outdated Show resolved Hide resolved
kanin/src/app/task.rs Outdated Show resolved Hide resolved
kanin/src/extract/req_id.rs Outdated Show resolved Hide resolved
kanin/src/extract/req_id.rs Outdated Show resolved Hide resolved
kanin/src/extract/req_id.rs Show resolved Hide resolved
kanin/src/extract/req_id.rs Outdated Show resolved Hide resolved
kanin/src/tests/send_recv.rs Outdated Show resolved Hide resolved
gorm-issuu and others added 10 commits August 25, 2023 10:58
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
Co-authored-by: Victor Nordam Suadicani <[email protected]>
"Handler {:?} produced response: {response:?}",
std::any::type_name::<H>()
);
info!("Handler produced response: {response:?}");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the name of the handler here (it feels weird that it's printed twice when you can just use the req_id to deduct the name.

But I have a concern about printing the full response of every single request. For small responses it's no problem; but it doesn't seem right thing to do as the default for every service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

info!("Handler produced response of {} bytes that will be published on {reply_to}", bytes_response.len());

could be an option.

Copy link
Contributor

Choose a reason for hiding this comment

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

There won't always be a reply_to. But maybe you can log in the different scenarios of reply_to/no reply_to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this? :)

kanin/src/request.rs Outdated Show resolved Hide resolved
@@ -25,6 +29,7 @@ impl Request {
Self {
state,
channel,
req_id: ReqId::from(&delivery),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the usage of the From trait here is slightly unnecessary (a simple from_delivery method would do) but it's not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am actually not a super big fan of these impl's (as with the example with thiserror), so I'll be happy to change it :)

kanin/src/request.rs Outdated Show resolved Hide resolved
@@ -25,6 +25,7 @@ use super::StateMap;
pub(super) type HandlerTask = Pin<Box<dyn Future<Output = String> + Send>>;

/// Creates the handler task for the given handler and routing key. See [`HandlerTask`].
#[tracing::instrument(skip_all, field(routing_key = routing_key))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't see this before. Won't this add yet another layer of a span? How does it look when printed? Is it too much?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh! I think this was just me debugging/exploring. It doesn't do anything because.. yeah.. I'm not sure tbh.

@gorm-issuu gorm-issuu marked this pull request as ready for review August 25, 2023 12:16
@gorm-issuu gorm-issuu requested a review from a team as a code owner August 25, 2023 12:16
@gorm-issuu gorm-issuu merged commit 1a39461 into main Aug 25, 2023
5 checks passed
@gorm-issuu gorm-issuu deleted the add-tracing branch August 25, 2023 12:35
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.

2 participants