Is there currently any way to see where Firestore reads are coming from?
I have several apps and many background + several scheduled cloud functions and it is going to be a big task to try and tune these to reduce reads if I don't know where the reads are coming from.
Even if I could split reads between the front end and the admin SDK that would help narrow things down.
All the SQL databases I have worked with have some kind of profiler to see which queries are being run and how long they take. I wouldn't mind increasing my Firestore usage while I am running the analysis as it would save me usage in the long run.
I am using Angular with AngularFire on the frontend.
EDIT:
One idea I had was to use google analytics to track the reads by using events for each query. I will update this question once I have tried it.
Since this was posted Firestore added audit logging (in late 2021), which allows you to track document reads on the backend and analyze that data using BigQuery.
For example, I could get the document read count per user per day with this query:
SELECT
JSON_VALUE(proto_payload.audit_log.authentication_info.third_party_principal.payload.user_id) as uid,
TIMESTAMP_TRUNC(timestamp, DAY) as day,
SUM(proto_payload.audit_log.num_response_items) as read_count
FROM `nanochat-20241022-mw8qu9.global._Default._AllLogs`
WHERE proto_payload.audit_log.authorization_info[0].permission_type IN ('DATA_READ', 'DATA_WRITE')
AND proto_payload.audit_log.method_name LIKE 'google.firestore.v1.Firestore%'
GROUP BY
JSON_VALUE(proto_payload.audit_log.authentication_info.third_party_principal.payload.user_id),
TIMESTAMP_TRUNC(timestamp, DAY)
When charted, that looks like this:
I wrote a post about this with more examples here: Counting document reads per user in Firestore