Skip to content

Commit e071d1c

Browse files
committed
Merged PR 48137: Add App request for instrumentationKey
Add "App" request for instrumentationKey
1 parent 8e160ed commit e071d1c

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

demo/v2-demo/scripts/aisdk.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
// Application Insights setup
2-
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n)})}}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",i.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{t.cookie=i.cookie}catch(e){}t.queue=[],t.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var s="Track"+r[0];if(n("start"+s),n("stop"+s),n("addTelemetryInitializer"),n("setAuthenticatedUserContext"),n("clearAuthenticatedUserContext"),n("flush"),!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var o=a[r];a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return!0!==c&&t["_"+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s}),c},e.autoExceptionInstrumented=!0}return t}(
3-
{
4-
instrumentationKey:"ffe7093c-af96-4df9-8452-b9f4b35ccded"
1+
const appUrl = 'https://powerbiplaygroundbe.azurewebsites.net/App';
2+
3+
var appInsightsInstanceDeferred = $.Deferred();
4+
5+
$.getJSON(appUrl, function (appConfig) {
6+
// Application Insights setup
7+
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n)})}}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",i.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{t.cookie=i.cookie}catch(e){}t.queue=[],t.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var s="Track"+r[0];if(n("start"+s),n("stop"+s),n("addTelemetryInitializer"),n("setAuthenticatedUserContext"),n("clearAuthenticatedUserContext"),n("flush"),!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var o=a[r];a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return!0!==c&&t["_"+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s}),c},e.autoExceptionInstrumented=!0}return t}(
8+
{
9+
instrumentationKey: appConfig.instrumentationKey
10+
}
11+
);window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({});
12+
13+
appInsightsInstanceDeferred.resolve(appInsights);
14+
});
15+
16+
function getAppInsightsInstance() {
17+
return appInsightsInstanceDeferred;
518
}
6-
);window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({});

demo/v2-demo/scripts/telemetry.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ function trackEvent(name, properties, flush = false) {
3333
assert(name && properties);
3434
properties.sessionId = GetSession(SessionKeys.SessionId);
3535

36-
// Normally, the SDK sends data at fixed intervals (typically 30 secs) or whenever buffer is full (typically 500 items).
37-
// https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#flushing-data
38-
appInsights.trackEvent({ name, properties });
39-
if (flush) {
40-
appInsights.flush();
41-
}
36+
getAppInsightsInstance().then(function(ai) {
37+
// Normally, the SDK sends data at fixed intervals (typically 30 secs) or whenever buffer is full (typically 500 items).
38+
// https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#flushing-data
39+
ai.trackEvent({ name, properties });
40+
if (flush) {
41+
ai.flush();
42+
}
43+
});
4244
}
4345

4446
trackEvent(TelemetryEventName.SessionStart, { referrer: document.referrer }, true);

0 commit comments

Comments
 (0)