-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
feat: request response tracing #462
Conversation
This is really great!! Before merging, let's discuss:
Less importantly (this might just be personal preference):
|
No. I did think about it, and I'm not sure how to do it easily. Because on the provider side we actually have a proxy, it was relatively easy. On the consumer side, we'd need to hijack the HTTP runtime (perhaps I'll spike that today).
For me, this is very much trace logging because it's passing through middleware that isn't apparent to end users that it even exists. Although I'm not ever confident in a real difference between DEBUG and TRACE - I could be convinced to abandon the use of trace altogether.
Interesting. I'm more of a fan of ramda these days anyway, and only brought across lodash to align to pact-node. Happy to make that change. |
Ah, of course. Probably the easiest place to do that is in the mock service, and communicating the results back to pact-js. This issue is probably related: pact-foundation/pact-mock_service#123 For log levels, what do you think of: DEBUG: Useful for users to debug their tests and find out why the results are what they are |
I think that's a fair delineation, but I think there will be examples where those lines cross over. But let's start with that as a guide (and perhaps add to a developer documentation). I've just pushed up a small change that allows us to log request/responses from the consumer side. It's currently wrapped in a logging guard, so in theory should be safe to release (but we shouldn't release it yet without tests - I need to think about how to do this). It needs to be refactored out of where it is and cleaned up. But it does work. What is really interesting about this change, is that in theory we have the tools within JS land to be able to give really good error messages about interactions not found etc. e.g. Or, perhaps even better... automatically redirect the request to the mock service (ala nock). The possibilities! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
8f53e29
to
456682d
Compare
Setting log level to 'trace' will log all request/response details in both provider verification and consumer tests.
456682d
to
37c3dc3
Compare
I think this is ready for review again Tim. I've made the suggested changes. There are ways to test this, but those ways involve more test code than actual code. I'm not sure how much value they'll add - but let me know. |
I reckon this is good to go! I won't merge it while Travis isn't working, but you can if you like 👍 I wrote to Travis to ask if they'll give us some OSS credits. If not/if that isn't enough, we'll have to move off them. |
This should have been there since day 1. Response logging is a little more involved (it's a stream) but I'm still not sure it's really worth the effort of writing tests. I'd say the only value, is that the tests themselves are documentation for a feature (so perhaps they are).
In any case, it produces output that looks like this:
This should allow for a) much better bug reports if there are indeed issues and b) better debugging for users trying to work out what's going on.
FWIW I did look at tools like https://github.com/expressjs/morgan until I realised that the response body wasn't captured, and I needed another plugin for that. In the end, I decided that all of the hassle of an extra library wasn't worth it, and took inspiration from several sources on the best approach to stream the response body. Wrapping the
http.write
andhttp.end
events (https://nodejs.org/api/http.html#http_response_write_chunk_encoding_callback) seemed to be the simplest option.