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

Add instrumentation using :telemetry #176

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

Conversation

Kasse-Dembele
Copy link

@Kasse-Dembele Kasse-Dembele commented Jul 10, 2024

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

@tompave
Copy link
Owner

tompave commented Aug 6, 2024

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.

mix.exs Outdated
@@ -80,7 +80,9 @@ defmodule FunWithFlags.Mixfile do

{:ex_doc, "~> 0.21", only: :dev, runtime: false},
{:credo, "~> 1.7", only: :dev, runtime: false},
{:dialyxir, "~> 1.0", only: :dev, runtime: false}
{:dialyxir, "~> 1.0", only: :dev, runtime: false},
{:telemetry_test, "~> 0.1", only: :test, runtime: false},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this package. It looks like it's not really much used in the ecosystem: https://hex.pm/packages/telemetry_test

Is there any other way to test telemetry?

Copy link
Author

@Kasse-Dembele Kasse-Dembele Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes for sure, https://hex.pm/packages/telemetry_test just abstract away the setup for telemetry event handler. But now i have updated the tests without using the telemetry_test package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants