elastic / elastic/ecs-logging-nodejs
Support convertReqRes-style ECS field mapping where req/res data is unavailable as Node http objects
- Dominant language
- JavaScript
- Stars
- 69
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
In my case I am running Node in an AWS Lambda environment where there is not a Node server running. Request data is available as [APIGatewayProxyEvent](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1536cc8b4679229d635908b5ee858b0398a5f09/types/aws-lambda/trigger/api-gateway-proxy.d.ts#L69) or [APIGatewayEventRequestContextV2](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1536cc8b4679229d635908b5ee858b0398a5f09/types/aws-lambda/trigger/api-gateway-proxy.d.ts#L160-L180) and responses as [APIGatewayProxyResult](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1536cc8b4679229d635908b5ee858b0398a5f09/types/aws-lambda/trigger/api-gateway-proxy.d.ts#L144-L154) or [APIGatewayProxyStructuredResultV2](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1536cc8b4679229d635908b5ee858b0398a5f09/types/aws-lambda/trigger/api-gateway-proxy.d.ts#L305-L313).
Ideally this context would be gathered automatically by the [apm-aws-lambda](https://github.com/elastic/apm-aws-lambda) extension and accessible by ecs-logging-nodejs via the agent. But from what I can tell this isn't the case. This library doesn't log any HTTP request/response data as part of it's APM integration. And I don't see that this API Gateway data is collected by the extension today, assuming it is even available from the AWS Lambda Logs/Telemetry APIs.
As a stopgap for an indeterminate period of time I am using AsyncLocalStorage and a Pino mixin to gather this data from my function handlers and include it in my logs following ECS conventions.
If #68 resolves with a namespace-based solution and APM support remains lacking I would like to continue logging HTTP details on top-level ECS fields for consistency with non-Lambda services. This seems possible if I could create compatible instances of `http.IncomingMessage` and `http.ServiceResponse` but Node's HTTP API seems excessively complicated for this case.
Ideally I could explicitly provide the ECS fields, similar to what I do today and how existing req/res support works. Alternately support for Fetch API [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects.
Contributor guide
Assessment
This issue has not been assessed yet.