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

HttpMessageHandler cannot be configured when initialization Serilog.Sinks.OpenTelemetry via configuration

Open HHobeck opened this issue 1 year ago • 3 comments

Dear community.

I'm initialization the Serilog.Sinks.OpenTelemetry only via the configuration file and getting an error because the HTTP connection cannot be estabshiled. The reason why is quite simple because my application uses the default proxy. I have taken a look into the code and saw that it is not possible to inject the HttpMessageHandler via the options BatchedOpenTelemetrySinkOptions to disable the proxy.

Here is my serilog configuration in appsetttings.json:

  "Serilog": {
    "Using": [ "Serilog.Sinks.OpenTelemetry" ],
    "WriteTo:OpenTelemetry": {
      "Name": "OpenTelemetry",
      "Args": {
        "endpoint": "http://localhost:4318/v1/logs",
        "protocol": "HttpProtobuf"
    }
  }
}

And my host builder setup:

hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
{
    serviceCollection.Configure<OpenTelemetrySinkOptions>(options =>
    {
        options.HttpMessageHandler = new HttpClientHandler() { UseProxy = false };
    });
});

hostBuilder.ConfigureLogging((hostBuilderContext, loggingBuilder) =>
{
    var loggerConfiguration = new LoggerConfiguration();

    ConfigurationReaderOptions configurationReaderOptions = new()
    {
        SectionName = $"{ConfigurationLoggerConfigurationExtensions.DefaultSectionName}"
    };
    Log.Logger = loggerConfiguration.ReadFrom.Configuration(
        hostBuilderContext.Configuration, configurationReaderOptions
    ).CreateLogger();

    loggingBuilder.AddSerilog();
});

I'm using the Serilog.Sinks.OpenTelemetry nuget package version 1.2.0 in a dot core 6.0 console application on windows10.

Regards Hardy

image

HHobeck avatar Feb 16 '24 10:02 HHobeck