Reputation: 3253
I am trying to get app insights to work in a local .NET 7 Worker Azure Function
public class Tools
{
public Tools(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Tools>();
}
[Function("test-app-insights")]
public async Task<IActionResult> TestAppInsightsAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "tools/test-app-insights")]
HttpRequest req)
{
_logger.LogInformation("HELLOFROMNEWFUNCTION");
await Task.Yield();
var response = 0;
var okResponse = new OkObjectResult(response);
return okResponse;
}
}
I have added the code below to configure services but nothing is shown in App Insights, and there are no errors
var appInsightsConnectionString = "MY CONNECTION STRING";
services.AddApplicationInsightsTelemetryWorkerService((a =>
{
a.EnableAdaptiveSampling = false;
a.ConnectionString = appInsightsConnectionString;
}));
Does anyone know what I have missed?
I have this in the logging section of my host.json
"logging": {
"logLevel": {
"default": "Information",
"Microsoft": "Warning",
"System": "Warning",
"Host": "Error",
"Function": "Error",
"Host.Aggregator": "Information"
},
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss} {Level} | {RequestId} - {Message}{NewLine}{Exception}"
}
}
]
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true
}
}
},
Paul
Upvotes: 0
Views: 1912
Reputation: 7297
Create Application Insights Instance and copy the Instrumentation key for later use.
Create a Function App
.
Enable Application Insights
option while creating the Function App.
Select the Application Insights which we have created in the previous step.
InstrumentationKey
will be added in the Application Settings
automatically once we enable the ApplicationInsights
.My host.json
:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}
My local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"APPINSIGHTS_INSTRUMENTATIONKEY": "Copy from Application Insights "
}
}
My Traces in Azure Application Insights
Instance:
Upvotes: 3