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

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

Open
vincenzobove opened this issue Nov 9, 2023 · 0 comments
Open
Labels

Comments

@vincenzobove
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant