Skip to content

Replace direct telemetry deps with the electric_telemetry library - #3412

Merged
alco merged 22 commits into
mainfrom
alco/electric-telemetry
Nov 25, 2025
Merged

alco merged 22 commits into
mainfrom
alco/electric-telemetry

Conversation

@alco

@alco alco commented Nov 10, 2025 •

Copy link
Copy Markdown
Contributor

Extract telemetry code from Electric into a separate package. On top of that, the new package accepts additional user-provided periodic measurements and metric definitions for otel/prometheus exporters; both exporters now use the same list of metrics.

One thing that's been lost in this move is the stack_id sentry tag inside the CallHomeRepoter process. Sentry is a dependency of Electric and there's no straightforward way of propagating it into CallHomeReporter which is a module in the electric_telemetry dependency now. I don't feel like it's a big loss because we set stack_id in the logger metadata for that process, as well as mention it in the process name and label.

With this merged, we can delete the electric-sql/electric-telemetry repo.

@codecov

codecov Bot commented Nov 10, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.84615% with 237 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.35%. Comparing base (69e4599) to head (3b9522e).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...metry/lib/electric/telemetry/call_home_reporter.ex 0.00% 94 Missing ⚠️
...ry/lib/electric/telemetry/application_telemetry.ex 22.54% 79 Missing ⚠️
...elemetry/lib/electric/telemetry/stack_telemetry.ex 0.00% 18 Missing ⚠️
...electric/telemetry/reporters/call_home_reporter.ex 0.00% 16 Missing ⚠️
...lectric-telemetry/lib/electric/telemetry/poller.ex 0.00% 13 Missing ⚠️
...try/lib/electric/telemetry/reporters/prometheus.ex 0.00% 6 Missing ⚠️
...lemetry/lib/electric/telemetry/reporters/statsd.ex 0.00% 6 Missing ⚠️
...telemetry/lib/electric/telemetry/reporters/otel.ex 0.00% 3 Missing ⚠️
.../electric-telemetry/lib/electric/telemetry/opts.ex 0.00% 1 Missing ⚠️
...telemetry/lib/electric/telemetry/system_monitor.ex 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3412      +/-   ##
==========================================
+ Coverage   67.82%   75.35%   +7.53%     
==========================================
  Files         184       51     -133     
  Lines        9955     2743    -7212     
  Branches      405      409       +4     
==========================================
- Hits         6752     2067    -4685     
+ Misses       3201      674    -2527     
  Partials        2        2              
Flag Coverage Δ
electric-telemetry 22.71% <8.84%> (?)
elixir 57.74% <8.84%> (-6.27%) ⬇️
elixir-client 74.47% <ø> (+0.52%) ⬆️
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/typescript-client 93.07% <ø> (+0.08%) ⬆️
packages/y-electric 55.12% <ø> (ø)
postgres-140000 ?
postgres-150000 ?
postgres-170000 ?
postgres-180000 ?
sync-service ?
typescript 87.45% <ø> (+0.06%) ⬆️
unit-tests 75.35% <8.84%> (+7.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@netlify

netlify Bot commented Nov 10, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit 3b9522e
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/692467527fdd830008080b1e
😎 Deploy Preview https://deploy-preview-3412--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@alco
alco marked this pull request as ready for review November 10, 2025 23:25
@msfstef

msfstef commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Why not keep https://github.com/electric-sql/electric-telemetry as part of our mono-repo as another elixir project? Easier to access and work with.

@alco

alco commented Nov 11, 2025 •

Copy link
Copy Markdown
Contributor Author

@msfstef Main reason is decoupling.

Our primary use case for telemetry is in Electric Cloud. So if we're going to make any changes to the telemetry code, it'll be informed by Cloud and should be tested first in Cloud. All while Electric keeps using its own stable version of the lib.

How can we achieve that?

  1. Keep electric-telemetry in a separate repo and pin Cloud and Electric to different commits.
  2. Publish electric-telemetry on Hex and pin different versions of the package in the two repos.

Moving electric-telemetry into Electric's repo would work fine with the 2nd option but I'm against publishing our telemetry as a Hex package since it is only ever going to work as part of Electric.

With the 1st option it becomes awkward: we cannot use electric-telemetry in Electric as a path dependency because then Electric will necessarily always use the latest version of it. And the alternative is to pull it from Github (i.e. {:electric_telemetry, github: "electric-sql/electric", path: "packages/electric-telemetry", ref: "..."}), even though it's part of the same repo as Electric itself?

@alco
alco force-pushed the alco/electric-telemetry branch 4 times, most recently from 66f1c97 to 8fedf3d Compare November 12, 2025 12:16

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have a bunch of tests still in place for these, and I suspect they are still passing because we're reusing the Electric.Telemetry namespace, whereas I think this should now be in ElectricTelemetry, and the tests should move to the new repo, no?

@alco
alco force-pushed the alco/electric-telemetry branch 3 times, most recently from e9756ff to 4f74858 Compare November 18, 2025 12:13
@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@electric-sql/react@3412
npm i https://pkg.pr.new/@electric-sql/client@3412
npm i https://pkg.pr.new/@electric-sql/y-electric@3412

commit: acf1224

@alco
alco force-pushed the alco/electric-telemetry branch 9 times, most recently from 732c6de to 93eed43 Compare November 20, 2025 01:22

@magnetised magnetised left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome. We should have done it like this right from the start.

if Electric.telemetry_enabled?() do
# Disable the default telemetry_poller process since we start our own in
# `ElectricTelemetry.{ApplicationTelemetry, StackTelemetry}`.
config :telemetry_poller, default: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we set this config value as a default in packages/electric-telemetry/mix.exs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know what you mean here.

The problem is that telemetry_poller gets started before electric_telemetry because it's a dependency. And it looks up the :default key in its app env at startup. So the key has to be set before telemetry_poller gets started and config/runtime.exs of the parent app is the only place to have this config in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can add env configuration to the application callback in mix.exs: https://hexdocs.pm/elixir/1.19.3/Application.html#module-the-application-environment

If we put this required config there it would remove the need to add it at every point of use

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But that configuration is for the app owns the mix.exs. We cannot put arbitrary config for other apps, such as telemetry_poller, in there.

Comment thread packages/sync-service/lib/electric/stack_supervisor.ex Outdated
Comment thread packages/sync-service/mix.exs
alco added 5 commits November 24, 2025 15:08
These settings must be set in Electric and in Cloud, so using a single
function helps avoid discrepancies.
This way, the electric_telemetry dependency can be included or excluded
as a whole. And conditional compilation is only relevant to Electric
anyway.
The telemetry library doesn't actually use Sentry. Cloud has its own
setup for it, so electric_telemetry is not the right place for it.
Once telemetry is enabled via MIX_TARGET=application, making individual
deps optional only puts the burden on the parent app to include them
directly. We want it the other way around: let the telemetry library
define its deps and fetch them.
@alco
alco force-pushed the alco/electric-telemetry branch from e414455 to 3b9522e Compare November 24, 2025 14:10
@alco
alco merged commit c28e8ed into main Nov 25, 2025
47 checks passed
@alco
alco deleted the alco/electric-telemetry branch November 25, 2025 10:37
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been released! 🚀

The following packages include changes from this PR:

Thanks for contributing to Electric!

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.

3 participants