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

Expose new transforms and formatters design #25

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

Conversation

stevenharman
Copy link
Contributor

This work is an extraction of some of #21.

It includes a new base class (BaseFormattingTarget) that Targets can opt into, giving them access to the formatter: and transform: options. It also extracts a cloud_watch transform and json formatter into discrete options, which can be mixed-and-matched with new :passthrough formatter and transform.

This also keeps the existing IOTarget backwards compatible by defaulting to formatter: :json and transform: :cloud_watch.

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.
@stevenharman
Copy link
Contributor Author

@unsign3d Sorry for the long delay - summer arrived here, the kids are out of school, and we've been doing our best to get out and enjoy it. This is the first of 2-3 PRs to rebuild what we had in #21. Once this is merged I'll get to work on adding the :logfmt formatter and new :log Target atop that work.

Thank you!

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
```
@stevenharman stevenharman force-pushed the expose_transforms_and_formatters branch from fc38c6e to cca4954 Compare July 3, 2024 20:25
@stevenharman
Copy link
Contributor Author

@unsign3d 👋 It's been a while and we're still running these changes in production, with great success. Are you still open to pulling them in?

Thanks!

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