Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Logs in Application Insights #2634

Open
aditvavikramx opened this issue Jul 31, 2024 · 6 comments
Open

Duplicate Logs in Application Insights #2634

aditvavikramx opened this issue Jul 31, 2024 · 6 comments
Labels
area: migration Items related to migration from the in-process model Needs: Triage (Functions)

Comments

@aditvavikramx
Copy link

aditvavikramx commented Jul 31, 2024

What version of .NET does your existing project use?

.NET 8

What version of .NET are you attempting to target?

.NET 8

Description

I am experiencing an issue where my logs are getting printed twice on Application Insights. Below are the details of my setup and configuration:
Logging Setup in Startup :

services.AddLogging(loggingBuilder =>
{
    loggingBuilder.SetMinimumLevel(logLevel);
    loggingBuilder.AddFilter<ApplicationInsightsLoggerProvider>("mykafkamodel", logLevel);
    loggingBuilder.AddApplicationInsights(loggingBuilder =>
    {
        loggingBuilder.IncludeScopes = true;
    });
});
services.AddApplicationInsightsTelemetryWorkerService(options: aiServiceOptions);
services.ConfigureFunctionsApplicationInsights();

Application Insights Configuration
By default, Application Insights is set to log warnings, so I reset the rules at bootup:

.ConfigureLogging(logging =>
{
    logLevel = LoadConfigurations.ApplicationInsightsLogLevel(config!);
logging.Services.Configure((Action<LoggerFilterOptions>)(options =>
    {
        var loggerFilterRule = options.Rules.FirstOrDefault(rule => rule.ProviderName == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
        if (loggerFilterRule is not null)
        {
            options.Rules.Remove(loggerFilterRule);
        }
        logging.AddFilter<ApplicationInsightsLoggerProvider>("mykafkamodel", logLevel);
    }));
});

Application Insights Service Options
var aiServiceOptions = new ApplicationInsightsServiceOptions { EnableAdaptiveSampling = false, EnableDebugLogger = false, };

Issue

Despite the above configuration, I observe that some logs are being duplicated in the trace logs. I suspect there might be an issue with my logging setup or configuration.

Request
Could someone please help identify if there is something wrong with my configuration or suggest a solution to prevent duplicate logs?

Project configuration and dependencies

I have upgraded my inprocess model to worker model dot net isolated ie dot net 8

Link to a repository that reproduces the issue

No response

@aditvavikramx aditvavikramx added the area: migration Items related to migration from the in-process model label Jul 31, 2024
@sravanreddy6745
Copy link

I am also facing same issue after migrating my function app from .NET 6 to .NET 8 LTS, seeing unwanted logs from HTTP calls

Eg : Logs while callingDefaultAzureCredential method

image

@s-nakagaki
Copy link

I have same issue.

Program.cs

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.Configure<TelemetryConfiguration>(config =>
        {
            var credential = new ManagedIdentityCredential();
            config.SetAzureTokenCredential(credential);
        });
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .ConfigureLogging(logging =>
    {
        logging.Services.Configure<LoggerFilterOptions>(options =>
        {
            LoggerFilterRule? defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
                == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
            if (defaultRule is not null)
            {
                options.Rules.Remove(defaultRule);
            }
        });
    })
    .Build();

host.json

  "logging": {
    "logLevel": {
      "default": "Warning",
      "Function": "Warning",
      "Host.Aggregator": "Information",
      "Host.Results": "Information",
      "Function.HealthCheck": "Error",
      "Function.Hoge": "Information",
      "Function.Hoge.User": "Information"
    },
    "console": {
      "isEnabled": false,
      "DisableColors": true
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 1,
        "excludedTypes": "Exception"
      },
      "enableLiveMetricsFilters": true
    }
  }

スクリーンショット 2024-08-01 18 32 29

@s-nakagaki
Copy link

The stream log of application insights log at the function of azure portal is ok.
But KQL result at application insights log are duplicated.

I have another function which runs on python and it has same situation.
Is this the problem of Application Insights or Azure Monitor?

@king-11
Copy link

king-11 commented Aug 2, 2024

I am also in the same boat as @s-nakagaki my dotnet isolated function app faces this issue with open telemetry distro.

I have already opened prior issue in azure dotnet linking it here as well Azure/azure-sdk-for-net#45320

@Barsonax
Copy link

Barsonax commented Aug 6, 2024

Iam seeing this as well with opentelemetry. The sdkversion is different for the logs:
image

@king-11
Copy link

king-11 commented Sep 10, 2024

I can ack on @Barsonax seeing duplicate logs from two different sdks as they mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: migration Items related to migration from the in-process model Needs: Triage (Functions)
Projects
None yet
Development

No branches or pull requests

5 participants