Open chayankar opened 5 months ago
Could you please try using the setup code mentioned in our documentation here?
When deploying your app, simply add the APPINSIGHTS_INSTRUMENTATIONKEY
app setting entry with the correct value (which you can obtain from your Application Insights resource). That should do the trick.
By following this model, your dotnet isolated function will send logs directly to Application Insights, bypassing the host, similar to how AI integration works for any .NET application.
Let us know how that goes.
Could you please try using the setup code mentioned in our documentation here?
When deploying your app, simply add the
APPINSIGHTS_INSTRUMENTATIONKEY
app setting entry with the correct value (which you can obtain from your Application Insights resource). That should do the trick.By following this model, your dotnet isolated function will send logs directly to Application Insights, bypassing the host, similar to how AI integration works for any .NET application.
Let us know how that goes.
Is there an issue with using the Application Insights connection string? Since instrumentation key support will end in less than a year. "On March 31, 2025, support for instrumentation key ingestion will end. Instrumentation key ingestion will continue to work, but we'll no longer provide updates or support for the feature. Transition to connection strings to take advantage of new capabilities." https://learn.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string?tabs=dotnet5
Could you please try using the setup code mentioned in our documentation here?
When deploying your app, simply add the
APPINSIGHTS_INSTRUMENTATIONKEY
app setting entry with the correct value (which you can obtain from your Application Insights resource). That should do the trick.By following this model, your dotnet isolated function will send logs directly to Application Insights, bypassing the host, similar to how AI integration works for any .NET application.
Let us know how that goes.
I have followed the mentioned documentation
Deployed function app has right set of APPINSIGHTS_INSTRUMENTATIONKEY & APPLICATIONINSIGHTS_CONNECTION_STRING as well. How do I know it is right? Because the setting is imported into local.settings.json & when the function is running locally, I can see the logs in AI.
But logs are not reaching AI from deployed function app. I know that the function app is executing because i can see entries in exception table in AI. But I don't see any entries in traces.
I am obtaining logger instance from FunctionContext.GetLogger(
@chayankar
How do I know it is right?
How do you know "what" is right? Can you be more specific?
The local.settings.json
is a file to define your app settings when running locally. It has no role when your app is running on azure. You need to specify your app settings under "Settings -> Environment variables -> App settings"
Can you try creating a new AI resource, copy it's connection string and update your deployed app's APPLICATIONINSIGHTS_CONNECTION_STRING
app setting to have this new value, then restart the app and see that works? Also remove the APPINSIGHTS_INSTRUMENTATIONKEY
(You don't need both of them(
Use below code in Program.cs, it will start working, Also do proper DI in function class for ILogger,
var host = new HostBuilder() .ConfigureFunctionsWebApplication() .ConfigureServices(services => {
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.ConfigureLogging(logging =>
{
logging.Services.Configure
FYI, the workaround supplied by @sopya88 above doesn't fix anything, at least in the solution I'm running.
Currently I'm using .net 8 isolated Have you consider move host var into Program.cs instead of Startup.cs
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services => {
services.AddLogging();
})
.Build();
host.Run();
and if you need to use activity log, like getting the operationId or RootId (using System.Diagnostics), , I've found that Azure.Core under Functions.Worker need to be 1.41.0 or later which should included the supported DiagnosticSource version
What version of .NET does your existing project use?
.NET 6
What version of .NET are you attempting to target?
.NET 6
Description
Upgrading azure function in-process model into isolated model. Followed the steps mentioned [here](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows#logging)
When running the function locally, I can see the logs reaching Application Insight, but after deploying it into azure I don't see logs reaching Application Insight, neither in Log Stream.
When working locally, I imported application settings from deployed function app in azure. I am sure that APPINSIGHTS_INSTRUMENTATIONKEY & APPLICATIONINSIGHTS_CONNECTION_STRING are correct.
I tried using Serilog for writing logs into Application Insight using Serilog.Sinks.ApplicationInsights (4.0.0) but the result is same as above.
Used both approaches for obtaining logger instance: Using dependency insjection & via FuctionContext.GetLogger(categoryName) method.
My question is: If function is generating logs when ran locally, then why is it not working as expected in azure? Is the worker process not communicating with host? Is there any other unknown configuration which is overriding my code? Do we have to define log level for the categaoryName parameter passed into FuctionContext.GetLogger(categoryName) host.json?
Below is the snippet from startup class.
host.json
Links referred: https://github.com/Azure/azure-functions-dotnet-worker/issues/1123 https://github.com/Azure/azure-functions-dotnet-worker/pull/944 https://github.com/Azure/azure-functions-dotnet-worker/issues/702 https://github.com/Azure/azure-functions-dotnet-worker/issues/760 https://github.com/Azure/azure-functions-dotnet-worker/issues/1123
Project configuration and dependencies
Startup project .csproj file content
Link to a repository that reproduces the issue
No response