Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Azure Application Insights with Azure WebJob

The Azure documentation covers many examples of integrating Azure Application Insights into different applications types, such as ASP.NET, Java, etc. However, the documentation doesn't show any examples of integrating Application Insights into a Azure WebJob.

Does anyone have link to an example or article that covers how to integrate Azure Application Insights into an Azure WebJob that's built as a Console App?

like image 208
Chris Pietschmann Avatar asked Sep 09 '15 00:09

Chris Pietschmann


People also ask

How do I use app Insights in Azure?

Select Application Insights in the Azure control panel for your app service, then select Enable. Choose to create a new resource, or select an existing Application Insights resource for this application. When you click OK to create the new resource you will be prompted to Apply monitoring settings.

Why would you use Azure application Insights?

Application Insights is a feature of Azure Monitor that provides extensible application performance management (APM) and monitoring for live web apps. Developers and DevOps professionals can use Application Insights to: Automatically detect performance anomalies. Help diagnose issues by using powerful analytics tools.

How do you deploy a .NET core console application to Azure WebJob?

NET Core WebJob to Azure App Service from Visual Studio uses the same tooling as publishing an ASP.NET Core app. In Solution Explorer, right-click the project and select Publish. In the Publish dialog box, select Azure for Target, and then select Next. Select Azure WebJobs for Specific target, and then select Next.

What is the difference between Azure functions and WebJobs?

Summary. Azure Functions offers more developer productivity than Azure App Service WebJobs does. It also offers more options for programming languages, development environments, Azure service integration, and pricing. For most scenarios, it's the best choice.


1 Answers

I have written a console application that tracks events and metrics via Application Insights, and I figure a WebJob won't be all that different, by adding the following NuGet packages:

  • Microsoft.ApplicationInsights
  • Microsoft.ApplicationInsights.TraceListener (this may not be required)

My ApplicationInsights.config looks like this:

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">     <TelemetryModules>         <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights" />     </TelemetryModules> </ApplicationInsights> 

And the simple program does this:

TelemetryConfiguration.Active.InstrumentationKey = "the_key"; TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;  var tc = new TelemetryClient(); tc.TrackRequest("Track Some Request", DateTimeOffset.UtcNow, new TimeSpan(0, 0, 3), "200", true); tc.TrackMetric("XYZ Metric", 100); tc.TrackEvent("Tracked Event");  tc.Flush(); //need to do this, otherwise if the app exits the telemetry data won't be sent 

There is also this: Application Insights on Windows Desktop apps, services and worker roles

like image 177
Brendan Green Avatar answered Sep 23 '22 03:09

Brendan Green