Execute Query
Request Body
The dataset to query. Optional if querying a storage directly. Examples:
events, transactions, metricsThe SnQL query string
Tenant identification for attribution and rate limiting
Organization ID
Service identifier (e.g., “api”, “issues”, “discover”)
Force consistent reads from first replica
Include detailed execution stats in response
Validate query without executing
Response
Array of result rows
Column metadata with names and types
Query timing information
Resource quota and allocation details
Execution statistics (included when
debug: true or STATS_IN_RESPONSE setting enabled)Generated Clickhouse SQL (included in debug mode)
Success Response Example
Dataset-Specific Query
Query a specific dataset using dedicated endpoints:MQL Query
Execute Metrics Query Language queries:Request Body
Same as SnQL queries, but with MQL syntax in thequery field.
Query Settings
Advanced query configuration:Enable turbo mode for faster execution (may reduce accuracy)
Query Pipeline
Every query goes through a processing pipeline:Pipeline Stages
- Parse Request - Validate JSON and schema (snuba/web/views.py:234)
- Build Request - Parse SnQL/MQL into query AST (snuba/request/validation.py)
- Entity Processing - Apply entity-specific processors (snuba/pipeline/stages/query_processing.py:14)
- Storage Processing - Apply storage-specific processors (snuba/pipeline/stages/query_processing.py:16)
- Allocation Policy - Check quota and rate limits (snuba/web/db_query.py:801)
- Execute Query - Run on Clickhouse with caching (snuba/web/db_query.py:160)
- Record Metadata - Log query metadata (snuba/querylog/query_metadata.py)
Error Examples
Invalid Query
Rate Limited
Clickhouse Error
Performance Tips
Use Time Ranges
Use Time Ranges
Always filter by timestamp to leverage time-based partitioning:
Filter by Project ID
Filter by Project ID
Project ID filtering is highly optimized:
Limit Result Sets
Limit Result Sets
Use LIMIT to reduce data transfer:
Leverage Caching
Leverage Caching
Identical queries are cached. Reuse queries when possible.
Use Consistent Referrers
Use Consistent Referrers
Use descriptive, consistent referrer strings for better observability:
Related
Python Query Builder
Build queries programmatically
Subscriptions
Create recurring queries