Skip to content

Skip 404/409 Blob Storage Telemetry Dependencies in AppInsights #217

@eff-vbov

Description

@eff-vbov

Hey guys, I don't know if it's a bug but we are having some issues and would like some help. What we are trying to achieve is the following:

We have an Azure Function that make use of Serilog and this sink to write into AppInsights, this function does some calls to Azure Blob and when container/blob does not exist we do not want to log the 404/409 dependencies trace (We have so many calls that are part of the business process).

This is the startup code of the function:

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        var configuration = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("local.settings.json", true, true)
                .AddEnvironmentVariables()
                .Build();

        var loggerConfiguration = new LoggerConfiguration();
        
        loggerConfiguration.MinimumLevel.Warning();
        loggerConfiguration.MinimumLevel.Override("Microsoft", LogEventLevel.Error);
        
        loggerConfiguration.Enrich.FromLogContext();
        
        loggerConfiguration.WriteTo.ApplicationInsights(configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"], new TraceTelemetryConverter(), LogEventLevel.Warning);
        
        var logger = loggerConfiguration.CreateLogger();

        builder.Services
            .AddLogging(lb => lb.AddSerilog(logger))
            .AddApplicationInsightsTelemetryProcessor<TelemetryStorageFilterProcessor>();
    }

    public class TelemetryStorageFilterProcessor : ITelemetryProcessor
    {
        private ITelemetryProcessor Next { get; set; }
        private static readonly List<string> _dependencyTypes = new() { "azure table", "azure blob", "inproc | microsoft.storage", "microsoft.storage" };

        public TelemetryStorageFilterProcessor(ITelemetryProcessor next)
        {
            Next = next;
        }

        public void Process(ITelemetry item)
        {
            if (item is DependencyTelemetry dependency 
                && _dependencyTypes.Contains(dependency.Type.ToLower())
                && dependency.Success == false)
            {
                return;
            }

            Next.Process(item);
        }
    }
}

The Function have the following NuGet packages installed:

Microsoft.ApplicationInsights.AspNetCore 2.21.0
Serilog.AspNetCore 5.0.0
Serilog.Extensions.Logging 3.1.0
Serilog.Sinks.ApplicationInsights 3.1.0

No matter how we register the processor, the 404/409 dependencies are still written in AppInsights. What are we doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions