RehanSaeed / Serilog.Enrichers.Span

Enrich Serilog log events with properties from Open Telemetry spans.
MIT License
95 stars 19 forks source link

ActivityEnricher uses a cached LogEventProperty regardless of the current SpanLogEventPropertiesNames #317

Closed rising-4ce closed 11 months ago

rising-4ce commented 1 year ago

Describe the bug

ActivityEnricher uses a cached in Activity LogEventProperty regardless of the current SpanLogEventPropertiesNames, resulting in unnecessary properties in LogEvent and missing desired properties. The behavior is reproduced on .NET 5.0 and later versions.

Steps to reproduce

  1. Create a project that uses .NET 5.0 or later.
  2. Add two SerilogLoggerProviders writing to two different Loggers, enriched with .Enrich.WithSpan with different SpanLogEventPropertiesNames parameters to the same ILoggerFactory.
  3. Create Logger with the above ILoggerFactory
  4. Start new Activity.
  5. Log something in a scope of the activity above.

Expected behaviour

Expected behavior: Each Logger receives LogEvents containing properties that have keys according to a corresponding SpanLogEventPropertiesNames.

Actual behavior: Each Logger receives LogEvents containing properties that have keys set in SpanLogEventPropertiesNames passed to the first SerilogLoggerProvider.