2
votes

Anyone know of any god guide for this?

First i created an Application Insight Resource and put:

APPINSIGHTS_INSTRUMENTATIONKEY = "INSTRUMENTATION KEY"

in the Function Apps Application Settings.

I have tried implementering the nuget package for the funtion app like this.

Createing a project.json file and pasting this:

 {   
  "frameworks": {   
   "net46":{   
    "dependencies": {   
     "Microsoft.ApplicationInsights": "2.1.0"   
    }   
   }   
   }   
 }

It installed the nuget package (i could see it in the log, everything went well).

After that i put these snippets in my code to use the telemetry.TrackException(exception) functionality:

First...

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

Then:

var telemetry = new TelemetryClient(new TelemetryConfiguration("INSTRUMENTATION KEY"));

and in my catch:

telemetry.TrackException(e);

and when i try to save my Function app i get this error:

error CS1729: 'TelemetryConfiguration' does not contain a constructor that takes 1 arguments

2
What exactly are you trying to achieve? Exceptions should be sent to AppInsights automatically once you enable Application Insights integration via the portal. - Mikhail Shilkov

2 Answers

0
votes

You don't need to use reference the Application Insights library to use it with Functions. If you've already set the APPINSIGHTS_INSTRUMENTATIONKEY application setting, you can simply add the ILogger interface as a parameter to your function and it will automatically send the log data to your Application Insights instance.

Full documentation can be found here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring

0
votes

Addition to @ChrisGillum answer for .Net Core 3.1 Azure Function:

If you create a new Azure Function with Http trigger from Visual Studio the following line will exist in the example:

log.LogInformation("C# HTTP trigger function processed a request.");

Add "APPINSIGHTS_INSTRUMENTATIONKEY" to local.settings.json Values.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "<YOUR_GUID>"
  },
}

Note that the key must be in an app setting named APPINSIGHTS_INSTRUMENTATIONKEY and nothing else.

Logging is then added automatically:

enter image description here

Complete guide for hosted values:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring?tabs=cmd#enable-application-insights-integration