Skip to content

Add JSON support for DefaultFields #3333

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

skyvine
Copy link

@skyvine skyvine commented Jul 6, 2025

Motivation

Currently, passing format().json() to the event_format method of SubscriberBuilder without also calling .json() on the SubscriberBuilder results in either a runtime panic (in debug mode) or missing information from the log output (in release mode). See #3327 for more details including reproducer code and output.

Solution

This change updates the current implementation to correctly declare that it only supports JsonFields and adds a second implementation that supports DefaultFields. The code in #3327 produces the expected output after this change.

The JSON formatter depends on the JsonFields FieldFormatter being in
use. When .json() is called on a SubscriberBuilder directly this is
handled automatically. However, when .json() is called on the Format
given to .event_format() method of SubscriberBuilder a runtime error
occurs unless the user also calls .json() on the SubscriberBuilder
itself.

This change correctly declares that the json code is only implemented
for the JsonFields formatter. This results in compile-time errors,
instead of a runtime error, unless the user calls .json() on the
SubscriberBuilder *before* calling .event_format().

This improves the situation described in issue 3327, but a full
resolution would involve either implementing the json code for the
DefaultFields formatter as well (and by extension all future formatters
added to the project), improving the error message so that the compiler
recommends calling .json() on the SubscriberBuilder (it currently
recommends removing the .json() call from the Format object), or making
the SubscriberBuilder automatically use JsonFields when using the JSON
output format.
@skyvine skyvine requested review from hawkw and a team as code owners July 6, 2025 11:58
skyvine added 2 commits July 13, 2025 03:43
For two of the methods the only constraint is that SerializableSpan has
to implement Serialize for N/JsonFields. Make them generic again by
adding this constraint, which will reduce code duplication when adding
support for DefaultFields.
@skyvine skyvine changed the title Correctly state dependency on JsonFields. Add JSON support for DefaultFields Jul 13, 2025
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.

1 participant