firebase / firebase/firebase-js-sdk

FR: Provide a way to add our own listeners to EventManager (maybe not a FR)

Open
#6,769 2 comments 0 reactions 0 assignees View on GitHub
api: firestore feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: Windows 10
* Browser version: Latest chrome
* Firebase SDK version: 9.13.0
* Firebase Product: Firestore

### [REQUIRED] Describe the problem

This is not a bug report so I won't provide steps to reproduce, but I'll explain my need, why and how I want to do what I want to do 😄 .

### Context

It all starts with https://groups.google.com/g/google-cloud-firestore-discuss/c/1WrV4sgFoU8/m/ZyI-IdanAgAJ?utm_medium=email&utm_source=footer, where I asked for some kind of requests profiler to optimize Firestore usage, this profiler's MVP features being:

- Track how much listeners you have active
- Track how many read operations you're getting with the client (without rules for the first iteration, rules parsing later on for approximate impact)

So my idea was to hook where I could in my Firestore instance (for the context: I'm using this inside of Angular with @angular/fire but that doesn't really matter since we can grab the FirestoreInstance from it anyways) and it looks like the best way to hook on this would be the EventManager instance inside of the FirestoreInstance. With this, I can monitor the amount of listeners and even have basic info for them using their key in the Map you're using.

Now, I wanted to PoC the second feature: monitoring read ops (and write/delete later on ofc). So I tried many approaches and failed, because the system is not designed for that, ofc 👍.

### What I tried

- Iterate on the QueryListener Map to add my own listener: 🚫 This breaks because then the listener is in an unexpected state, blocking the instance entirely.
- Patch the listener to add my own logic on top of it (basically patch the next method to call my probe then do its normal behavior): 🚫 looks like patching isn't an option, no mater what I do, the probe is never called so I assume it's just not possible.
- Patch the onListen method in the EventManager: 🚫 Same as above, patching this doesn't seem to be working, probably due to some integrity checks on your end but idk.

### The solution(s?)

I think there's two solutions, a quick and a slow one:

- Quick one: maybe there's a way to do that that I ignore because I only spent half a day digging in the code and I'm not a maintainer here, meaning that I don't know the code enough to find this way.
- Slow one: there's no ways to do that atm and in that case, this is really a FR because I really think it's important to provide some sort of profiler to help people understand their firestore usage on a single client.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.