Skip to content

Function execution logs not filtered when using OpenTelemetry telemetryMode #2657

@foliv57

Description

@foliv57

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:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.51.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.7" />
  </ItemGroup>

</Project>
  • Setup your host.json file with:
{
  "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:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "Logging:LogLevel:Default": "None",
    "APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey={YourInstrumentationKey}"
  }
}
  • Configure your Program.cs with:
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Hosting;

var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();

builder.Build().Run();
  • Add a MyHealthFunction.cs:
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.

Image Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions