Skip to content

Commit d904b84

Browse files
committed
Document the new LogTarget
1 parent fcc2f48 commit d904b84

2 files changed

Lines changed: 66 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [Unreleased] TBD
99

10+
### Added
1011
- Add new `LogTarget`
1112
- Introduce new `formatter:` options: `:json`, `:logfmt`, and `:noop`
1213
- Introduce new `transform:` options: `:cloud_watch`, `:l2met`, and `:noop`
1314

14-
## [1.1.4]
15+
## [1.1.4] 2024-05-29
1516

1617
### Changed
1718
- Updated gems in the lockfile
1819

19-
## [1.1.3]
20+
## [1.1.3] 2024-05-13
2021

2122
### Changed
2223
- Updated gems in the lockfile
@@ -27,14 +28,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2728
### Dropped
2829
- Check for support for 'ubuntu-18.04'
2930

30-
## [1.1.2]
31+
## [1.1.2] 2022-12-28
3132

3233
- Add Puma 6 compatibility
33-
## [1.1.1]
34+
35+
## [1.1.1] 2022-06-22
3436

3537
Public release.
3638

37-
## [1.1.0]
39+
## [1.1.0] 2022-06-22
3840

3941
Out of beta testing, reading for usage. Following is a recap from Alpha & Beta releases.
4042

@@ -46,8 +48,7 @@ Out of beta testing, reading for usage. Following is a recap from Alpha & Beta r
4648
- `config.socket_parser` option to allow custom parser implementation as needed
4749
- Datadog widgets examples under `docs/examples.md`
4850

49-
## [1.1.0 Beta]
50-
51+
## [1.1.0 Beta] ???
5152
### Added
5253

5354
Different ways to parse `Socket::Option`. Mainly due to the fact that `#inspect` can't
@@ -60,8 +61,7 @@ struct, so it should more or less stay stable.
6061
You can configure it by passing in `config.socket_parser = :inspect` or
6162
`config.socket_parser = ->(opt) { your implementation }`.
6263

63-
## [1.1.0 Alpha]
64-
64+
## [1.1.0 Alpha] ???
6565
### Added
6666

6767
Socket telemetry, and to be more precise new metric: `sockets.backlog`. If enabled it will
@@ -70,32 +70,32 @@ be acknowledged by Puma). It will be exposed under `sockets-backlog` metric.
7070

7171
You can enable and test it via `config.sockets_telemetry!` option.
7272

73-
## [1.0.0] - 2021-09-08
73+
## [1.0.0] 2021-09-08
7474
### Added
75-
- Release to Github Packages
76-
- Explicitly flush datadog metrics after publishing them
75+
- Release to GitHub Packages
76+
- Explicitly flush Datadog metrics after publishing them
7777
- Middleware for measuring and tracking request queue time
7878

7979
### Changed
80-
- Replace `statsd.batch` with direct calls, as it aggregates metrics interally by default now.
80+
- Replace `statsd.batch` with direct calls, as it aggregates metrics internally by default now.
8181
Also `#batch` method is deprecated and will be removed in version 6 of Datadog Statsd client.
8282

83-
## [0.3.1] - 2021-03-26
83+
## [0.3.1] 2021-03-26
8484
### Changed
8585
- IO target replaces dots in telemetry keys with dashes for better integration with AWS CloudWatch
8686

87-
## [0.3.0] - 2020-12-21
87+
## [0.3.0] 2020-12-21
8888
### Added
8989
- Datadog Target integration tests
9090

9191
### Fixed
9292
- Datadog Target
9393

94-
## [0.2.0] - 2020-12-21
94+
## [0.2.0] 2020-12-21
9595
### Fixed
9696
- Removed debugging information
9797

98-
## [0.1.0] - 2020-12-18
98+
## [0.1.0] 2020-12-18
9999
### Added
100100
- Core Plugin
101101
- Telemetry generation

