Closed Kolthor closed 6 months ago
Hello @Kolthor!
Thank you for reporting this issue and for the thorough analysis. I will look into itnas soon as I can. Hopefully within the next 2 weeks.
Cheers, Christian
Hi @ckadluba Is there any progress on this ticket? Based on what @Kolthor described, it seems to be a very easy fix, doesn't it? Regards
Sorry for the delay. I have not enough bandwidth for testing the proposed fix at the moment. But we are always happy if someone helps us out with a PR. We could review this quickly and merge if it is good.
@ckadluba Thank you for your fast response. Please check the quick PR here :) #535
@vui611 Thank you very much for the PR. It was just merged into the dev branch. 🫶
@Kolthor Thanks a lot for reporting this and for the detailed bug analysis.
A dev version of the sink was built and published on nuget.
https://www.nuget.org/packages/Serilog.Sinks.MSSqlServer/6.6.1-dev-00077
It would be great if you could take it for a spin and test the fix with this version or with the current code in the dev branch.
Naturally the fix will also go into the next regular release (when we merge dev into main). But since there are one or two significant open bugs, I would like to wait until we have them fixed too.
@ckadluba I can confirm the version 6.6.1-dev-00077 works well now. I can use AuditTo()
without any exception and 2 columns TraceId
, SpanId
are written to the database.
Thank you.
Bug Report
Please clearly describe what the SQL Sink is doing incorrectly:
When using
.AuditTo.MSSqlServer
and including the newSpanId
andTraceId
standard columns, events which contains either a SpanId or TraceId breaks Serilog.Sinks.MSSqlServer, with the exception message:or:
This exception does not occur when using
.WriteTo.MSSqlServer
, and both columns are populated in the table as expected.The problem is that
.AuditTo
usesSqlLogEventWriter
, which usesSqlCommand.AddParameter
when adding the SpanId and TraceId: https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/b1d8553b76ac33ec7e958992efc63ffb57a28090/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlLogEventWriter.cs#L57 and the values returned fromStandardColumnDataGenerator.GetColumnsAndValues()
are the structsSystem.Diagnostics.ActivitySpanId
andSystem.Diagnostics.ActivityTraceId
respectively..WriteTo
is not affected because it usesSqlBulkBatchWriter
, which maps aSqlBulkCopy
to aDataTable
, where theDataColumn
s are specified as strings, and the structs are converted when they are added.I believe calling
.ToString()
onlogEvent.TraceId
andlogEvent.SpanId
inStandardColumnDataGenerator.GetColumnsAndValues()
should fix the issue: https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/b1d8553b76ac33ec7e958992efc63ffb57a28090/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/StandardColumnDataGenerator.cs#L53-L56Please clearly describe the expected behavior:
Both columns are populated in the table, with no exceptions or missing events.
List the names and versions of all Serilog packages used in the project:
Target framework and operating system:
[x] .NET 6 [ ] .NET Framework 4.8 [ ] .NET Framework 4.7 [ ] .NET Framework 4.6
OS: Windows 11 Version 22H2 (OS Build 22621.3007)
Provide a simple reproduction of your Serilog configuration code:
Provide a simple reproduction of your Serilog configuration file, if any:
N/A
Provide a simple reproduction of your application code:
https://github.com/Kolthor/SerilogTest