I am totally in despair and probably is it just a minor detail I am missing, but I cannot figure it out.
Description
I am following Application Insights for Worker Service applications (non-HTTP applications), and here is some details.
My package references:
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
My secret.json
"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=xxxx;IngestionEndpoint=https://somewhere-0.in.applicationinsights.azure.com/",
}
The code follows the link mentioned, but just to put it here. Program.cs
services.AddLogging();
services.AddHostedService<TimedHostedService>();
services.AddApplicationInsightsTelemetryWorkerService();
Worker.cs
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
using (_telemetryClient.StartOperation<RequestTelemetry>("operation"))
{
_logger.LogWarning("A sample warning message.");
_logger.LogInformation("Calling bing.com");
var res = await _httpClient.GetAsync("https://bing.com");
_logger.LogInformation("Calling bing, status:" + res.StatusCode);
_telemetryClient.TrackEvent("Bing call event completed");
_telemetryClient.Flush();
}
await Task.Delay(5000, stoppingToken);
In Visual Studio I can see events ticking in.
Problem
After days, I have not been able to get anything to be apper in Azure Portal. I wanted one web application and some containers to report to the same log analytics and azure application insights. However, no luck so far.
The web application whom is deployed to Azure app service reports fine.
The containers are supposed to run on a local datacenter (on premise), but now I am running them in a Docker Desktop.
Questions.
I simply have no idea how to figure out what I am missing, so it will just be a series of questions what pops into my head. Is there something blocking from Docker? Must I adjust something in Azure Portal? Do I need to set something up on my computer? Is there a settings somewhere stating that the app should not transmit to application insights because it is a development enviroment? (I could go on for ever).
I am pretty sure this has an easy answer, but Google is not my friend these days.
Any help will be appreciated.
2
Answers
I followed the same MSDOC you shared. I can be able to get all telemetry data in Application Insights. I hope you followed all the things mentioned in the document.
Please check below to overcome the issue
Program.cs
likeRefer usage of Custom Operation Tracking in Application Insights
services.AddApplicationInsightsTelemetryWorkerService();
With this method, the connection string must be part of application’s IConfiguration. I am not sure if secrets.json is automatically loaded into IConfiguration.
You can confirm this by using the following snippet: