ApplicationInsights-dotnet
ApplicationInsights-dotnet copied to clipboard
How to set configuration for 'Application Insights for web pages' when using Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet
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?
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.
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).
@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.
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?
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 thanks for confirming! We've taken the approach of switching to the manual snippet.
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.
@TimothyMothra so there are no plans to implement this?
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.
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.
I'm still interested in this.
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.
It's little details like this that make me dislike ASP.net and the microsoft ecosystem. These small things pile up.