Console formatter improvements for developers (#6391) #6801
+2,208
−589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6391
Design discussion issue #none
Changes
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesNOTE: There is minimal changes to the public API, just adding a small number of configuration options.
Most code is internal, allowing easy future improvement.
Notes
This was originally a Contrib submission, as a completely separate exporter, but it was requested
to change to be an update to the default console logger.
This is not meant to address every console logger requirement, but has a specific focus on something
application development friendly. It is not meant for production performance, or to be flexible, or output
to files.
It is meant to be something that an application developer can use during application development, running
in a local console. The output format is compact (2 lines), uses colour, and much less verbose than the previous
default console logger.
Other considerations (e.g. performance) are no worse than the existing KeyValue formatter; only the formatting
has been improved (simplified).
I have kept the previous logger as an alternative 'KeyValue' formatter, in case anyone wants that format
(it is a lot more verbose), but for details of the full attributes of any telemetry a developer could
also use an appropriate local tool, such as Loki (for logs) or Jaeger (for traces), etc.
Output format bikeshedding
The format used for the output could be debated ad-infinitum. Rather than spend time on this,
I'd like to get a basic console logger in with any reasonable format.
If the senior project lead on OpenTelemetry .NET (a project should not be a democracy) has a specific format /
change to the format, I'm happy to make it to get things merged.
What I don't want is a half dozen people suggesting different minor tweaks as you could forever be debating
colours, abbreviations, order of the attributes, etc.
The longer term plans are to have a customisable format anyway, so the sooner we get this in, the sooner
someone can start on that.
The chosen format
Originally my Contrib submission was very similar to the default .NET Console Logger, so it could operate
as mostly a drop in replacement with no visible difference to the user except that it would include
Trace ID when available.
This version leans more towards OpenTelemetry standards.
Resource details are not output by default, as usually you are running one application in the console on your local machine.
The main thing missing from .NET logs is the CategoryName, which doesn't have a direct equivalent in OpenTelemetry. The indentation is also different, to align with the default timestamp (rather than severity), and output is written in a single line (rather than 2).