Last active
November 3, 2017 09:20
-
-
Save jshcrowthe/834ce956327e71d3f1c192ca976d504e to your computer and use it in GitHub Desktop.
yeoman/insights ApplicationInisights Provider Sandboxing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
// ALL THE OTHER PROVIDERS ARE HERE | |
applicationinsights(id, payload) { | |
/** | |
* This feels like it's in the right direction, IDK | |
*/ | |
const ai = require('applicationinsights'); | |
/** | |
* I'm assuming that the tracking code is the instrumentationId, | |
* if I'm wrong then you just gotta somehow get that ID here | |
*/ | |
const client = ai.TelemetryClient(this.trackingCode); | |
/** | |
* This here is the tricky bit, you need the correlationId from | |
* a TelemetryClient context. The problem is, that data is fetched | |
* async. So it won't be readily available, additionally, it doesn't | |
* seem like the insight class is instrumented for async provider init either | |
* so this may be a tad involved but I may be missing something obvious. | |
* Wouldn't be the first time. | |
*/ | |
return { | |
url: client.config.endpointUrl, | |
method: 'POST', | |
headers: { | |
/** | |
* Header format stolen from: | |
* https://github.com/Microsoft/ApplicationInsights-node.js/blob/master/AutoCollection/HttpDependencies.ts#L117-L119 | |
*/ | |
'request-context': `appId=${client.config.correlationId},roleName=${client.context.tags[client.context.keys.cloudRole]}` | |
}, | |
// OTHER STUFF (I'm assuming this is log data and what not) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment