ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

How to set configuration for 'Application Insights for web pages' when using Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet

Open Daniel-Khodabakhsh opened this issue 5 years ago • 11 comments
trafficstars

Environment:

  • SDK version: 2.1.x, 3.1.x
  • .NET runtime version: netcoreapp2.1 netcoreapp3.1
  • Hosting Info (IIS/Azure WebApps/etc): All
  • Platform and OS version: All

Question: In this page (https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript#configuration) configuration options are listed out when using the Application Insights for web pages. This page only mentions how to add Application Insights functionality in two methods:

  • npm package
  • Snippet (with entire snippet source)

In this second page (https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-client-side-telemetry-for-web-applications) the Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet package is introduced.

How can I use the options from the first page with the NuGet package from the second page? Inspecting the contents of JavaScriptSnippet I can see that it matches the snippet from the first page.

So would this be the correct way of combining them?

@using Microsoft.ApplicationInsights.AspNetCore
@inject IJavaScriptSnippet AppInsightJavascriptSnippet
<!DOCTYPE html>
<html>
    <head>
        <script>
            @Html.Raw(AppInsightJavascriptSnippet.ScriptBody)
            aisdk.config.enableAutoRouteTracking = true; // Use configuration from first page.
        </script>
        ...
    </head>
    ...
</html>

If it is, would it be possible to update the documentation? If not, what's the intended way to combine these two functionalities?

Daniel-Khodabakhsh avatar Apr 20 '20 18:04 Daniel-Khodabakhsh

In this second page (https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-client-side-telemetry-for-web-applications) the Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet package is introduced.

This is applicable only for ASP.NET Core based web applications. We simplified the process of integrating JavaScript SDK with ASP.NET Core WebApps.

If it is, would it be possible to update the documentation? If not, what's the intended way to combine these two functionalities?

JavaScript Application Insights SDK will work with different server based application developed using ASP.NET, Java, NodeJS, etc., keeping both these documents makes more sense.

For ASP.NET Core app, using one of the way to onboard JavaScript SDK will help. If information in an article still confuses please let us know.

rajkumar-rangaraj avatar Apr 21 '20 01:04 rajkumar-rangaraj

Thanks for your response @rajkumar-rangaraj Could you confirm that the above snippet is a valid and intended way of combining those two elements?

I agree with your point that the two pages should remain separate, I wasn't suggesting they should be combined. What's missing is documentation on how to use client-side configurations when using Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet. This can probably be added to the second page (https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-client-side-telemetry-for-web-applications).

Daniel-Khodabakhsh avatar Apr 21 '20 12:04 Daniel-Khodabakhsh

@rajkumar-rangaraj I'm interested in this as well. When using the JavaScript Snippet code it only does the initialization with the instrumentation key. If I want to pass some other configuration, i.e. disable cookie tracking or some other property how do I do that? I have not seen that in provided documentation.

johnayoub avatar May 15 '20 00:05 johnayoub

I too have this same problem. Is the demonstrated code the preferred solution, or is there a way to put this in the configuration during injection?

jgentil avatar Jul 23 '20 19:07 jgentil

I'm sorry to say that we don't proxy any of the Javascript SDK configuration options. As a workaround, you can do string replacement to include extra settings. I understand this is less than ideal.

If you want full control of the Javascript SDK, you will want to manually include the snippet. Their github has more information to get started: https://github.com/microsoft/ApplicationInsights-js#basic-usage

TimothyMothra avatar Jul 23 '20 21:07 TimothyMothra

@TimothyMothra thanks for confirming! We've taken the approach of switching to the manual snippet.

jgentil avatar Jul 29 '20 14:07 jgentil

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 16 '21 00:09 github-actions[bot]

@TimothyMothra so there are no plans to implement this?

older avatar Sep 21 '21 06:09 older

There are no plans to implement additional features with the JavaScriptSnippet. The workaround is to manually add the snippet to your application.

Please continue to upvote this issue so we can judge interest in this area.

cc @MSNev so the JS team is aware of this ask.

TimothyMothra avatar Sep 21 '21 18:09 TimothyMothra

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jul 19 '22 00:07 github-actions[bot]

I'm still interested in this.

older avatar Jul 19 '22 07:07 older

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar May 17 '23 00:05 github-actions[bot]

It's little details like this that make me dislike ASP.net and the microsoft ecosystem. These small things pile up.

Daniel-Khodabakhsh avatar May 25 '23 01:05 Daniel-Khodabakhsh