Skip to content
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

Convert dotted property names into nested values when Serilog v4's experimental AppContext switch is set #223

Merged
merged 2 commits into from
May 29, 2024

Conversation

nblumhardt
Copy link
Member

This is experimental functionality not intended for production use. It helps prepare for the possible introduction of . into property names, which Serilog v4 will enable behind a feature flag:

AppContext.SetSwitch("Serilog.Parsing.MessageTemplateParser.AcceptDottedPropertyNames", true);

Log.Information("Running loop {Counter.I}, switch is at {Level}", i, levelSwitch.MinimumLevel);

The sink could transmit these to Seq as-is, but the query ergonomics for dotted names in Seq is poor (@Properties['Some.Name']), so they're converted client-side into structured data.

Seq handles the resulting structured property values, but cannot render these in templates - something this PR may help pave the way for in the future.

image

Lots of exploration and testing required around properties with partially-overlapping names, pre-rendered substitutions (format strings), etc. etc. :-)

See also serilog/serilog#2063

@@ -20,7 +22,7 @@

foreach (var i in Enumerable.Range(0, 100))
{
Log.Information("Running loop {Counter}, switch is at {Level}", i, levelSwitch.MinimumLevel);
Log.Information("Running loop {Counter.I}, switch is at {Level}", i, levelSwitch.MinimumLevel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the example just be left as-is? I can't imagine actually wanting to log a thing called Counter.I

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks! Fixed now 👍

@nblumhardt nblumhardt merged commit 675409c into datalust:dev May 29, 2024
1 check passed
@wjrogers
Copy link

wjrogers commented Jun 6, 2024

This has already been implemented, but I still want to chime in because I haven't seen anyone mention OpenTelemetry in the discussion of dotted property names in Serilog and Seq. Seq supports OpenTelemetry traces, now, which has been a real boon for adding span-based tracing to our existing logging infrastructure. It also supports dotted span attribute names, including automatic accordion-style display:

image

I am interested in aligning property/attribute names across our logs and traces, so e.g. searching for a job ID finds both kinds of data. OpenTelemetry strongly encourages "namespaced" dotted names, but it was previously cumbersome (and inefficient) to do the same with Serilog. It looks like this new feature will make it much easier. Please keep this use case in mind as you consider whether to support dotted names in Serilog in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants