# Building a Usage Dashboard Without Logging Arguments or Response Bodies

How DataToRAG's usage dashboard shows calls, latency, and errors per tool without storing argument values or response bodies. What is recorded.

Published: 2026-04-20  
Updated: 2026-11-25  
Source: https://datatorag.com/blog/usage-metrics-for-multi-tenant-mcp

Users kept asking the same thing. "Is it actually doing anything?" They'd wire their agent up to DataToRAG, kick off a workflow, and have no way to see what happened. Did Gmail even get called? Did a search fail silently? Was the slow response our fault or Anthropic's?

We needed a usage dashboard. But DataToRAG is a multi-tenant MCP gateway. Every user's data flows through the same pipes on its way to Google or Atlassian, so the last thing anyone wants is a "helpful" dashboard that logs their Gmail search terms or the contents of a Jira comment they just drafted.

The first design constraint was easy to name: track behavior, not content.

## What we log, and what we refuse to

For every tool call we record these things:

- Tool name (`gmail_search`, `jira_create_issue`)
- Connector (`google-workspace`, `atlassian`)
- Outcome label (`success`, `user_error`, or `server_error`)
- Latency in milliseconds
- Response size in bytes
- The error message when something failed, stored as received and capped in length
- The connected account the call used, the client that made it, the size of its arguments and the units it counted for
- For the raw `gws_run` call only: the API service, resource and method, and the names of the parameters it passed, never their values

That's the whole row. No arguments. No response body. No `q=` search query, no message ID, no ticket title, no document contents.

If a call errored with something like `"Message 18f3a2c1b not found for user alice@company.com"`, we store that string as received and capped in length, in a row only that user can see. It quotes their own data, and they already received the same error in full when the call failed, so censoring the stored copy only made failures harder to diagnose. The redaction happens on the way out instead: before that message is sent to our analytics provider it runs through a regex redactor that replaces emails, Google Drive IDs, and long quoted strings with a `[redacted]` marker. The error message is useful because it tells users why something failed. It's not worth sending PII to a third party to get there.

The schema lives in a single `usage_events` table in the same Postgres instance as the rest of the app, with no separate warehouse and no cross-region replication. A redacted copy of each tool-call event also goes to our analytics provider.

## Counting what matters

Not every tool call should count equally. We settled on three outcome buckets:

**Success.** Gateway dispatched the call, upstream API returned 2xx, plugin handed back a normal response. Counted.

**User error.** Gateway dispatched the call, upstream API returned something the user can fix (404 on a missing message, 400 on bad JQL, 403 on a file the user can't access). Counted. These are legitimate invocations. The system did its job. The user asked for something that doesn't exist.

**Server error.** Our gateway choked, a plugin threw, or the upstream API had a 5xx outage. *Not counted.* If we're broken, that's on us. Charging the user (or even showing it in their metrics) is the wrong signal.

When this was written, calls from the in-dashboard tool tester did not count either. Since August 2026 calls made by the hosted agent count like any other call, and plans are billed on this meter.

The classifier that makes this decision is one function with a handful of branches. Every code path that dispatches a tool call routes through it, so the meter rules can't drift between the MCP endpoint and the playground.

## Why we write synchronously (with a 200ms leash)

The easy architecture for something like this is "fire and forget through a queue." Tool call finishes, push an event onto a Redis list, have a worker drain it into Postgres.

We didn't do that.

The reason is blast radius. Redis down means events silently lost. A worker lag spike means the dashboard shows stale data five minutes after a call. And every event pipeline eventually develops a dead-letter queue that someone has to babysit.

Instead, `writeUsageEvent` runs inline with the tool-call response path, wrapped in a `Promise.race` with a 200ms timeout. If Postgres is healthy (the common case), the insert finishes in a millisecond and the response flows through. If Postgres is wedged, the insert loses the race, we log a warning, and the tool-call response goes out anyway. The user gets their tool result. The metric is the thing that drops, not the call itself.

This works because the write is small and indexed, and because we're willing to accept "some events missed during an outage" in exchange for "dashboard is always real-time during normal operation."

![Write path: 200ms leash](https://datatorag.com/blog/usage-write-path.png)

## Daily rollups and 90-day retention

Raw events are expensive to keep forever, and nobody needs per-call detail for a call that happened four months ago.

Every night at 02:00 UTC, a `node-cron` job runs:

```
INSERT INTO usage_events_daily (day, user_id, tool_name, ...)
SELECT yesterday, user_id, tool_name,
       count(*),
       count(*) filter (where status = 'user_error'),
       percentile_cont(0.5) within group (order by latency_ms),
       percentile_cont(0.95) within group (order by latency_ms),
       sum(response_size_bytes)
  FROM usage_events
 WHERE created_at >= yesterday AND created_at < today
 GROUP BY user_id, tool_name, connector
ON CONFLICT (day, user_id, tool_name) DO UPDATE SET ...;

DELETE FROM usage_events WHERE created_at < now() - INTERVAL '90 days';
```

The rollup is idempotent. If the job runs twice, the `ON CONFLICT` clause just overwrites. The prune drops anything older than 90 days. Every range on the dashboard, 24h through 90d, reads the raw `usage_events` table, which holds 90 days. No dashboard view reads `usage_events_daily`; the daily rows are what is left of older usage after the raw events are pruned. (An earlier version of this paragraph said the 30d and 90d views read the daily table. They never did.)

We picked `node-cron` over Postgres's `pg_cron` extension because the gateway already owns a long-running process. Adding a dependency on a Postgres extension to run one query per day felt like overkill. If the gateway is up, the cron runs. If the gateway is down, nothing is happening anyway and there's no metrics to roll up.

## Rate-limiting the dashboard's own APIs

The dashboard launched with five API endpoints: summary, timeseries, by-tool, by-connector, recent. (Two more, runs and sessions, were added on September 11, 2026 for the agent sessions panel, and sit behind the same limiter.) All of them run Postgres aggregations. All of them are cheap individually, but expensive if someone holds down F5.

We wrapped them in an in-memory sliding-window rate limiter: 120 requests per user per minute, returns a `429` with `Retry-After` when you blow through it. The limiter is a `Map<userId, number[]>` where each array holds timestamps of recent requests. Every 5 minutes, a sweep pass evicts empty buckets so the Map doesn't accumulate entries for users who have signed out.

This is deliberately simple. No Redis, no distributed state, no leaky-bucket math. The gateway runs as a single process. If we ever horizontal-scale it, we'll revisit. For now, in-memory is fine and the code is 50 lines.

## The dashboard itself

The UI is a Next.js server component with a client-side range toggle (24h / 7d / 30d / 90d). When the range changes, it refetches the endpoints that take a range (timeseries, by-tool, by-connector, and the two session endpoints) in parallel and updates the chart, the breakdown, the per-tool table, and the agent sessions. The summary cards and recent activity do not change with the range. (This paragraph used to say a range change refetched all five endpoints and updated the cards.)

Two choices worth naming.

**"Median" and "slow-end" instead of "P50" and "P95."** Users aren't SREs. "Slow-end latency" tells them "this is the speed you get on a bad day" without requiring them to know what a percentile is. I went back and forth on this one. The instinct when you work on infrastructure is to use the precise term. The instinct is wrong when you're writing UI for people who have better things to do than learn percentiles.

**Click a tool row to drill down.** The table lists every tool the user has called. Clicking one navigates to `/dashboard/usage/[tool]` with the last 50 calls and per-tool aggregates. The drill-down is the answer to "what actually broke?" It's where the error messages live.

![Per-tool drill-down: aggregates plus the last 50 calls with status and latency](https://datatorag.com/blog/usage-drilldown.png)

## What it's worth

A usage dashboard in a multi-tenant service isn't a feature. It's a trust signal. The promise is that you can see what your agent is doing, and that what we keep to show you is a record of the call, not its contents: no argument values, no response bodies, and an error message that can quote your own data, kept in a row only you can see.

We got there by being disciplined about the row schema: what was called, by which account and client, the outcome, latency and sizes, and the error message. No argument values and no response body.

Billing now runs on this meter, and the semantics held: success and user errors count, server errors don't. The [usage docs](https://datatorag.com/docs/usage) say what the dashboard shows today, and [plans and limits](https://datatorag.com/docs/plans-and-limits) says what counts as a call.

But that's a post for another day.

## Edit history

- November 25, 2026: the usage API launched with five endpoints and has had seven since September 11, 2026, when runs and sessions were added; and a range change refetches only the endpoints that take a range, since the summary cards and recent activity do not change with it, where the post said it refetched all five; corrected which table the dashboard reads. The post said the 30d and 90d views read the daily rollup table; every range reads the raw events table, which holds 90 days, and no dashboard view reads the daily table. The closing promise is also reworded to match what the row holds, since a stored error message can quote your data. Also retitled. The title said the dashboard logs no user data. The row holds no arguments and no response bodies, but a stored error message is kept as received and can quote the user's own data, as the post itself says, so the title now says what is true.
- November 17, 2026: the row now lists every field it holds (the account, client, argument size and cost units, and for the raw gws_run call its service, resource, method and parameter names, never values); a redacted copy of each event goes to our analytics provider; and hosted agent calls count, since plans are billed on this meter. Corrected the error-message claim. The post said stored error messages are redacted, which was true when it was written and is no longer. The redaction protected against sending user content to a third-party analytics provider, and that still happens; it was never a reason to censor the copy stored for the user in a row only they can see, quoting an error they had already received in full. The stored copy is now raw.
