0
votes

I have a console application we deploy as a WebJob in Azure. Application Insights is working, because the telemetry is send to Azure correctly. But the "Application Insights Search" window in Visual Studio (2019) is not picking up the telemetry locally. What do I need to configure, so the application insights window will show the telemetry for the console application?

In the solution we have an MVC website and the WebJob together in the same solution. The telemetry works locally for the MVC website project, but not for the webjob project.

I have integrated Application Insights with the following code:

builder.ConfigureLogging((context, loggingBuilder) =>
{
  loggingBuilder.AddApplicationInsightsWebJobs(o =>
  {
    o.InstrumentationKey = instrumentationKey;
    o.EnableLiveMetrics = true;
    o.LiveMetricsInitializationDelay = TimeSpan.FromMinutes(1);
    o.SamplingExcludedTypes = "Exception";
  });
});

The instrumentation key comes from the appsettings.json:

  "Company.Logging": {
    "InstrumentationKey": "1242189c-1192-41d9-b877-b26890bd0eef",
    "LoggingServiceUrl": "https://loggingapidev.company.com/api/logs/batch"
  }

We use the same configuration for the website, that works.

I did try to add the "APPINSIGHTS_INSTRUMENTATIONKEY" key in the appsettings.json and as an environment variable. That didn't have any effect.

Does anyone know what I can do to make this work? It would make it more intuitive for developers to work with application insights. Now I have to direct them to the portal where they can find their local telemetry.

1
Are you using an “Environment” value (e.g. Production vs Development)? Does it behave differently in Debug vs. Release builds? Is anything mentioning AppInsights written to the VS Output window when debugging? Have you verified that your ConfigureLogging callback is being invoked at all?Dai
Thanks for you response. Just tried running with Environment=Production. The console gets a lot less chatty (no trace messages anymore), so it is picked up. But no change to the Application Insights Search window. For Debug vs Release there is no difference at allErik Steinebach
In the output you can see the json that is being send to Application Insights, so the logging itself in the app is working. I think that also means I know for sure that the ConfigureLogging is being called. The issue is not with application insights in the app, just that the Application Insights Search window doesn't understand it needs to "show" that telemetry.Erik Steinebach
@ErikSteinebach, something needs to confirm. 1: for the webjob, are you using webjob sdk, v2 or v3? 2:for the search window in vs, could you please show us a screenshot(it's better if you can provide a full screenshot)?Ivan Yang
These are the referenced nuget packages: AutoMapper.Extensions.Microsoft.DependencyInjection 8.0.1 Microsoft.Extensions.Configuration.EnvironmentVariables 3.1.7 Microsoft.Azure.WebJobs 3.0.18 Microsoft.Azure.WebJobs.Extensions 3.0.6 Microsoft.Azure.WebJobs.Extensions.Storage 4.0.2 Microsoft.Azure.WebJobs.Host.Storage 4.0.1 Microsoft.Extensions.Hosting 3.1.7 Microsoft.Extensions.Logging.Console 3.1.7 So as far as I know that is V3 correct?Erik Steinebach

1 Answers

1
votes

I tested it with console project(webjob v3), and it works fine. I can see the logs are shown in Visual Studio Application Insights Search window.

If this issue still occurs at your side, please give it a try by manually adding an empty ApplicationInsights.config file to your webjob project.

Workflow:

  • Right click project: Add -> new item...
  • Choose: Application Configuration File, like "JavaScript JSON Configuration File".
  • Name: ApplicationInsights.config
  • Remove the content of this file -> then click save. Then right right this file-> select Properties -> Set "Copy to Output Directory" as "Copy if newer"