serilog-contrib / serilog-sinks-splunk

A Serilog sink that writes to Splunk
https://splunk.com
Apache License 2.0
46 stars 47 forks source link

TraceId and SpanId are missing from the logs #195

Closed KrishnaKole closed 7 months ago

KrishnaKole commented 7 months ago

I am using v4.0.3 of this sink with below setup:

        Log.Logger = new LoggerConfiguration()
            .Destructure.UsingAttributes()
            .Enrich.FromLogContext()
            .Enrich.WithExceptionDetails()
            .Enrich.WithCorrelationId(StaticConfig.CorrelationIdHeader, addValueIfHeaderAbsence: true)
            .WriteTo.Conditional(
                _ => !builder.Environment.IsDevelopment(),
                wt => wt.EventCollector(
                    splunkConfig.BaseUri,
                    splunkConfig.Token,
                    "services/collector/event",
                    splunkConfig.AppSource ?? Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty,
                    sourceType: "",
                    splunkConfig.AppHost ?? Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME", EnvironmentVariableTarget.Process) ?? Environment.MachineName,
                    splunkConfig.Index
                )
            )
            .WriteTo.Conditional(
                _ => builder.Environment.IsDevelopment(),
                wt => wt.Console(
                    outputTemplate:
                    "[{Timestamp:yyyy.MM.dd HH:mm:ss} {TraceId} {SpanId} {CorrelationId} {Level:u3}] {Message:lj} {Properties:j} {NewLine}{Exception}"
                )
            )
            .ReadFrom.Configuration(builder.Configuration)
            .CreateLogger();
       builder.Host.UseSerilog();

I get the TraceId and SpanId in console logs, but they are missing from the logs image

Am I doing something wrong?

EEParker commented 7 months ago

I added a reproduction case #196. I looks like this is related to some internal changes to dotnet 6.0 and up, see https://github.com/dotnet/runtime/issues/34305

I found a related MR to serilog here: https://github.com/serilog/serilog/pull/1955/files#diff-b111b459384a29d3e58a068b0b47c05777172c9974217fb615a6976c70841de7

EEParker commented 7 months ago

image This will be fixed with 4.0.4

EEParker commented 7 months ago

@KrishnaKole once 4.0.4 is available on nuget, can you confirm this is fixed?

KrishnaKole commented 7 months ago

Yes, it is fixed with 4.0.4. Thank you!