question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested metadata from winston logger shows as [object Object]

See original GitHub issue

We are using the winston logger in a node.js application. We are also using the library express-winston to log our requests. This library utilizes the metadata of winston for request and response details, which are complex objects. From my understanding in this case the following code of winston.sub.ts converts the metadata to properties for AI:

client.trackTrace(
            {
                message: event.data.message,
                severity: AIlevel,
                properties: event.data.meta
            });

edit: To be precise, it is not a problem of the winston subscription, it is also not possible to log nested metadata directly, using trackTrace(). The conversion actually happens in Util.validateStringMap.

But the type for properties has an index signature, values get typed to string. This causes nested objects to be converted to strings, resulting in [object Object]. Is it possible to change this? I can imagine several possible solutions, but i do not know if there are some limitations in the insights API, or the library. I can imagine:

  • Change the type to ‘any’ (would have to check how this gets serialized and shows up in insights then)
  • use util.inspect or JSON.stringify, may need some checks when to apply that.

We are also investigating how we can solve this on our side, finding a way around this in express-winston, or not using express-winston, but i wanted to open the issue, since it is a general problem with nested metadata objects.

regards, Thomas

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
OsvaldoRosadocommented, Oct 16, 2018

This should now work correctly in 1.0.6

2reactions
OsvaldoRosadocommented, Mar 1, 2018

Good catch! We can probably do something here to format nested objects in a sensible way before serializing it into the telemetry payload. Labeling as bug to track.

From a quick look, changing the property.toString() to JSON.stringify(property) may be all that’s needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winston logging object - node.js - Stack Overflow
The first parameter of the logger.* functions is the message (string), then you can pass a metadata object (JSON). To use the metadata...
Read more >
Complete Winston Logger Guide With Hands-on Examples
Winston creates custom logger instances which can be configured to act as centralized logging entities. Essentially, the internal architecture ...
Read more >
How to log full objects in winston (hint... Use meta data)
I'm exploring the Azure Devops API at the moment and I find logging out the API responses is far better than trying to...
Read more >
Winston Logger Ultimate Tutorial: Best Practices, Resources ...
Get an in-depth tutorial on Winston logging. Learn best practices for structuring your Node.js application so you can write easy and clean ...
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
You can change the format of this datetime value by passing an object to timestamp() as shown below. The string value of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found