elastic / elastic/ecs-logging-nodejs

update formatHttpRequest and formatHttpResponse to handle *client* req and res

Open
#67 3 comments 0 reactions 0 assignees View on GitHub
agent-nodejs
Dominant language
JavaScript
Stars
69
Forks
45
PR merge metrics
No merged PRs in 30d

Description

Currently `formatHttpRequest` and `formatHttpResponse` handle server-side request and response objects (from node core and some of the http frameworks). It would be nice to support the *client-side* request and response objects:

- client-side request is a
[`http.ClientRequest`](https://nodejs.org/api/all.html#http_class_http_clientrequest) returned from `http.request()` and `http.get()`
- client-side response is a
[`http.IncomingMessage`](https://nodejs.org/api/all.html#http_class_http_incomingmessage) returned from the "response" event of a client `http.request()`

Normally I'm opposed to [DWIM](https://en.wikipedia.org/wiki/DWIM)'ing, but it would be nice if it could be managed here without gross heuristics and ambiguity. Node core docs (and likely lots of community docs) commonly refer to both server-side and client-side requests and responses as `req` and `res`. Just logging those variables as is would be nice.

One potential issue is if this blows up to a desire to support many varying "client request" and "client response" objects from Node-land http client libraries. I don't know if that would be the case.

FWIW, some minor prior art is [handling for `client_req` and `client_res` log record fields in Bunyan](https://github.com/trentm/node-bunyan/blob/1.8.15/bin/bunyan#L901-L949) and [`client_req` and `client_res` serializers for Bunyan in the restify-clients package](https://github.com/restify/clients/blob/v4.0.0/lib/helpers/bunyan.js#L213-L264).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.