Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.ApplicationInsights.WorkerService does not log traces even after specifying override in config #2849

Open
karun-verghese opened this issue Feb 26, 2024 · 3 comments

Comments

@karun-verghese
Copy link

Dear team,

I have a .net core Worker service for which I had configured App Insights using the below snippet in my ConfigureServices method:

 services.AddLogging(builder =>
 {
     builder.AddConsole();
     builder.AddDebug();
     builder.AddApplicationInsightsWebJobs(options =>
     {
         options.ConnectionString = configuration.GetConnectionString("ApplicationInsights");
         options.EnableLiveMetrics = true;
     });
 });

Using this (the above snippet uses the Microsoft.Azure.WebJobs.Logging.ApplicationInsights package which I know is related to another repo, but bear with me) I was only able to see traces and exceptions in my logs. I wanted to setup telemetry to track my dependency calls as well. So after reading up, I tried to use and configure the ApplicationInsights.WorkerService library instead of the above package. So my new setup looked like below:

   var aiOptions = new ApplicationInsightsServiceOptions
   {
       EnableAdaptiveSampling = false,
       ConnectionString = configuration.GetConnectionString("ApplicationInsights")
   };

   services.AddApplicationInsightsTelemetryWorkerService(aiOptions);

My dependency telemetry started showing up, but now my traces disappeared.

Following your documentation here, I provided a specific override for ApplicationInsights in the configuration(with the "Information" level enabled) , but this did not work either. I still only saw the dependencies in my logs.

The only way I got both my traces and dependencies working is to use both the packages and configure them very specifically in the following order:

 services.AddApplicationInsightsTelemetryWorkerService(aiOptions); //This has to go first
services.AddLogging(builder =>
 {
     builder.AddConsole();
     builder.AddDebug();
     builder.AddApplicationInsightsWebJobs(options =>
     {
         options.ConnectionString = configuration.GetConnectionString("ApplicationInsights");
         options.EnableLiveMetrics = true;
     });
 });

Can you please check why the logging of traces does not work? I would expect that only the WorkerService SDK is required since it has all the providers required according to the documentation.

Further information on my setup:
.Net Core 8.0
Project SDK used -> Microsoft.NET.Sdk

@cijothomas
Copy link
Contributor

https://github.com/microsoft/ApplicationInsights-dotnet/tree/develop/examples/WorkerService There is an example shared in this repo. Is that no working? i.e is that not capturing Logs?

@karun-verghese
Copy link
Author

@cijothomas In the example you shared, do you mean the use of some CustomTelemetryProcessor? Other than that, the example looks pretty similar to what I had done above.

One question, does the fact that we are not using the Worker SDK but only the .Net SDK make a difference? That's something I did not try.

@cijothomas
Copy link
Contributor

In the example you shared, do you mean the use of some CustomTelemetryProcessor?

No. telemetry processor is just shown for example, and has no impact to telemetry pipeline.

Have you confirmed if the shared example is working or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants