Skip to content

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

Open
@HHobeck

Description

@HHobeck

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions