Nested metadata from winston logger shows as [object Object]
See original GitHub issueWe 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:
- Created 6 years ago
- Comments:9 (6 by maintainers)

Top Related StackOverflow Question
This should now work correctly in 1.0.6
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()toJSON.stringify(property)may be all that’s needed.