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

UseAdaptiveSampling with excludeTypes: Exception doesn't always work #1281

Closed
brotacel opened this issue Nov 4, 2019 · 3 comments
Closed
Assignees

Comments

@brotacel
Copy link

brotacel commented Nov 4, 2019

Sometimes uncaught exceptions from a netcore 2.2 WebApi seem to be sampled out. Not all expected error logs can be found in Azure Portal -> Application Insights -> Failed requests.
Using Serilog ApplicationInsights sink, and the following configuration:

In Startup->Configure:

            var appInsightsConfig = app.ApplicationServices.GetService<TelemetryConfiguration>();

            TelemetryProcessorChainBuilder builder = appInsightsConfig.TelemetryProcessorChainBuilder;
            // some custom telemetry processor for Application Insights that filters out synthetic traffic (e.g traffic that comes from Azure to keep the server awake).
            builder.UseAdaptiveSampling(excludedTypes: "Exception");
            builder.Build();

In Startup->ConfigureServices:

            services.AddApplicationInsightsTelemetry(o =>
            {
                o.EnableAdaptiveSampling = false; // Disable adaptive sampling here, so we can configure it in the Configure method
            });

In Program->Main a Serilog sink is configured:

            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(Configuration)
                .WriteTo.ApplicationInsights(TelemetryConfiguration.Active, TelemetryConverter.Traces)
                .CreateLogger();

Packages:

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.0.4" />

A valid telemetry key is set in application.json.

Can you please advise if the above configuration is correct for enabling adaptive sampling, but never sample out api requests which have an uncaught exception?

@cijothomas
Copy link
Contributor

This looks like Serilog is configured with TC.Active, but sample Processor is done on the TC retrieved from DI. They are different, hence Serilog logs wont respect.
Either use TC from DI always (recommended approach), or use TC.Active always.

Let us know if this helps

@brotacel
Copy link
Author

brotacel commented Nov 8, 2019

Thank you. It does help. I have a better understanding of the issue now.

However, I am not sure which is the correct approach of using Serilog with ApplicationInsights configured through dependency injection, while also being able to have early logging when application starts.
I have found 2 posts which seem to be related with this problem (configuring Serilog without using TelemetryConfiguration.Active, without losing early logging)

I will follow them to see which is the recommended approach (I haven't had time to try any of the proposed workarounds yet).
Currently they have status Open without a definitive solution.

@github-actions
Copy link

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

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

No branches or pull requests

2 participants