How to Configure Cosmos DB Slow Query Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a cosmos db slow query log by routing diagnostic data to a central workspace. Once diagnostic logging is active, you filter the event stream by request charge and run time. Most engineering teams turn on these logs during a database slowdown. They often grant broad cloud roles so engineers can read the log workspace and run test queries. When roles are too broad, users get standing rights to read live production containers. How the native cosmos db slow query log works Unlike relat

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a cosmos db slow query log by routing diagnostic data to a central workspace. Once diagnostic logging is active, you filter the event stream by request charge and run time. Most engineering teams turn on these logs during a database slowdown. They often grant broad cloud roles so engineers can read the log workspace and run test queries. When roles are too broad, users get standing rights to read live production containers.

How the native cosmos db slow query log works

Unlike relational databases, this NoSQL service does not write a local text file for slow queries. Instead, the database engine emits diagnostic events for every data plane request it handles. You must set up a diagnostic rule in your cloud account to capture these events. This rule sends the raw request records to a central log analytics workspace or storage account.

Each log record holds key facts about a single database run. It shows the time taken, the request units spent, and the partition key used. To build a usable slow query view, your team writes log queries against this workspace. You filter the diagnostic table for operations that cross your latency or cost threshold. You can also turn on full query text logging in the diagnostic settings. This setting lets engineers see the exact filter predicates that caused a full container scan.

What native diagnostic logging solves and what it misses

Native diagnostic logs give your team a clear history of past database bottlenecks. They help engineers spot missing indexes, skewed partition keys, and expensive cross-partition scans. Cloud role assignments also let you control who can view the log workspace itself.

Still, diagnostic logs only tell you what happened after a slow query finishes. Native cloud roles decide who can log in, not what individual statements do in flight. When you turn on full query text capture, raw filter values flow into your log tables. Those filter values often hold sensitive emails, phone numbers, card numbers, or national IDs. Anyone with read rights to the log workspace can see those values in plain text.

Worse, fixing a slow query requires an engineer or app to test new statements against live data. If you hand out shared master keys or broad data roles, you lose control over live sessions. A user tuning a query can run an expensive scan or read restricted records. Native diagnostic settings cannot pause a risky query before it runs. They also cannot mask sensitive fields in query results during a live debugging session.

End-to-End Encryption + Log Aggregation & Correlation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why runtime query controls matter for database tuning

Relying only on post-run logs leaves a gap between detection and safe action. Teams need a way to inspect and govern database requests the moment they run. When you check requests in flight, you tie every single query to an individual user identity. You no longer rely on shared read-write keys that hide who ran a heavy command.

In-flight controls also let you apply data masking to live query outputs. Masking rewrites matched fields like emails or card numbers in results before they reach the user. Engineers can test query speed and check execution plans on real containers safely. You get fast query tuning alongside strict data privacy and clear audit trails.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does turning on diagnostic query logs slow down the database?

No, the database engine sends diagnostic events out of band to your log workspace. This process does not add latency to your live read and write requests. Still, storing high volumes of log records will increase your cloud storage and ingestion bill.

How do we find which queries cost the most request units?

You query the diagnostic log table in your workspace and sort by the request charge column. Filtering for high request charges reveals which operations scan too many documents or partitions. You can then add an index or fix the partition key in your app code.

Why do sensitive values show up in our diagnostic logs?

When you enable full query text logging, the database records the entire query string. If an app filters by an email or phone number, that value enters the log. You should restrict who can read those logs and control how engineers run ad-hoc queries.

The query runs. The emails stay hidden.