-
Notifications
You must be signed in to change notification settings - Fork 148
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
Cannot use .AuditTo with SpanId or TraceId #515
Comments
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, |
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. |
When include 2 standard columns SpanId and TraceId, AuditTo will throw an exception. The quick solution is adding ToString() for these columns.
@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 |
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:serilog-sinks-mssqlserver/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlLogEventWriter.cs
Line 57 in b1d8553
and the values returned from
StandardColumnDataGenerator.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:serilog-sinks-mssqlserver/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/StandardColumnDataGenerator.cs
Lines 53 to 56 in b1d8553
Please 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
The text was updated successfully, but these errors were encountered: