1

I am trying to log into dependency table of appinsight, I am using frontend code javascript. Below is the snippet. It executes fine but I don't see any entry in dependency table of appinsight.

var appInsights = window.appInsights || function (a){function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
     }({
         instrumentationKey: '@Model.InstrumentationKey'
     });



    window.appInsights = appInsights;
    appInsights.trackDependency({target:"http://dbname", name:"select customers proc", data:"SELECT * FROM Customers", duration:231, resultCode:0, success: true, dependencyTypeName: "ZSQL"});

Is there anything wrong in above code?

2
  • Target URL looks fishy. Commented Feb 18, 2020 at 12:56
  • @net.uk.sweet yeah its just for testing, once its get working then I can update it Commented Feb 18, 2020 at 13:13

1 Answer 1

0

It should be incorrect use of trackDependency method. You can refer to this doc for the definition of trackDependency(in the page, search trackDependency).

And here is another link about how to use trackDependency method in JavaScript.

Here is a sample code, and works at my side(you can modify it to meet your need):

<script type="text/javascript">
var appInsights=window.appInsights||function(config){
    function s(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } } var t = { config: config }, r = document, f = window, e = "script", o = r.createElement(e), i, u; for (o.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", r.getElementsByTagName(e)[0].parentNode.appendChild(o), t.cookie = r.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace","Dependency"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t["_"+i](config,r,f,e,o),s}),t
}({
    instrumentationKey:"the key"
});
window.appInsights = appInsights;

// end of insertion
    appInsights.trackPageView();
    appInsights.trackTrace("sssssss114");
    appInsights.trackDependency("id", "GET", "https://www.bing.com", null, null, true, null, { prop1: 'abc' }, { meas1: 4.5 })
</script>

And the dependency data is shown in azure portal -> application insights logs:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

is trackDependency outdated now? I can only see trackDependencyData

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.