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

Logger/middleware for rpc client? #972

Closed
allquixotic opened this issue Jan 18, 2023 · 10 comments
Closed

Logger/middleware for rpc client? #972

allquixotic opened this issue Jan 18, 2023 · 10 comments

Comments

@allquixotic
Copy link

I have a client class generated using the rpc macro. How can I use logger/middleware with this to see the contents of all HTTP responses, even those from failed requests that generated an Error?

@lexnv
Copy link
Contributor

lexnv commented Jan 18, 2023

Hey!

IIRC the client should log the requests and responses.
Would adding the RUST_LOG=trace when starting your program provide enough details here?

@niklasad1
Copy link
Member

niklasad1 commented Jan 18, 2023

Yes, as @lexnv said run RUST_LOG=trace and make sure that you use the tracing_subscriber because env_logger and similar doesn't output the tracing output.

You could even subscribe to certain rpc methods with the tracing stuff, example here

Further, we have no middleware for the clients but I think it should be rather trivial to add tower in the clients as well.

@allquixotic
Copy link
Author

allquixotic commented Jan 18, 2023

Thanks for the help.

However, I'm still not seeing the HTTP response body. Here is my code and the output: https://gist.github.com/allquixotic/f1b02d7e674cdd4abd72b46cb9ff2d57

I should add that the request body displayed in the trace looks good, and if I issue that request body manually, I get a 200 OK response with a session_id parameter as a response (that's what I'm looking for). Is jsonrpsee respecting the URL I provide in build()?

@niklasad1
Copy link
Member

niklasad1 commented Jan 18, 2023

jsonrpsee isn't logging the HTTP request and response so that's the reason why you can't find it.
We are logging jsonrpc related stuff but we could add it though I reckon it could be useful when debugging stuff...

I did re-run your app with logging the request and the URI looks good:

2023-01-18T15:58:32.379730Z  INFO method_call{method="User.login"}: jsonrpsee_http_client::transport: req: Builder { inner: Ok(Parts { method: POST, uri: https://www.enjin.com:443/api/v1/api.php, version: HTTP/1.1, headers: {"content-type": "application/json", "accept": "application/json"} }) }

I have no idea why the HTTP request fails but I guess bad username/password (the HTTP library we use doesn't return response body on failures)

@allquixotic
Copy link
Author

allquixotic commented Jan 18, 2023

the HTTP library we use doesn't return response body on failures

That's unfortunate. Since I can't figure out what error the server is giving me, I'm not sure how to proceed. I'm certain my credentials are correct, and the request looks good, so I need to be able to fully see the HTTP layer of the stack.

I've gotten this to work during some prototyping sessions in Python, so I know the json request body looks good.

I'm going to have to put my use of Rust on hold due to this problem and probably switch my project over to Kotlin where better debugging info is available. Thanks for the help.

@niklasad1
Copy link
Member

niklasad1 commented Jan 18, 2023

Sorry to hear, is the python prototype public somewhere so I can try it?

Let me investigate if we provide that debugging info somehow ^^

EDIT: I was wrong it jsonrpsee's fault we throw away the message if response is status() == !success

2023-01-18T19:23:43.479094Z  INFO method_call{method="User.login"}: jsonrpsee_http_client::transport: response: Response { status: 403, version: HTTP/1.1, headers: {"date": "Wed, 18 Jan 2023 19:22:14 GMT", "content-type": "text/plain; charset=UTF-8", "content-length": "16", "connection": "keep-alive", "x-frame-options": "SAMEORIGIN", "referrer-policy": "same-origin", "cache-control": "private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0", "expires": "Thu, 01 Jan 1970 00:00:01 GMT", "set-cookie": "__cf_bm=N7TiLSNzPMiM8xG6BhnHAc4.XgM.NDNRXCeL3U6NfAk-1674069734-0-AcxmqIslqlEXxNCJ3Xh6W/zLZjdpF/szdk1cL71JTAQyubcmN9rwZs9b2cNZyHERJ+Q/hzFKiOH2uEy9jsfcCKvXHWVq5ZwdTZLYrjGzJeiJ; path=/; expires=Wed, 18-Jan-23 19:52:14 GMT; domain=.enjin.com; HttpOnly; Secure", "server": "cloudflare", "cf-ray": "78b9b2c0ca07be35-CPH", "alt-svc": "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"}, body: Body(Streaming) }
body: `error code: 1020`

The error response seems to trigger some firewall rule in cloudflare.... ok then let's add this tower middleware to make this smoother in the future

@allquixotic
Copy link
Author

Also, independent of you guys doing any work on jsonrpsee to make this better, I added HTTP proxy support to jsonrpsee. See: #975

This helps me debug the raw payload :)

@allquixotic
Copy link
Author

Now I have the raw payload, working sourcecode in Python, and broken sourcecode in Rust, and I still can't figure out what jsonrpsee is doing "wrong" to cause the Enjin server to throw an error. Anyone have any idea from this? https://gist.github.com/allquixotic/34c36951c4ba19dd47882e77a0f06d23

@allquixotic
Copy link
Author

This fixed my jsonrpsee usage:

headers.insert("Accept", "*/*".parse().unwrap());
headers.insert("User-Agent", "anything".parse().unwrap());

@niklasad1
Copy link
Member

Closing this because middleware has been added to the HTTP client in #981.

I have looked at the websocket client as well but looks tricky as we have no access to that in the websocket transport library.

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

No branches or pull requests

3 participants