Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application Insights Search with Azure Functions

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 ?

like image 935
Nathanael Marchand Avatar asked Jan 30 '20 09:01

Nathanael Marchand


People also ask

How does Azure function connect to application Insights?

In your function app, select Configuration under Settings, and then select Application settings. If you see a setting named APPINSIGHTS_INSTRUMENTATIONKEY , Application Insights integration is enabled for your function app running in Azure.

How do I view Azure function logs in application Insights?

Select Application Insights from the Settings, then select View Application Insights data. This link takes you to your separate metrics resource created for you when you created your Azure Function with VS Code. Select Logs in the Monitoring section.

How do I query function app logs?

Querying the logs To query the generated logs: From your function app, select Diagnostic settings. From the Diagnostic settings list, select the Log Analytics workspace that you configured to send the function logs to. From the Log Analytics workspace page, select Logs.


1 Answers

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

like image 90
Ivan Yang Avatar answered Sep 25 '22 19:09

Ivan Yang