Warm tip: This article is reproduced from stackoverflow.com, please click
.net-core azure azure-functions visual-studio azure-application-insights

Application Insights Search with Azure Functions

发布于 2020-03-29 21:02:17

Usually when adding Application Insights (even without configuring it) in a ASP.Net Core website, the Application Insights Search window in Visual Studio shows all the telemetry gathered (requests, exceptions, etc.).

When developing an Azure function the same window stays desperately empty and no telemetry shows up. I've checked the TelemetryConfiguration in both case and both looks the same. I highly suspect that it's a matter of host process/child process for running the function which isolate and makes it unable to see what's going on.

Am I missing something ? Is it worth opening a bug/feature request in any GitHub repo ?

Questioner
Nathanael Marchand
Viewed
97
Ivan Yang 2020-01-31 18:45

If the azure function is published to azure, then I suggest you DO NOT configure application insights locally in your function. Just follow this doc.

In your case, you develop the azure function locally in visual studio, and wan to test it application insights locally, then please follow this steps below(Note again: this is just for testing purpose, but before it is published to azure, you should remove all the settings, just publish a clean function to azure -> then configure application insights by this doc):

Step 1:Create a function in visual studio, here I created a blob trigger azure function, version v3.

Step 2:Then install this package Microsoft.Azure.WebJobs.Logging.ApplicationInsights.

Step 3:Add a file to the root of the function, the file name is ApplicationInsights.config.

The content:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
</ApplicationInsights>

Here is a screenshot of the file and it's content:

enter image description here

Step 4:In local.settings.json, add "APPINSIGHTS_INSTRUMENTATIONKEY":"any value here, even it is not a real key". Here is a screenshot:

enter image description here

Step 5:Here is the screenshot of my code in function.cs:

enter image description here

Step 6:Run the function locally, and then nav to "Application insights search", you can see the messages:

enter image description here