fun_with_flags icon indicating copy to clipboard operation
fun_with_flags copied to clipboard

Add instrumentation using :telemetry

Open Kasse-Dembele opened this issue 1 year ago • 1 comments

This PR adds instrumentation to FunWithFlags using the :telemetry library. This allows users to gain insights into the performance and usage of feature flags in their applications.

Key changes:

  • Added telemetry events for all major operations (enable, disable, clear, enabled?)
  • Each event includes duration measurements and relevant metadata
  • Telemetry events are emitted using the [:fun_with_flags, :flag_operation] event name

New telemetry events:

  • [:fun_with_flags, :flag_operation]
    • Measurements:
      • duration: Time taken for the operation in native time units
    • Metadata:
      • flag_name: Name of the flag being operated on
      • operation: Type of operation (:enable, :disable, :clear, or :enabled?)
      • options: Any options passed to the operation
      • result: Result of the operation

This change is backwards compatible and does not affect existing functionality. Users can choose to attach handlers to these events to collect metrics or perform logging.

This PR aims to provide better observability for applications using FunWithFlags, allowing for easier debugging, performance monitoring, and usage analytics.

Testing:

  • Added unit tests for telemetry event emission in all relevant operations
  • Ensured existing tests pass without modification

Next steps:

  • Update documentation to include information about the new telemetry events

Feedback and suggestions are welcome! @tompave

Kasse-Dembele avatar Jul 10 '24 21:07 Kasse-Dembele

Hi, thank you for using the library and for the PR. This is some nice work! I think I can accept this change, but first I want to measure the performance overhead.

In the meantime, can you please merge in master or rebase? I've updated the CI matrix and it'd be good to re-run CI with the latest Elixir and OTP versions.

I can also see that at the moment the telemetry tests are failing with Elixir 1.14 (is it incompatible?), but the good news is that I'm dropping support for Elixir 1.14 (it's removed from CI on master), so that won't be a concern. Still, I'd be curious to know why it's failing there.

tompave avatar Aug 06 '24 23:08 tompave

I love this idea, I was thinking of building an ad hoc solution to solve this problem

Is there anything pending to be able to add this to the library? Can we help in any way to make this a reality? @tompave

jmartinezpoq avatar Nov 22 '24 17:11 jmartinezpoq

Apologies for the very long wait.

I'm adding Telemetry support to the library, but I've decided that it's better to emit events for things that happen deep inside the library (cache hits and misses, DB reads, change notifications, etc). This PR, in contrast, focusses on the top API module.

That is also part of the reasons why I left it here for so long: I fee that anything that only acts on the top API module could be easily achievable in any host application (by providing a helper function that wraps calls to the top API module). That would also remove the need to add complexity to FWF.

I'm closing this PR for now, sorry. I'll make sure to reference it in the changelog to give credit to the author. 👍

tompave avatar Mar 10 '25 09:03 tompave

Telemetry events are being added with: https://github.com/tompave/fun_with_flags/pull/197.

tompave avatar Mar 23 '25 14:03 tompave