Skip to content

Comments

Add log target and logfmt formatter#26

Draft
stevenharman wants to merge 6 commits intobabbel:mainfrom
stevenharman:add_log_target_and_logfmt_formatter
Draft

Add log target and logfmt formatter#26
stevenharman wants to merge 6 commits intobabbel:mainfrom
stevenharman:add_log_target_and_logfmt_formatter

Conversation

@stevenharman
Copy link
Contributor

Building on #25, this continues building out parts of #21, adding a new :log target, which defaults to a new :logfmt formatter.

NOTE: Once #25 is merged, I'll rebase this to only include the changes for this PR.

Making the formatter available outside the IOTarget means other targets
can also use it. This will be helpful when I add a LogTarget. This also
adds some very basic tests (for my own sanity) for the IOTarget and
JSONFormatter classes.
As it was, the formatters were doing both transforms on the keys
(specific to a particular service) AND formatting the telemetry data.
By separating those responsibilities, we can mix and match different
Targets, Formatters, and Transforms to get the output needed for
different consumers.
These are useful for custom targets that might not need/want any
transforms for formatting, or to mix-and-match. For example, image a
custom `LogTarget` that can be configured with a `:logger` option. It
could be that the logger itself already knows how to format they
telemetry data, (e.g., into key/value pairs), and so we don't want/need
the Target to do any formatting.

This allows this plugin's config to look like this:

```ruby
Puma::Plugin::Telemetry.configure do |config|
  config.add_target(CustomLogTarget, logger: Logfmt.logger, transform: :cloud_watch, formatter: :noop)
end
```
Which defaults to the `:json` formatter with a `:passthrough` transform.
For now…
@stevenharman stevenharman force-pushed the add_log_target_and_logfmt_formatter branch from 01596e8 to 03b80e1 Compare September 17, 2025 20:32
This is also the default `formatter:` of the new LogTarget.
@stevenharman stevenharman force-pushed the add_log_target_and_logfmt_formatter branch from 03b80e1 to ab9860d Compare September 17, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant