# Hapi server emitted a log event tagged error

**URL:** <https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [May 4, 2021, 3:01pm UTC](https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081 "2021-05-04T15:01:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Aracil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javier_aracil/32/87086_2.png) [@Javier\_Aracil](https://discuss.elastic.co/u/Javier_Aracil)\
**Post date:** [May 4, 2021, 3:01pm UTC](https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081/1 "2021-05-04T15:01:59Z")

</div>

Hi,

We are getting a lot of "hapi server emitted a log event tagged error" with a hapi server.

 ![Captura de pantalla 2021-05-04 a las 16.58.30](https://us1.discourse-cdn.com/elastic/original/3X/6/9/697c246f46e6097209de7d12adb6e4f32e6b6ba4.png)

Any clue? Thanks very much, best regards

Javier

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [May 4, 2021, 7:19pm UTC](https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081/2 "2021-05-04T19:19:21Z")

</div>

Hi Javier,

The Node.js APM agent will [capture an error](https://github.com/elastic/apm-agent-nodejs/blob/v3.14.0/lib/instrumentation/modules/hapi.js#L77-L89) for any hapi [`server.log(tags, data)`](https://hapi.dev/api/?v=20.1.2#-serverlogtags-data-timestamp) call where "error" is one of the tags. If the logged `data` field is neither an Error instance nor a string, the captured error will be given a fallback message ["hapi server emitted a log event tagged error"](https://github.com/elastic/apm-agent-nodejs/blob/v3.14.0/lib/instrumentation/modules/hapi.js#L103-L105).

If it helps, the `data` passed to `server.log(['error'], data)` is included in the capture error in custom context, which should be visible in the "Metadata" tab:

![Screen Shot 2021-05-04 at 12.18.54 PM](https://us1.discourse-cdn.com/elastic/original/3X/2/6/265c5e9849e7ae8fec80cb98be0fa8c1de3fcf04.png)

At least for me (relatively new to hapi), I don't think that is very obvious, so I've opened [hapi instrumentation capturing of `server.log(['error'], ...)` is obscure · Issue #2071 · elastic/apm-agent-nodejs · GitHub](https://github.com/elastic/apm-agent-nodejs/issues/2071) to look into improving the experience here.

Thanks for bringing this up.

---

<div class="post-metadata">

**Author:** ![Javier\_Aracil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javier_aracil/32/87086_2.png) [@Javier\_Aracil](https://discuss.elastic.co/u/Javier_Aracil)\
**Post date:** [May 5, 2021, 12:53pm UTC](https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081/3 "2021-05-05T12:53:03Z")

</div>

> [@Javier\_Aracil](#):
>
> hapi server emitted a log event tagged error

Thanks Trent,

I see, in the metadata I can see the capture error:

 ![Captura de pantalla 2021-05-05 a las 14.51.23](https://us1.discourse-cdn.com/elastic/original/3X/8/a/8aae3816709d4c4e94a7fcc3076287e127b5593e.png)

Best regards,

Javier

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2021, 8:53am UTC](https://discuss.elastic.co/t/hapi-server-emitted-a-log-event-tagged-error/272081/4 "2021-05-26T08:53:06Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
