[privacy] surface local filtered-count request summary sink

In-process, thread-safe last-request-summary sink (per account_id) with a
public last_request_summary(account_id:) reader so FilteredCountInstrumentation's
documented local observability signals are consumable instead of discarded.
No APM/New Relic or any off-box egress; sink and reader stay fully in-process.
Adds regression specs asserting the completed summary (status, counts,
duration) is readable and an unknown account returns nil.
This commit is contained in:
Kunthawat Greethong
2026-08-16 07:36:06 +07:00
parent c9c0a749c3
commit 2ef6fa554b
2 changed files with 44 additions and 0 deletions

View File

@@ -44,5 +44,25 @@ RSpec.describe Conversations::UnreadCounts::FilteredCountInstrumentation do
described_class.summarize_request(account_id: 1) { raise error }
end.to raise_error(error)
end
it 'makes the completed request summary readable from the local sink' do
described_class.summarize_request(account_id: 99) do
described_class.increment(:snapshot_state, account_id: 99, snapshot_scope: :filter, snapshot_status: :missing)
described_class.observe(:snapshot_build, account_id: 99, snapshot_scope: :filter) { 'built' }
'ok'
end
summary = described_class.last_request_summary(account_id: 99)
expect(summary).not_to be_nil
expect(summary[:account_id]).to eq(99)
expect(summary[:status]).to eq(:success)
expect(summary[:snapshot_status_missing_count]).to eq(1)
expect(summary[:snapshot_build_success_count]).to eq(1)
expect(summary[:duration_ms]).to be_a(Numeric)
end
it 'returns nil from the local sink for an account with no recorded summary' do
expect(described_class.last_request_summary(account_id: 999_999)).to be_nil
end
end
end