Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include tags when hapi error events are logged #150

Closed
jonathansamines opened this issue Dec 2, 2021 · 1 comment
Closed

Include tags when hapi error events are logged #150

jonathansamines opened this issue Dec 2, 2021 · 1 comment

Comments

@jonathansamines
Copy link
Contributor

What problem are you trying to solve?
When a hapi event containing an error is logged by hapi-pino, then those errors are logged with very few context. This is specially true for server logs, where usually the context is provided by the plugin itself through the use of tags:

'use strict';

const Hapi = require('@hapi/hapi');
const Pino = require('hapi-pino');

const PluginA = {
    name: 'plugin-a',
    register(server) {
        const log = () => server.log(['error', 'plugin-a', 'operation-a'], new Error('Operation failed with error'));
        server.ext('onPreStart', log);
    }
};

const PluginB = {
    name: 'plugin-b',
    register(server) {
        const log = () => server.log(['error', 'plugin-b', 'operation-b'], new Error('Operation failed with error'));

        server.ext('onPreStart', log);
    }
};

async function run() {
    const server = Hapi.Server();

    await server.register([Pino, PluginA, PluginB]);

    return server.initialize();
}

run();

What did you get?

When the code above is executed, the additional information provided through the use of tags is missing from the log.

{"level":50,"time":1638469266007,"pid":6306,"hostname":"codespaces_02ef33","err":{"type":"Error","message":"Operation failed with error","stack":"Error: Operation failed with error\n    at log (/workspaces/hapi-pino-test-sandbox/server-logs-error-test.js:9:76)\n    at module.exports.internals.Core._invoke (/workspaces/hapi-pino-test-sandbox/node_modules/@hapi/hapi/lib/core.js:490:40)\n    at module.exports.internals.Core._initialize (/workspaces/hapi-pino-test-sandbox/node_modules/@hapi/hapi/lib/core.js:368:24)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"},"msg":"Operation failed with error"}
{"level":50,"time":1638469266008,"pid":6306,"hostname":"codespaces_02ef33","err":{"type":"Error","message":"Operation failed with error","stack":"Error: Operation failed with error\n    at log (/workspaces/hapi-pino-test-sandbox/server-logs-error-test.js:17:76)\n    at module.exports.internals.Core._invoke (/workspaces/hapi-pino-test-sandbox/node_modules/@hapi/hapi/lib/core.js:490:40)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n    at async module.exports.internals.Core._initialize (/workspaces/hapi-pino-test-sandbox/node_modules/@hapi/hapi/lib/core.js:368:13)"},"msg":"Operation failed with error"}

What did you expected?

I expected the tags information to be preserved on server logs.

@jonathansamines
Copy link
Contributor Author

Closing as this is now resolved by #151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant