elastic / elastic/ecs-logging-nodejs

ecs-pino-format with convertReqRes wrong http field format

Open
#102 10 comments 1 reaction 0 assignees View on GitHub
agent-nodejs
Dominant language
JavaScript
Stars
69
Forks
45
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am using NestJS with [nestjs-pino](https://github.com/iamolegga/nestjs-pino) and I am trying to set up `ecsFormat({ convertReqRes: true })`. Logging of request and response works, but format is odd.
If this is meant for `nestjs-pino` i am sorry just let me know. Thank you

Versions I am using:
Node: 14.17.3
npm: 7.23.0
nestjs: latest setup
@elastic/ecs-pino-format: 1.3.0
nestjs-pino: 2.2.0
pino-http: 5.7.0

### Usage
```
@Module({
imports: [
LoggerModule.forRoot({
pinoHttp: { ...ecsFormat({ convertReqRes: true }) },
}),
],
})
export class AppModule {}
```

In this picture, you can see `ecsFormat` with` convertReqRes` set to `false` behaves as expected with `req` and `res` logged in their separate fields.
![convertReqRes-false](https://user-images.githubusercontent.com/31594179/135047689-6551e563-be86-4919-a2aa-196b9f13189f.png)

In this picture, convertReqRes was set to true. As you can see `response` field is in `HTTP`, but `req` is not and the log is missing `url` and `user_agent` fields (maybe others as well).
![convertReqRes-true](https://user-images.githubusercontent.com/31594179/135047679-aaf9bcd0-f971-4aee-98fa-b3ac42d5ec47.png)

### Expected behavior
Correct format as shown in [elastic/pino-http-logging](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/pino.html#pino-http-logging)

Thank you for your response, please let me know if this does not belong here.

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.