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

Configure Logger headers declaratively with JSON #120

Open
frank-ang opened this issue Dec 11, 2023 · 1 comment
Open

Configure Logger headers declaratively with JSON #120

frank-ang opened this issue Dec 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@frank-ang
Copy link

Summary

Opentelemetry sink incorrectly ignores request headers when the Logger is configured declaratively using JSON ConfigurationBuilder.
In contrast, request headers are sent correctly only when the Logger is configured programmatically.

Steps to reproduce

  1. Configure a header section of Serilog.Sinks.OpenTelemetry sink in the JSON configuration file.
    "WriteTo": [
      {
        "Name": "OpenTelemetry",
        "Args": { 
          "endpoint": "http://127.0.0.1:4318/v1/logs",
          "protocol": "HttpProtobuf",
          "headers": {
            "Authorization": "Bearer TOKEN_REDACTED"          
          }
        },
      }
    ]
  1. Build the logger using JSON
var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();
Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();
  1. Call the logger, Log.Information()

Expected Result.

  • Authentication succeeds.
  • Network packet capture should show headers are included in requests to OpenTelemetry endpoint.

Actual Result.

  • Authentication fails.
    • Exception when using HttpProtobuf protocol: Exception while emitting periodic batch from Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink: System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
    • Exception when using Grpc protocol: Exception while emitting periodic batch from Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink: Grpc.Core.RpcException: Status(StatusCode="Unauthenticated",
  • Network packet capture (Wireshark) verifies headers are missing from requests to OpenTelemetry endpoint.

Potentially Related

@frank-ang frank-ang changed the title Logger ignores request headers when configured using JSON Configure Logger headers declaratively with JSON Dec 15, 2023
@nblumhardt nblumhardt added the enhancement New feature or request label Jan 2, 2024
@juarola
Copy link

juarola commented Nov 9, 2024

@frank-ang @nblumhardt This seems to be working fine now, i'm sending "x-seq-apikey" header from appsettings to Seq without any issues.

"WriteTo:OpenTelemetry": {
  "Name": "OpenTelemetry",
  "Args": {
    "Endpoint": "__SeqBaseUrl__/ingest/otlp/v1/logs",
    "Protocol": "HttpProtobuf",
    "resourceAttributes": {
      "service.name": "redacted"
    },
    "headers": {
      "x-seq-apikey": "__SeqApiKey__"
    }
  }
},

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

No branches or pull requests

3 participants