README.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,61 @@ Puma::Plugin::Telemetry.configure do |config|
4141
end
4242
```
4343

44-
### Basic
44+
### Basic IO Target
4545

46-
Output telemetry as JSON to `STDOUT`
46+
A basic I/O target will emit telemetry data to `STDOUT`, formatted in JSON.
4747

4848
```ruby
49-
config.add_target :io
49+
config.add_target :io
5050
```
5151

52+
#### Options
53+
54+
This target has configurable `formatter:` and `transform:` options.
55+
The `formatter:` options are
56+
57+
* `:json` _(default)_ - Print the logs in JSON.
58+
* `:logfmt` - Print the logs in key/value pairs, as per `logfmt`.
59+
* `:noop` - A NOOP formatter which returns the telemetry `Hash` unaltered, passing it directly to the `io:` instance.
60+
61+
The `transform:` options are
62+
63+
* `:cloud_watch` _(default)_ - Transforms telemetry keys, replacing dots with dashes to support AWS CloudWatch Log Metrics filters.
64+
* `:logfmt` - Transforms telemetry keys, prepending `sample#` for [L2Met][l2met] consumption.
65+
* `:noop` - A NOOP transform which returns the telemetry `Hash` unaltered.
66+
67+
### Log target
68+
69+
Emitting to `STDOUT` via the basic `IOTarget` can work for getting telemetry into logs, we also provide an explicit `LogTarget`.
70+
This target will defaults to emitting telemetry at the `INFO` log level via a [standard library `::Logger`][logger] instance.
71+
That default logger will print to `STDOUT` in [the `logfmt` format][logfmt].
72+
73+
```ruby
74+
config.add_target :log
75+
```
76+
77+
You can pass an explicit `logger:` option if you wanted to, for example, use the same logger as Rails.
78+
79+
```ruby
80+
config.add_target :log, logger: Rails.logger
81+
```
82+
83+
This target also has configurable `formatter:` and `transform:` options.
84+
The [possible options are the same as for the `IOTarget`](#options), but the defaults are different.
85+
The `LogTarget` defaults to `formatter: :logfmt`, and `transform: :noop`
86+
87+
[l2met]: https://github.com/ryandotsmith/l2met?tab=readme-ov-file#l2met "l2met - Logs to Metrics"
88+
[logfmt]: https://brandur.org/logfmt "logfmt - Structured log format"
89+
[logger]: https://rubyapi.org/o/logger "Ruby's Logger, from the stdlib"
90+
5291
### Datadog StatsD target
5392

54-
Given gem provides built in target for Datadog StatsD client, that uses batch operation to publish metrics.
93+
A target for the Datadog StatsD client, that uses batch operation to publish metrics.
5594

56-
**NOTE** Be sure to have `dogstatsd` gem installed.
95+
**NOTE** Be sure to have the `dogstatsd` gem installed.
5796

5897
```ruby
59-
config.add_target :dogstatsd, client: Datadog::Statsd.new
98+
config.add_target :dogstatsd, client: Datadog::Statsd.new
6099
```
61100

62101
You can provide all the tags, namespaces, and other configuration options as always to `Datadog::Statsd.new` method.
@@ -75,6 +114,7 @@ Puma::Plugin::Telemetry.configure do |config|
75114
config.socket_parser = :inspect
76115
config.add_target :io, formatter: :json, io: StringIO.new
77116
config.add_target :dogstatsd, client: Datadog::Statsd.new(tags: { env: ENV["RAILS_ENV"] })
117+
config.add_target :log, logger: Rails.logger, formatter: :logfmt, transform: :l2met)
78118
end
79119
```
80120

@@ -85,8 +125,8 @@ Target is a simple object that implements `call` methods that accepts `telemetry
85125
Just be mindful that if the API takes long to call, it will slow down frequency with which telemetry will get reported.
86126

87127
```ruby
88-
# Example logfmt to stdout target
89-
config.add_target proc { |telemetry| puts telemetry.map { |k, v| "#{k}=#{v.inspect}" }.join(" ") }
128+
# Example key/value log to `STDOUT` target
129+
config.add_target ->(telemetry) { puts telemetry.map { |k, v| "#{k}=#{v.inspect}" }.join(" ") }
90130
```
91131

92132
## Extra middleware

0 commit comments

Comments
 (0)