logdna / nodejs

Node.js library for logging to LogDNA
MIT License
74 stars 66 forks source link

Log metadata from different lines being merged #69

Closed elsbree closed 5 years ago

elsbree commented 5 years ago

Since we installed the most recent version of this library, we've been seeing metadata from log lines getting merged (see issue on logdna-winston). I believe this is due to this change from #66.

The line that was added is:

opts.meta = Object.assign(message.meta, opts.meta);

The problem with this is that message.meta is a reference to this._meta (assigned here), which is the default metadata object for all log lines. So the line above actually merges opts.meta into the default metadata object every time the log function is called, causing the default metadata object to grow in size and contain all keys from all previous log lines.

I'll submit a PR for this- I think the easy solution is to change the above line to

opts.meta = Object.assign({}, message.meta, opts.meta);
smusali commented 5 years ago

Thanks, @elsbree, for reporting the bug!

70 has been merged and the new versions have already been released: logdna:v3.3.1, logdna-winston:v2.2.3, and logdna-bunyan:v1.1.3.