Consider accessing ApplicationInsights instance via import
See original GitHub issueCurrently the recommended way to access to access the ApplicationInsights instance seems to be to set it as a global, if I want to access it from another module, or to pass it to every module that needs it.
I would love it if I could simply do something like this: index.js:
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
var appInsights = new ApplicationInsights({
config: {
instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE'
}
});
appInsights.loadAppInsights();
other-module.js:
// This imports the appInsights instance that was configured with `loadAppInsights()` in index.js
import appInsights from '@microsoft/applicationinsights-web';
// appInsights.trackX();
Ideally index.js would probably looks something like this, but this would be very breaking, so probably not possible:
import { initAppInsights } from '@microsoft/applicationinsights-web';
initAppInsights({
config: {
instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE'
}
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Connection strings in Application Insights - Azure Monitor
The Application Insights JavaScript SDK requires the connection string to be passed in during initialization and configuration. It's viewable in ...
Read more >Using Azure Application Insights to Provide Business ...
With the Application Insights instance created, access it and copy the Instrumentation Key, present in the upper right corner.
Read more >Given an Applications Insight Instrumentation key, get the ...
Ideally, I would like to embed something so I could implement a page like 'myapp.com/appinsights' and this would give me the correct app ......
Read more >Application Insights - Product Documentation | ServiceNow
You can access Application Insights by logging in as a user with the admin or sn_app_insights.admin role and navigating to All > Application...
Read more >6 steps to integrate Application Insights with .Net Core ...
Net Core Web API using Visual Studio as shown below. ... The final step is to create an Application Insights instance and integrate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is how I’ve gone about implementing it and seems to be good. Basically moving away from the revealing module pattern used in the demo in favor of a class singleton-ish pattern.
Then any module can get access to the appInsights singleton.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.