question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation for addTelemetryInitializer is unclear

See original GitHub issue

I am trying to use addTelemetryInitializer as per the documentation but it is unclear because the docs (API-reference.md) refer to:

window.appInsights = appInsights;

// Add telemetry initializer
appInsights.trackPageView();

but the JS code from the portal does not look like that, it looks like this:

var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var etc...
{
     instrumentationKey:"key"
}); window[aiName] = aisdk,aisdk.queue && aisdk.queue.length ===0 && aisdk.trackPageView({});;

I tried splitting the last line and ended up with

}); window[aiName];
// Add my initializer here
aisdk.queue && aisdk.trackPageView({});

But this doesn’t seem to work. The initializer is not called and I cannot see the call to track in the network monitor. Is there some more clear documentation about how this works with the new JS snippet?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jakenutscommented, Jan 2, 2020

Aha! Here is one that works… I left in the check for an empty queue as it seems like a safety check to make sure a duplicate snippet doesn’t cause the page to track twice… Turns out the non-minified snippet (here) sets up the addTelemetryInitializer function to automatically queue calls so you can use it right away rather than pushing your own function on the queue.

    var sdkInstance="appInsightsSDK";... (
    {
      instrumentationKey:"<key>"
    }
    );window[aiName]=aisdk; /*removed track here*/
       
    if (aisdk.queue && 0 === aisdk.queue.length) {
        aisdk.addTelemetryInitializer(function (evlp) {
            evlp.tags["ai.application.ver"] = '<your app version>;
        });        

        aisdk.trackPageView({}); 
    }
2reactions
jakenutscommented, Jan 2, 2020

Same here. Searched all of github for someone adding an application version to telemetry and there’s not a single instance of someone using the new snippet and adding any custom initializers. All my attempts to add a TelemetryInitializer with the current snippet result in the page going untracked (even when the queue empty test is removed). Really odd since this has to be the #1 method for people using AI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I call addTelemetryInitializer when using the latest ...
Please try the code below, I can add a custom property by using the latest javascript code snippet: var sdkInstance="appInsightsSDK" ...
Read more >
D365 TypeScript Web Resources - Part 6 - Application Insights
It can monitor and analyze telemetry from mobile apps by integrating with Visual Studio App Center. https://docs.microsoft.com/en-us/azure/azure ...
Read more >
Azure Application Insights for JavaScript web apps
The input argument to addTelemetryInitializer is a callback that takes a ITelemetryItem as an argument and returns boolean or void . If false...
Read more >
Renovate Bot Package Diff
+ of this software and associated documentation files (the "Software"), to deal ... string"&&(Dy.diag.error("Cannot create baggage metadata from unknown ...
Read more >
Automated Malware Analysis Report for https://forms.office.com/r ...
Source: unknown, Network traffic detected: HTTP traffic on port 443 -> 49722. Source: unknown, Network traffic detected: HTTP ... Sec-Fetch-Dest: document
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found