Function execution logs not filtered when using `OpenTelemetry` telemetryMode
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
## Description
When my Function App is setup to use `OpenTelemetry` telemetryMode, function execution logs ("Executing 'Functions." / "Executed 'Functions.") cannot be filtered out with `logging:logLevel:Function.{FunctionName}` section in `host.json` file.
The problem is that it prevents to filter out an important amount of logs created by e.g. `health` functions.
## Environment
- Function Runtime Version: 4.1047.100.26071 (From Core Tools Version: 4.9.0+29aeab590e6c229a1a6631f6653df70f150f9f0e in local development)
OR `mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated10.0-azurelinux3` docker image when deployed.
- Framework: dotnet 10.0.100
- Function Version: V4
## Repro steps
- Create a new Function App with csproj config:
```xml
net10.0
v4
Exe
enable
enable
```
- Setup your `host.json` file with:
```json
{
"version": "2.0",
"telemetryMode": "OpenTelemetry",
"logging": {
"logLevel": {
"default": "None",
"Function.MyHealthFunction": "None"
}
}
}
```
- Setup your `local.settings.json` with your App Insights connection string so that logs are exported:
```json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"Logging:LogLevel:Default": "None",
"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey={YourInstrumentationKey}"
}
}
```
- Configure your `Program.cs` with:
```csharp
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Hosting;
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Build().Run();
```
- Add a `MyHealthFunction.cs`:
```csharp
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
namespace FunctionAppLog;
public class MyHealthFunction
{
[Function("MyHealthFunction")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req)
{
return new OkResult();
}
}
```
- Start your Function App on port 7174
- Execute an HTTP request on health function `curl http://localhost:7174/api/health`
## Current behavior
`Function.MyHealthFunction` log filter is ignored and function execution logs are exported to App Insights.
## Expected behavior
Function execution logs must be filtered out when using `Function.{FunctionName}` log filter.
## Other info
Seems that the filter in not taken into account only for the OpenTelemetry exporter because the function execution logs are not displayed in the function execution console when the filter is applied.
The expected behavior is the one that you have if you remove the "OpenTelemetry" telemetryMode from host.json. In this case the filter is taken into account and function execution logs are not recorded in App Insights.
Those logs are created by the host, not the worker, so it's not possible to do something in the worker to prevent them.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.