I read this article about adding tracing to logs and it inspired me to want to enable this inside my hapi/hapi-pino project.
I registered hapi-pino as a hapi plugin just like the docs recommend (below). I'm wondering if it would make more sense to register a separate cls-pino-logger plugin or if it would be recommended to do it somehow inside of hapi-pino? Thanks in advance for any guidance.
import { clsProxify, clsProxifyNamespace, setClsProxyValue } from 'cls-proxify'
import * as Pino from "pino";
const logger = Pino();
const loggerCls = clsProxify('clsKeyLogger', logger)
const handler = function (request, h) {
clsProxifyNamespace.bindEmitter(request);
clsProxifyNamespace.bindEmitter(request.response);
clsProxifyNamespace.run(() => {
const headerRequestID = request.headers.Traceparent
// this value will be accesible in CLS by key 'clsKeyLogger'
// it will be used as a proxy for `loggerCls`
const loggerProxy = {
info: (msg: string) => `${headerRequestID}: ${msg}`,
}
setClsProxyValue('clsKeyLogger', loggerProxy)
})
};
exports.plugin = {
name: 'cls-trace-logger',
register: function (server, options) {
server.route({ method: 'GET', path: '/test/cls', handler });
loggerCls.info('My message!');
}
};
But I get this error:
[```
1597365833550] ERROR (55306 on ip-192-168-2-50.ec2.internal): request error
err: {
"type": "AssertionError",
"message": "can only bind real EEs",
"stack":
AssertionError [ERR_ASSERTION]: can only bind real EEs
I read this article about adding tracing to logs and it inspired me to want to enable this inside my hapi/hapi-pino project.
I registered hapi-pino as a hapi plugin just like the docs recommend (below). I'm wondering if it would make more sense to register a separate cls-pino-logger plugin or if it would be recommended to do it somehow inside of hapi-pino? Thanks in advance for any guidance.
I created a plugin per the hapi plugin docs:
But I get this error: [``` 1597365833550] ERROR (55306 on ip-192-168-2-50.ec2.internal): request error err: { "type": "AssertionError", "message": "can only bind real EEs", "stack": AssertionError [ERR_ASSERTION]: can only bind real EEs