Apollo Server 2.0 - Add public getters for SubscriptionServer and HTTPServer #1137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To enable people to instrument and log requests served by Apollo Server, we should expose the subscription server and http server to them.
This would allow people to make use of
Motivation:
The logging isn't very good at the moment. It's pretty terrible. If I want to understand my logs then I need to know the req which the res originated from. Currently the logging simply emits anonymous events with very little meta and I have no way to tie log entries to preceding log entries. By exposing the servers, I can at least hook into the server lifecycles and then, for example, uniquely identify each request or connection with a generated uuid to achieve some context-aware logging and add some instrumentation (response times, number of open socket connections, etc).
Along the same vein, it might be useful for the Apollo Server to use an event emitter to advertise it's own GraphQL lifecycle events (with useful callback arguments) and allow people to hook into them. The tracing and logging could then simply listen to these events, decoupled from the server itself. It'd be trivial for people to use the emitted events for their own purposes too (e.g. custom logging, tracing or other instrumentation).
Ideally I'd like to be able to tie a Query to a specific request or socket connection (and socket message).
If a maintainer will accept the premise of this PR then I will complete the CLA and the TODOs - alternatively, a maintainer can implement this in their own commits/PR
TODO: