I am trying to apply @elastic/ecs-pino-format to nestjs-pino. Under the good nestjs-pino is using http-pino
. I have noticed that http-pino
adds the request object inside [Symbol(pino.chindings)]
and I am assuming it's using a child logger.So I tried to write a custom formatter for extracting the req by calling obj.res.log.bindings()
and putting at http.request
to be compliant with Elastic Common Schema (ecs). The problem I face is now my log contains duplicate the req
and the http.request
and can't find a way to remove it. Not sure if I am looking in the wrong direction but I have found a lot of issues trying to make nestjs-pino print Elastic Common Schema (ecs) format logs. Also I have noticed issues where @elastic/ecs-pino-format can't handle fastify. Has anyone had similar issues ?
Asked
Active
Viewed 1,945 times
1

Georgios Kampitakis
- 388
- 3
- 9
1 Answers
1
So I was confused with pino
and pino-http
and how they were integrated in nestjs-pino. From the looks of it @elastic/ecs-pino-format doesn't handle all the specifics for Elastic Common Schema (ecs) in pino-http
. So what I ended up doing was passing in nestjs-pino
as a configuration a merge of the format object from @elastic/ecs-pino-format and configuring pino-http
.
pino-http
supports passing
customAttributeKeys: {
req: 'http.request',
res: 'http.response',
}
for changing the keys of req
and res
. As for the data that req
and res
contain, http-pino
has another option for transforming them
serializers: {
req: (log) => {... return transform },
res: (log) => {... return transform },
}
For more information about pino HTTP options.
Hope this helps anyone facing the same problem or want nestjs with Elastic Common Schema (ecs) logs.
An example configuration passed to http-pino
for having ECS format.

Georgios Kampitakis
- 388
- 3
- 9
-
Hey Georgios, any chance you could share a snippet of how you achieved this? I'm trying to do the exact same thing and it's not immediately obvious how to do so while still getting all the nestjs-pino features. – Seth Jul 29 '22 at 18:30
-
You can create a configuration like this and pass it to nestjs-pino options. https://gist.github.com/gkampitakis/b36819f38f8886598c20ed1af7245e3a – Georgios Kampitakis Jul 30 '22 at 19:27
-
1One comment is the Error passed to "formatError" should be "err" and not "error", though I'm not sure if this my setup vs. yours. – Seth Aug 01 '22 at 14:39