dmarr
How do I add a custom log reporter to nuxt?
Turns out, otel doesn't ingest stdout. There are many types of exporters using their sdk, one being console. It doesn't actually go to the collector, however. I was finally able to figure out how to log to the collector using their official sdk.
If anyone is curious..
19 replies
How do I add a custom log reporter to nuxt?
More information:
- what is structured log format https://opentelemetry.io/docs/specs/otel/logs/data-model/#log-and-event-record-definition
- really nice page with short explanation what are benefits of log4js-node https://betterstack.com/community/guides/logging/best-nodejs-logging-libraries/ (#3)
19 replies
How do I add a custom log reporter to nuxt?
Hello everyone,
I researched your current issue with logs and OpenTelemetry, and here is my summary: you should migrate from using console logging (via console.xxx) to a framework that supports structured formats.
Initially, I considered Winston, but I am leaning toward log4js-node since it has appender configurations similar to log4java.
What does this mean? You can have human-readable logs displayed in the console (as you prefer) while simultaneously configuring OpenTelemetry to export logs in a JSON-structured format. This will ensure proper export to Datadog, including all required attributes such as spans, etc.
19 replies
How do I add a custom log reporter to nuxt?
next steps might be to package this all up in a module. Add options, and maybe a reporter formatted for OTEL output. (https://opentelemetry.io/docs/specs/otel/logs/data-model/#log-and-event-record-definition)
19 replies
How do I add a custom log reporter to nuxt?
I was able to accomplish this in a few steps.
1. Create a shared util in
~/shared/utils/logging.ts
.
2. Create a plugin that exposes the logger to be used in app land.
3. Create a server util to use the logger directly in nitro land.
shared util:
plugin:
server/utils/logger.ts
(ssr usage)
server/plugins/logger.ts
19 replies