How to stop logging excessive ServiceBusReceiver.Receive Dependency logs to App Insights
Asked Answered
K

2

7

I have a Kubernetes app that is constantly logging ServiceBusReceiver.Receive Dependency calls. It is creating 2000 logs per hour, per instance. In the TelemtryClient there are only custom methods for TrackEvent and TrackException so these look like they are coming from somewhere else and I haven't been able to trace it to disable or find out why its logging so much. The TrackDependency method is part of the built in Microsoft.ApplicationInsights.TelemetryClient package. I have changed versions of packages to match another messaging app I have with no luck, and also updated packages to latest versions also with no luck. There isn't much other info in the logs to trace it.

SERVICEBUS ServiceBusReceiver.Receive

  • Dependency Properties

Type: servicebus
Call status: true
Duration: 1.0 mins
Name: ServiceBusReceiver.Receive
Telemetry type: dependency
Application version: 4.19.0.0
SDK version dotnetc:2.21.0-429
Sample rate: 1
Performance: 1min-2min
Base name: ServiceBusReceiver.Receive

Other info about packages and versions installed:

  • Sdk="Microsoft.NET.Sdk"

  • net6.0

  • AzureFunctionsVersion v4

  • "AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1"

  • "Azure.Messaging.ServiceBus" Version="7.10.0"

  • "Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.4.0"

  • "Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.33"

  • "Microsoft.NET.Sdk.Functions" Version="4.0.1"

  • "Microsoft.Azure.Functions.Extensions" Version="1.1.0"

  • "Microsoft.Extensions.Azure" Version="1.2.0"

  • "Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.1.0"

  • "Microsoft.Extensions.Caching.Memory" Version="6.0.1"

  • "Polly" Version="7.1.0"

  • "Scrutor" Version="4.1.0"

Kerri answered 4/5, 2023 at 11:17 Comment(2)
#55909788Selves
I don't want to exclude all Dependency calls, just these SERVICEBUS ServiceBusReceiver.Receive ones which are of no value.Kerri
D
4

For that, you can write a TelemetryProcessor:

Telemetry processors allow you to completely replace or discard a telemetry item.

It could look like this:

public class ServiceBusTelemetryReducer : ITelemetryProcessor
{
    private readonly ITelemetryProcessor _next;
            
    public ServiceBusTelemetryReducer(ITelemetryProcessor next)
    {
        _next = next;
    }

    public void Process(ITelemetry item)
    {
        var isServiceBusReceiveTelemetry = item is DependencyTelemetry telemetry
            && telemetry.Type == "Azure Service Bus"
            && telemetry.Name == "ServiceBusReceiver.Receive";

        // Only process telemetry that is relevant
        if (!isServiceBusReceiveTelemetry)
            _next.Process(item);
    }
}

Do not forget to register the processor:

services.AddApplicationInsightsTelemetryProcessor<ServiceBusTelemetryReducer>();
Deason answered 5/5, 2023 at 8:1 Comment(0)
C
1

You cannot suppress individual logs, but you can tune the level that gets captured to reduce the noise.

By default, the Azure SDKs used in the 5.x+ extension packages will respect the global log level configuration. Each can be tuned individually to allow you to capture the level of detail that your application is interested in.

To change the log detail that you're seeing for Service Bus and other Azure SDK packages, you need to define their level by package in your host.json logging section. For example, if you wanted to restrict Service Bus calls to just warnings and errors, you'd use something similar to:

"Logging": {
  "LogLevel": {
    "Default": "Information",
    "System": "Information",
    "Azure.Messaging.ServiceBus": "Warning"
  }
}

More information on how the Azure SDK logging configuration maps to the Functions logging can be found in the article Logging with the Azure SDK for .NET.

Chatham answered 4/5, 2023 at 13:5 Comment(2)
The question is about how to suppress a dependency, not a trace which I believe is what you explain how to control.Formality
This worked for me, to stop logging the dependency!Harberd

© 2022 - 2024 — McMap. All rights reserved.