Skip to content

Commit cf3a090

Browse files
committed
Document the new Telemetry integration
1 parent 867b2ea commit cf3a090

File tree

3 files changed

+78
-10
lines changed

3 files changed

+78
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
* Add support for Elixir 1.18. Drop support for Elixir 1.15. Elixir >= 1.16 is now required. Dropping support for older versions of Elixir simply means that this package is no longer tested with them in CI, and that compatibility issues are not considered bugs.
66
* Drop support for Erlang/OTP 24, and Erlang/OTP >= 25 is now required. Dropping support for older versions of Erlang/OTP simply means that this package is not tested with them in CI, and that no compatibility issues are considered bugs.
7+
* Instrument the package with [Telemetry](https://hex.pm/packages/telemetry): FunWithFlags now emits Telemetry events for persistence operations. ([pull/197](https://github.com/tompave/fun_with_flags/pull/197), and thanks [Kasse-Dembele](https://github.com/Kasse-Dembele) for suggesting the feature and sharing his work in [pull/176](https://github.com/tompave/fun_with_flags/pull/176))
78
* Improve how the change-notification Phoenix.PubSub adapter manages its connection and readiness status. ([pull/191](https://github.com/tompave/fun_with_flags/pull/191))
8-
* Adding a suite of synthetic benchmark scripts for the package. ([pull/193](https://github.com/tompave/fun_with_flags/pull/193))
9+
* Add a suite of synthetic benchmark scripts for the package. ([pull/193](https://github.com/tompave/fun_with_flags/pull/193))
910

1011
## v1.12.0
1112

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ It stores flag information in Redis or a relational DB (PostgreSQL, MySQL, or SQ
4242
- [PubSub Adapters](#pubsub-adapters)
4343
* [Extensibility](#extensibility)
4444
- [Custom Persistence Adapters](#custom-persistence-adapters)
45+
* [Telemetry](#telemetry)
4546
* [Application Start Behaviour](#application-start-behaviour)
4647
* [Testing](#testing)
4748
* [Development](#development)
@@ -705,6 +706,11 @@ And then configure the library to use it:
705706
```elixir
706707
config :fun_with_flags, :persistence, adapter: MyApp.MyAlternativeFlagStore
707708
```
709+
## Telemetry
710+
711+
FunWithFlags is instrumented with [Telemetry](https://hex.pm/packages/telemetry) and emits events at runtime. Please refer to the [Telemetry docs](https://hexdocs.pm/telemetry/readme.html) for detailed instructions on how to consume the emitted events.
712+
713+
The full list of events emitted by FunWithFlags are documented in the [FunWithFlags.Telemetry](https://hexdocs.pm/fun_with_flags/FunWithFlags.Telemetry.html) module.
708714

709715
## Application Start Behaviour
710716

lib/fun_with_flags/telemetry.ex

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,83 @@ defmodule FunWithFlags.Telemetry do
22
@moduledoc """
33
Telemetry events for FunWithFlags.
44
5-
This module is responsible for emitting [Telemetry](https://hex.pm/packages/telemetry) events for FunWithFlags.
5+
This module centralizes the emission of all [Telemetry](https://hexdocs.pm/telemetry/readme.html)
6+
events for the package.
67
78
## Events
89
10+
The common prefix for all events is `:fun_with_flags`, followed by a logical
11+
scope (e.g. `:persistence`) and the event name.
12+
13+
Events are simple "point in time" events rather than span events (that is,
14+
there is no distinct `:start` and `:stop` events with a duration measurement).
915
1016
### Persistence
1117
12-
* `[:fun_with_flags, :persistence, :read]`
13-
* `[:fun_with_flags, :persistence, :read_all_flags]`
14-
* `[:fun_with_flags, :persistence, :read_all_flag_names]`
15-
* `[:fun_with_flags, :persistence, :write]`
16-
* `[:fun_with_flags, :persistence, :delete_flag]`
17-
* `[:fun_with_flags, :persistence, :delete_gate]`
18-
* `[:fun_with_flags, :persistence, :reload]`
19-
* `[:fun_with_flags, :persistence, :error]`
18+
Events for CRUD operations on the persistent datastore.
19+
20+
All events contain the same measurement:
21+
* `system_time` (integer), which is the current system time in the
22+
`:native` time unit. See `:erlang.system_time/0`.
23+
24+
Events:
25+
26+
* `[:fun_with_flags, :persistence, :read]`, emitted when a flag is read from
27+
the DB. Crucially, this event is not emitted when the cache is enabled and
28+
there is a cache hit, and it's emitted only when retrieving a flag reads
29+
from the persistent datastore. Therefore, when the cache is disabled, this
30+
event is always emitted every time a flag is queried.
31+
32+
Metadata:
33+
* `flag_name` (string), the name of the flag being read.
34+
35+
* `[:fun_with_flags, :persistence, :read_all_flags]`, emitted when all flags
36+
are read from the DB. No extra metadata.
37+
38+
* `[:fun_with_flags, :persistence, :read_all_flag_names]`, emitted when all
39+
flags names are read from the DB. No extra metadata.
40+
41+
* `[:fun_with_flags, :persistence, :write]`, emitted when writing a flag to
42+
the DB. In practive, what is written is one of the gates of the flag, which
43+
is always upserted.
44+
45+
Metadata:
46+
* `flag_name` (string), the name of the flag being written.
47+
* `gate` (`FunWithFlags.Gate`), the gate being upserted.
48+
49+
* `[:fun_with_flags, :persistence, :delete_flag]`, emitted when an entire flag
50+
is deleted from the DB.
51+
52+
Metadata:
53+
* `flag_name` (string), the name of the flag being deleted.
54+
55+
* `[:fun_with_flags, :persistence, :delete_gate]`, emitted when one of the flag's
56+
gates is deleted from the DB.
57+
58+
Metadata:
59+
* `flag_name` (string), the name of the flag whose gate is being deleted.
60+
* `gate` (`FunWithFlags.Gate`), the gate being deleted.
61+
62+
* `[:fun_with_flags, :persistence, :reload]`, emitted when a flag is reloaded
63+
from the DB. This typically happens when the node has received a change
64+
notification for a flag, which results in the cache being invalidated and
65+
the flag being reloaded from the DB.
66+
67+
Metadata:
68+
* `flag_name` (string), the name of the flag being reloaded.
69+
70+
* `[:fun_with_flags, :persistence, :error]`, emitted for erorrs in any of the
71+
above operations.
2072
73+
Metadata:
74+
* `error` (any), the error that occurred. This is typically a string or any
75+
appropriate error term returned by the underlying persistence adapters.
76+
* `original_event` (atom), the name of the original event that failed, e.g.
77+
`:read`, `:write`, `:delete_gate`, etc.
78+
* `flag_name` (string), the name of the flag being operated on, if supported
79+
by the original event.
80+
* `gate` (`FunWithFlags.Gate`), the gate being operated on, if supported by
81+
the original event.
2182
"""
2283

2384
require Logger

0 commit comments

Comments
 (0)