Skip to content

Add traceId and spanId properties in LogstashJsonFormatter output #55

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

Merged
merged 6 commits into from
Apr 14, 2025

Conversation

tbdrake
Copy link
Contributor

@tbdrake tbdrake commented Apr 9, 2025

Fixes #53

See related changes in serilog/serilog#1955

For reference, Serilog.Formatting.Json.JsonFormatter also includes these properties here:
https://github.com/serilog/serilog/blob/cd6420aeafcdedd3790da1a03a419e389f0faa64/src/Serilog/Formatting/Json/JsonFormatter.cs#L74-L84

Also enabled <Nullable> in the unit test project (already enabled in the main project) and fixed some warnings. moved to #56 and #57.

@tbdrake tbdrake changed the title Add traceId and spanId properties in LogstashJsonFormatter output Add traceId and spanId properties in LogstashJsonFormatter output Apr 9, 2025
@nojaf
Copy link
Collaborator

nojaf commented Apr 9, 2025

@Smaug123, I don't see any harm in this, do you?

@tbdrake
Copy link
Contributor Author

tbdrake commented Apr 13, 2025

@nojaf One concern I realized is that existing code could be adding traceId and spanId properties already, for example with https://github.com/RehanSaeed/Serilog.Enrichers.Span, and in that case the LogstashJsonFormatter would have duplicate properties. I found this issue #39 so it looks like this applies to other properties like message as well.

I added a failing test in the latest commit and plan to look into #39 and maybe open a separate PR.

@Smaug123
Copy link

I don't see any harm in this per se, but I'm certainly not a domain expert, and that issue does look concerning! (On general principles I'd prefer to pull out the Nullable enablement into a separate PR, so that the change with possibly-dangerous semantics can go in on its own.)

@tbdrake
Copy link
Contributor Author

tbdrake commented Apr 13, 2025

I don't see any harm in this per se, but I'm certainly not a domain expert, and that issue does look concerning! (On general principles I'd prefer to pull out the Nullable enablement into a separate PR, so that the change with possibly-dangerous semantics can go in on its own.)

Thank you for the input and suggestion! I moved the <Nullable> changes to separate PRs #56 and #57. (Also I accidentally clicked close PR 😄)

@tbdrake
Copy link
Contributor Author

tbdrake commented Apr 14, 2025

I added a failing test in the latest commit and plan to look into #39 and maybe open a separate PR.

I adjusted the test to pass based on looking into it further and added comment here on #39.

@tbdrake
Copy link
Contributor Author

tbdrake commented Apr 14, 2025

@nojaf No rush but do you have any ETA for a next release, and do you think this change could go in it?

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Thanks, this looks fine. I'll publish a new alpha so you can test this further on your end.

@nojaf nojaf merged commit 947f03c into serilog-contrib:master Apr 14, 2025
3 checks passed
@tbdrake tbdrake deleted the trace-and-span-ids branch April 14, 2025 11:52
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.

LogstashJsonFormatter does not include LogEvent.TraceId or SpanId
3 participants