serilog-sinks-elasticsearch icon indicating copy to clipboard operation
serilog-sinks-elasticsearch copied to clipboard

Slow inicialization application when ElasticSearch is down, why this lock the main thread of application?

Open gmoretti-gruposbf opened this issue 3 years ago • 2 comments
trafficstars

A few questions before you begin:

Is this an issue related to the Serilog core project or one of the sinks or community projects.
This issue list is intended for Serilog Elasticsearch Sink issues. If this issue relates to another sink or to the code project, please log on the related repository. Please use Gitter chat and Stack Overflow for discussions and questions.

Does this issue relate to a new feature or an existing bug?

  • [x] Bug
  • [ ] New Feature

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.

<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />

What is the target framework and operating system? See target frameworks & net standard matrix.

  • [ ] netCore 2.0
  • [ ] netCore 1.0
  • [ ] 4.7
  • [ ] 4.6.x
  • [ ] 4.5.x
  • [x] 5.0.x

Please describe the current behavior?

I have a question about the thread that is running my ElasticSearchSink, cause a was reading about and learn that this Sink alreay runs async, but the current behavior in my application when the ElasticSearch URI doesn't respond is that I can't access my health endpoint,for example, only after the timeout is achieve my endpoint can be reachable. On my tests, my application start quickly only I set the Period and ConnectionTimeout with 5 milliseconds with isn't recommend so short timeout.

Please describe the expected behavior?

I expect that when my elastic search instance is off my main thread doesn't lock.

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem

My current configuration


namespace Shipping.Extensions
{
    public static class SerilogExtensions
    {
        public static void AddSerilog(this IServiceCollection services)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var configuration = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile(
                    $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json",
                    optional: true)
                .Build();
            Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .Enrich.WithExceptionDetails()
                .Enrich.WithMachineName()
                 // I tried to wrapper this but not working.
                .WriteTo.Async(a => a.Elasticsearch(ConfigureElasticSink(configuration, environment)))
                .Enrich.WithProperty("Environment", environment)    
                .ReadFrom.Configuration(configuration)
                .CreateLogger();
        }

        private static ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment)
        {
            var uri = new Uri(configuration["ElasticConfiguration:Uri"]);
            return new ElasticsearchSinkOptions(uri)
            {
                AutoRegisterTemplate = true,
                IndexFormat = $"{configuration["ElasticConfiguration:IndexPrefix"]}-{DateTime.UtcNow:yyyy-MM}",
                FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
                EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
                                       EmitEventFailureHandling.WriteToFailureSink |
                                       EmitEventFailureHandling.RaiseCallback,
                Period = TimeSpan.FromSeconds(2),
                ConnectionTimeout = TimeSpan.FromSeconds(3),
                BatchPostingLimit = 5
            };
        }
    }
}

gmoretti-gruposbf avatar Apr 18 '22 19:04 gmoretti-gruposbf

One mouth without support

gmoretti-gruposbf avatar May 20 '22 14:05 gmoretti-gruposbf

Up! why initializing the Elasticsearch locks the main thread for so long?

pablokawan avatar Jul 20 '22 00:07 pablokawan