-
Notifications
You must be signed in to change notification settings - Fork 138
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
[Winston] Metadata passed through child logger isn't showing in Application Insights customDimensions #515
Comments
This is happening because winston's // App Insights setup
const appInsights = require('applicationinsights');
appInsights.setup('')
.setInternalLogging(true,true)
.start();
appInsights.defaultClient.config.maxBatchSize = 1;
// Require in Winston 3.x
var winston = require('winston');
var {createLogger, transports, loggers} = winston;
// App Insights custom Transport
class AppInsightsTransport extends winston.Transport {
constructor(winston, client, opts) {
super(opts);
this.winston = winston;
this.client = client;
}
mapLevelToKind(winston, level) {
let levelKind;
if (winston.config.npm.levels[level] != null) {
levelKind = "npm";
} else if (winston.config.syslog.levels[level] != null) {
levelKind = "syslog";
} else {
levelKind = "unknown";
}
return levelKind;
};
log(info, callback) {
const {message, level} = info;
const levelKind = this.mapLevelToKind(this.winston, level);
const meta = {};
const { level, message, ...splat } = info;
for (const key in splat) {
meta[key] = splat[key];
}
this.client.trackTrace({message: `${level}: ${message}`, properties: meta});
callback();
}
}
// Create the loggers
const myLogger = createLogger({
level: 'info'
});
loggers.add('MY', myLogger);
loggers.options.transports = [new AppInsightsTransport(winston, appInsights.defaultClient)];
const logger = loggers.get('MY');
logger.info('hello world'); |
@markwolff If you have the info handy, can you share more details about this, or a reference to where this is in their codebase? I'm open to creating a pull request on the Winston side if it's feasible. I just might need a little more details about what you're describing here. |
@sawyerh For a typical logging situation, there is more complexity in how it handles the metadata field, as per: Compare this to the child logging process, where it simply copies the object over, but misses out on all of the splat stuff. I'm not sure if this was intentionally left out though. |
Updating this thread to mention that I fixed this on our end here. It will land in 1.4.0 in a week or so. This PR on winston's end might also fix it: winstonjs/winston#1598 |
@markwolff, glad to see I'm not the only one who ran into this issue. I'm hoping to get my PR on Winston cleaned up and ready for re-approval this weekend if life allows. That being said I'm not super familiar with the SPLAT functionality and if you want to help verify that's working on the child/root once I get my PR up it would be greatly appreciated! |
Closing this as the fix is already released. You can just reinstall this SDK to pick up the latest version of |
@markwolff Unfortunately, |
@markwolff Sorry to pester you – any idea when |
Hey sorry for the delays. I'm aiming for Monday. |
Environment:
winston
- Version3.2.1
applicationinsights
- Version1.3.1
10.15.3
Our application is using Winston's "child loggers" feature to set metadata defaults on each trace. Below is an example:
Expected result
Given the above, I would expect to see a
trace
recorded in Application insights with the following as thecustomDimensions
shape:Actual result
What I see in my console:
But this is what I see in Application Insights (notice that
caseIndexingInfoId
andfileUploadId
are missing fromcustomDimensions
:The text was updated successfully, but these errors were encountered: