Skip to content

TraceId and SpanId are saved as empty string instead of NULL #643

@marcominerva

Description

@marcominerva

I have the following configuration with Serilog.Sinks.MSSqlServer v9.0.0:

{
    "Serilog": {
        "Using": [ "Serilog.Sinks.MSSqlServer" ],
        "MinimumLevel": {
            "Default": "Information"            
        },
        "WriteTo": [           
            {
                "Name": "MSSqlServer",
                "Args": {
                    "connectionString": "...",
                    "sinkOptionsSection": {
                        "tableName": "Logs",
                        "autoCreateSqlTable": true
                    },
                    "columnOptionsSection": {
                        "addStandardColumns": [ "LogEvent", "TraceId", "SpanId" ],
                        "removeStandardColumns": [ "MessageTemplate", "Properties" ],
                        "id": { "dataType": "bigint" },
                        "timeStamp": {
                            "columnName": "Timestamp",
                            "convertToUtc": true,
                            "nonClusteredIndex": true,
                            "nonClusteredIndexDirection": "Desc"
                        },
                        "logEvent": {
                            "excludeAdditionalProperties": false,
                            "excludeStandardColumns": false
                        }
                    }
                }
            }
        ],
        "Enrich": [ "FromLogContext" ]
    }
}

With this settings, I notice that when log messages don't contain SpanId or TraceId, in the database are written empty strings instead of NULL, even if the columns allow null:

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions