@trigger.dev/sdk 4.5.0-rc.5 → 4.5.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/v3/ai.d.ts +178 -5
- package/dist/commonjs/v3/ai.js +603 -119
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/chat-client.js +3 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.js +10 -7
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +8 -0
- package/dist/commonjs/v3/chat-server.js +32 -10
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat-server.test.js +51 -0
- package/dist/commonjs/v3/chat-server.test.js.map +1 -1
- package/dist/commonjs/v3/chat.js +34 -6
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chat.test.js +53 -0
- package/dist/commonjs/v3/chat.test.js.map +1 -1
- package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +11 -6
- package/dist/commonjs/v3/sessions.js +10 -5
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +178 -5
- package/dist/esm/v3/ai.js +603 -120
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/chat-client.js +3 -0
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.js +10 -7
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +8 -0
- package/dist/esm/v3/chat-server.js +32 -10
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat-server.test.js +51 -0
- package/dist/esm/v3/chat-server.test.js.map +1 -1
- package/dist/esm/v3/chat.js +34 -6
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chat.test.js +53 -0
- package/dist/esm/v3/chat.test.js.map +1 -1
- package/dist/esm/v3/createStartSessionAction.test.js +30 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +11 -6
- package/dist/esm/v3/sessions.js +10 -5
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/esm/v3/test/mock-chat-agent.js +1 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/prompts.mdx +430 -0
- package/docs/ai-chat/actions.mdx +115 -0
- package/docs/ai-chat/anatomy.mdx +71 -0
- package/docs/ai-chat/backend.mdx +817 -0
- package/docs/ai-chat/background-injection.mdx +221 -0
- package/docs/ai-chat/changelog.mdx +850 -0
- package/docs/ai-chat/chat-local.mdx +174 -0
- package/docs/ai-chat/client-protocol.mdx +1081 -0
- package/docs/ai-chat/compaction.mdx +411 -0
- package/docs/ai-chat/custom-agents.mdx +364 -0
- package/docs/ai-chat/error-handling.mdx +415 -0
- package/docs/ai-chat/fast-starts.mdx +672 -0
- package/docs/ai-chat/frontend.mdx +580 -0
- package/docs/ai-chat/how-it-works.mdx +230 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
- package/docs/ai-chat/mcp.mdx +101 -0
- package/docs/ai-chat/overview.mdx +90 -0
- package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
- package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
- package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
- package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
- package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
- package/docs/ai-chat/patterns/skills.mdx +221 -0
- package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
- package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
- package/docs/ai-chat/pending-messages.mdx +343 -0
- package/docs/ai-chat/prompt-caching.mdx +206 -0
- package/docs/ai-chat/quick-start.mdx +161 -0
- package/docs/ai-chat/reference.mdx +909 -0
- package/docs/ai-chat/server-chat.mdx +263 -0
- package/docs/ai-chat/sessions.mdx +333 -0
- package/docs/ai-chat/testing.mdx +682 -0
- package/docs/ai-chat/tools.mdx +191 -0
- package/docs/ai-chat/types.mdx +242 -0
- package/docs/ai-chat/upgrade-guide.mdx +515 -0
- package/docs/apikeys.mdx +54 -0
- package/docs/building-with-ai.mdx +261 -0
- package/docs/bulk-actions.mdx +49 -0
- package/docs/changelog.mdx +6 -0
- package/docs/cli-deploy-commands.mdx +9 -0
- package/docs/cli-dev-commands.mdx +9 -0
- package/docs/cli-dev.mdx +8 -0
- package/docs/cli-init-commands.mdx +58 -0
- package/docs/cli-introduction.mdx +25 -0
- package/docs/cli-list-profiles-commands.mdx +42 -0
- package/docs/cli-login-commands.mdx +33 -0
- package/docs/cli-logout-commands.mdx +33 -0
- package/docs/cli-preview-archive.mdx +59 -0
- package/docs/cli-promote-commands.mdx +9 -0
- package/docs/cli-switch.mdx +43 -0
- package/docs/cli-update-commands.mdx +42 -0
- package/docs/cli-whoami-commands.mdx +33 -0
- package/docs/community.mdx +6 -0
- package/docs/config/config-file.mdx +602 -0
- package/docs/config/extensions/additionalFiles.mdx +38 -0
- package/docs/config/extensions/additionalPackages.mdx +40 -0
- package/docs/config/extensions/aptGet.mdx +34 -0
- package/docs/config/extensions/audioWaveform.mdx +20 -0
- package/docs/config/extensions/custom.mdx +380 -0
- package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
- package/docs/config/extensions/esbuildPlugin.mdx +31 -0
- package/docs/config/extensions/ffmpeg.mdx +45 -0
- package/docs/config/extensions/lightpanda.mdx +56 -0
- package/docs/config/extensions/overview.mdx +67 -0
- package/docs/config/extensions/playwright.mdx +195 -0
- package/docs/config/extensions/prismaExtension.mdx +1014 -0
- package/docs/config/extensions/puppeteer.mdx +30 -0
- package/docs/config/extensions/pythonExtension.mdx +182 -0
- package/docs/config/extensions/syncEnvVars.mdx +291 -0
- package/docs/context.mdx +235 -0
- package/docs/database-connections.mdx +213 -0
- package/docs/deploy-environment-variables.mdx +435 -0
- package/docs/deployment/atomic-deployment.mdx +172 -0
- package/docs/deployment/overview.mdx +257 -0
- package/docs/deployment/preview-branches.mdx +224 -0
- package/docs/errors-retrying.mdx +379 -0
- package/docs/github-actions.mdx +222 -0
- package/docs/github-integration.mdx +136 -0
- package/docs/github-repo.mdx +8 -0
- package/docs/help-email.mdx +6 -0
- package/docs/help-slack.mdx +11 -0
- package/docs/hidden-tasks.mdx +56 -0
- package/docs/how-it-works.mdx +454 -0
- package/docs/how-to-reduce-your-spend.mdx +217 -0
- package/docs/idempotency.mdx +504 -0
- package/docs/introduction.mdx +223 -0
- package/docs/limits.mdx +241 -0
- package/docs/logging.mdx +195 -0
- package/docs/machines.mdx +952 -0
- package/docs/manual-setup.mdx +632 -0
- package/docs/mcp-agent-rules.mdx +41 -0
- package/docs/mcp-introduction.mdx +385 -0
- package/docs/mcp-tools.mdx +273 -0
- package/docs/migrating-from-v3.mdx +334 -0
- package/docs/observability/dashboards.mdx +102 -0
- package/docs/observability/query.mdx +585 -0
- package/docs/open-source-contributing.mdx +16 -0
- package/docs/open-source-self-hosting.mdx +541 -0
- package/docs/private-networking/aws-console-setup.mdx +304 -0
- package/docs/private-networking/overview.mdx +144 -0
- package/docs/private-networking/troubleshooting.mdx +78 -0
- package/docs/queue-concurrency.mdx +354 -0
- package/docs/quick-start.mdx +97 -0
- package/docs/realtime/auth.mdx +208 -0
- package/docs/realtime/backend/overview.mdx +45 -0
- package/docs/realtime/backend/streams.mdx +418 -0
- package/docs/realtime/backend/subscribe.mdx +225 -0
- package/docs/realtime/how-it-works.mdx +94 -0
- package/docs/realtime/overview.mdx +63 -0
- package/docs/realtime/react-hooks/overview.mdx +73 -0
- package/docs/realtime/react-hooks/streams.mdx +449 -0
- package/docs/realtime/react-hooks/subscribe.mdx +674 -0
- package/docs/realtime/react-hooks/swr.mdx +87 -0
- package/docs/realtime/react-hooks/triggering.mdx +194 -0
- package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
- package/docs/realtime/run-object.mdx +174 -0
- package/docs/replaying.mdx +72 -0
- package/docs/request-feature.mdx +6 -0
- package/docs/roadmap.mdx +6 -0
- package/docs/run-tests.mdx +20 -0
- package/docs/run-usage.mdx +113 -0
- package/docs/runs/heartbeats.mdx +38 -0
- package/docs/runs/max-duration.mdx +139 -0
- package/docs/runs/metadata.mdx +734 -0
- package/docs/runs/priority.mdx +31 -0
- package/docs/runs.mdx +396 -0
- package/docs/self-hosting/docker.mdx +458 -0
- package/docs/self-hosting/env/supervisor.mdx +74 -0
- package/docs/self-hosting/env/webapp.mdx +276 -0
- package/docs/self-hosting/kubernetes.mdx +601 -0
- package/docs/self-hosting/overview.mdx +108 -0
- package/docs/skills.mdx +85 -0
- package/docs/tags.mdx +120 -0
- package/docs/tasks/overview.mdx +697 -0
- package/docs/tasks/scheduled.mdx +382 -0
- package/docs/tasks/schemaTask.mdx +413 -0
- package/docs/tasks/streams.mdx +884 -0
- package/docs/triggering.mdx +1320 -0
- package/docs/troubleshooting-alerts.mdx +385 -0
- package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
- package/docs/troubleshooting-github-issues.mdx +6 -0
- package/docs/troubleshooting-uptime-status.mdx +6 -0
- package/docs/troubleshooting.mdx +398 -0
- package/docs/upgrading-packages.mdx +80 -0
- package/docs/vercel-integration.mdx +207 -0
- package/docs/versioning.mdx +56 -0
- package/docs/video-walkthrough.mdx +23 -0
- package/docs/wait-for-token.mdx +540 -0
- package/docs/wait-for.mdx +42 -0
- package/docs/wait-until.mdx +53 -0
- package/docs/wait.mdx +18 -0
- package/docs/writing-tasks-introduction.mdx +33 -0
- package/package.json +10 -6
- package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
- package/skills/trigger-authoring-tasks/SKILL.md +254 -0
- package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
- package/skills/trigger-cost-savings/SKILL.md +116 -0
- package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Query"
|
|
3
|
+
description: "Query allows you to write custom queries against your data using TRQL (Trigger.dev Query Language), a SQL-style language based on ClickHouse SQL. You can query your data through the dashboard, SDK, or REST API."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
### Available tables
|
|
7
|
+
|
|
8
|
+
- `runs`: contains all task run data including status, timing, costs, and task output. Run metadata (key-value set in your task) is not available on the Query page.
|
|
9
|
+
- `metrics`: contains metrics data for your runs including CPU, memory, and your custom metrics
|
|
10
|
+
- `llm_metrics`: contains LLM/AI metrics including token usage, costs, latency, and model performance data from GenAI spans
|
|
11
|
+
|
|
12
|
+
### `metrics` table columns
|
|
13
|
+
|
|
14
|
+
| Column | Type | Description |
|
|
15
|
+
| :--- | :--- | :--- |
|
|
16
|
+
| `metric_name` | string | Metric identifier (e.g., `process.cpu.utilization`) |
|
|
17
|
+
| `metric_type` | string | `gauge`, `sum`, or `histogram` |
|
|
18
|
+
| `metric_value` | number | The observed value |
|
|
19
|
+
| `bucket_start` | datetime | 10-second aggregation bucket start time |
|
|
20
|
+
| `run_id` | string | Associated run ID |
|
|
21
|
+
| `task_identifier` | string | Task slug |
|
|
22
|
+
| `attempt_number` | number | Attempt number |
|
|
23
|
+
| `machine_id` | string | Machine that produced the metric |
|
|
24
|
+
| `machine_name` | string | Machine preset (e.g., `small-1x`) |
|
|
25
|
+
| `worker_version` | string | Worker version |
|
|
26
|
+
| `environment_type` | string | `PRODUCTION`, `STAGING`, `DEVELOPMENT`, `PREVIEW` |
|
|
27
|
+
| `attributes` | json | Raw JSON attributes for custom data |
|
|
28
|
+
|
|
29
|
+
See [Logging, tracing & metrics](/logging#automatic-system-and-runtime-metrics) for the full list of automatically collected metrics and how to create custom metrics. You can visualize this data on [Dashboards](/observability/dashboards).
|
|
30
|
+
|
|
31
|
+
### `prettyFormat()`
|
|
32
|
+
|
|
33
|
+
Use `prettyFormat()` to format metric values for display:
|
|
34
|
+
|
|
35
|
+
```sql
|
|
36
|
+
SELECT
|
|
37
|
+
timeBucket(),
|
|
38
|
+
prettyFormat(avg(metric_value), 'bytes') AS avg_memory_usage
|
|
39
|
+
FROM metrics
|
|
40
|
+
WHERE metric_name = 'process.memory.usage'
|
|
41
|
+
GROUP BY timeBucket
|
|
42
|
+
ORDER BY timeBucket
|
|
43
|
+
LIMIT 1000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Available format types: `bytes`, `percent`, `duration`, `durationSeconds`, `quantity`, `costInDollars`.
|
|
47
|
+
|
|
48
|
+
## Using the Query dashboard
|
|
49
|
+
|
|
50
|
+
Navigate to the Query page to write and execute queries. The dashboard provides:
|
|
51
|
+
|
|
52
|
+
- **AI-powered query generation** - Describe what you want in natural language
|
|
53
|
+
- **Syntax highlighting** - SQL syntax highlighting for better readability
|
|
54
|
+
- **Query history** - Access your previous queries
|
|
55
|
+
- **Interactive help** - Built-in documentation for TRQL syntax and functions
|
|
56
|
+
- **Export options** - Download results as JSON or CSV
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
## Querying from the SDK
|
|
61
|
+
|
|
62
|
+
Use `query.execute()` to run TRQL queries programmatically from your backend code:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { query } from "@trigger.dev/sdk";
|
|
66
|
+
|
|
67
|
+
// Basic query with defaults (environment scope, json format)
|
|
68
|
+
const result = await query.execute("SELECT run_id, status FROM runs LIMIT 10");
|
|
69
|
+
console.log(result.results); // Array<Record<string, any>>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Type-safe queries
|
|
73
|
+
|
|
74
|
+
Use the `QueryTable` type for nice inferred types in your query results:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { query, type QueryTable } from "@trigger.dev/sdk";
|
|
78
|
+
|
|
79
|
+
// Type-safe query using QueryTable with specific columns
|
|
80
|
+
const typedResult = await query.execute<QueryTable<"runs", "run_id" | "status" | "triggered_at">>(
|
|
81
|
+
"SELECT run_id, status, triggered_at FROM runs LIMIT 10"
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
typedResult.results.forEach((row) => {
|
|
85
|
+
console.log(row.run_id, row.status); // Fully typed!
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Query options
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { query } from "@trigger.dev/sdk";
|
|
93
|
+
|
|
94
|
+
const result = await query.execute("SELECT COUNT(*) as count FROM runs", {
|
|
95
|
+
// Scope: "environment" (default), "project", or "organization"
|
|
96
|
+
scope: "project",
|
|
97
|
+
// Time period using shorthand (e.g., "7d", "30d", "1h")
|
|
98
|
+
period: "7d",
|
|
99
|
+
// Or use explicit time range
|
|
100
|
+
// from: new Date("2024-01-01"),
|
|
101
|
+
// to: new Date("2024-01-31"),
|
|
102
|
+
|
|
103
|
+
// Response format: "json" (default) or "csv"
|
|
104
|
+
format: "json",
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### CSV export
|
|
109
|
+
|
|
110
|
+
Export query results as CSV by setting `format: "csv"`:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const csvResult = await query.execute("SELECT run_id, status, triggered_at FROM runs", {
|
|
114
|
+
format: "csv",
|
|
115
|
+
period: "7d",
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const lines = csvResult.results.split("\n");
|
|
119
|
+
console.log(lines[0]); // CSV header row
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Querying from the REST API
|
|
123
|
+
|
|
124
|
+
Execute queries via HTTP POST to `/api/v1/query`:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
curl -X POST https://api.trigger.dev/api/v1/query \
|
|
128
|
+
-H "Authorization: Bearer YOUR_SECRET_KEY" \
|
|
129
|
+
-H "Content-Type: application/json" \
|
|
130
|
+
-d '{
|
|
131
|
+
"query": "SELECT run_id, status FROM runs LIMIT 10",
|
|
132
|
+
"scope": "environment",
|
|
133
|
+
"period": "7d",
|
|
134
|
+
"format": "json"
|
|
135
|
+
}'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
See the [API reference](/management/query/execute) for full details.
|
|
139
|
+
|
|
140
|
+
## TRQL syntax guide
|
|
141
|
+
|
|
142
|
+
### Basic queries
|
|
143
|
+
|
|
144
|
+
Select columns from a table:
|
|
145
|
+
|
|
146
|
+
```sql
|
|
147
|
+
SELECT run_id, task_identifier, status
|
|
148
|
+
FROM runs
|
|
149
|
+
LIMIT 10
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Alias columns with `AS`:
|
|
153
|
+
|
|
154
|
+
```sql
|
|
155
|
+
SELECT task_identifier AS task, count() AS total
|
|
156
|
+
FROM runs
|
|
157
|
+
GROUP BY task
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Using \*
|
|
161
|
+
|
|
162
|
+
Note that when you use `SELECT *` we don't return all the columns, we only return the core columns. This is for performance reasons (the underlying ClickHouse database is columnar and selecting lots of columns isn't efficient).
|
|
163
|
+
|
|
164
|
+
You should specify the columns you want to return.
|
|
165
|
+
|
|
166
|
+
### Filtering with WHERE
|
|
167
|
+
|
|
168
|
+
Use comparison operators:
|
|
169
|
+
|
|
170
|
+
```sql
|
|
171
|
+
SELECT run_id, task_identifier FROM runs
|
|
172
|
+
WHERE status = 'Failed'
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Available operators:
|
|
176
|
+
|
|
177
|
+
```sql
|
|
178
|
+
-- Comparison operators
|
|
179
|
+
WHERE status = 'Failed' -- Equal
|
|
180
|
+
WHERE status != 'Completed' -- Not equal
|
|
181
|
+
WHERE attempt_count > 3 -- Greater than
|
|
182
|
+
WHERE attempt_count >= 3 -- Greater than or equal
|
|
183
|
+
WHERE attempt_count < 5 -- Less than
|
|
184
|
+
WHERE attempt_count <= 5 -- Less than or equal
|
|
185
|
+
|
|
186
|
+
-- IN for multiple values
|
|
187
|
+
WHERE status IN ('Failed', 'Crashed')
|
|
188
|
+
|
|
189
|
+
-- LIKE for pattern matching (% = wildcard)
|
|
190
|
+
WHERE task_identifier LIKE 'email%'
|
|
191
|
+
|
|
192
|
+
-- ILIKE for case-insensitive matching
|
|
193
|
+
WHERE task_identifier ILIKE '%send%'
|
|
194
|
+
|
|
195
|
+
-- BETWEEN for ranges
|
|
196
|
+
WHERE triggered_at BETWEEN '2024-01-01' AND '2024-01-31'
|
|
197
|
+
|
|
198
|
+
-- NULL checks
|
|
199
|
+
WHERE completed_at IS NOT NULL
|
|
200
|
+
WHERE completed_at IS NULL
|
|
201
|
+
|
|
202
|
+
-- Array column checks
|
|
203
|
+
WHERE has(tags, 'user_12345')
|
|
204
|
+
WHERE notEmpty(tags)
|
|
205
|
+
WHERE hasAny(tags, array('user_12345', 'user_67890'))
|
|
206
|
+
WHERE hasAll(tags, array('user_12345', 'user_67890'))
|
|
207
|
+
WHERE indexOf(tags, 'user_12345') > 0
|
|
208
|
+
WHERE arrayElement(tags, 1) = 'user_12345'
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Sorting and limiting
|
|
212
|
+
|
|
213
|
+
Sort results with `ORDER BY`:
|
|
214
|
+
|
|
215
|
+
```sql
|
|
216
|
+
SELECT run_id, compute_cost, triggered_at
|
|
217
|
+
FROM runs
|
|
218
|
+
ORDER BY compute_cost DESC, triggered_at ASC
|
|
219
|
+
LIMIT 50
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Grouping and aggregation
|
|
223
|
+
|
|
224
|
+
Use `GROUP BY` with aggregate functions:
|
|
225
|
+
|
|
226
|
+
```sql
|
|
227
|
+
SELECT
|
|
228
|
+
task_identifier,
|
|
229
|
+
avg(metric_value) AS avg_memory
|
|
230
|
+
FROM metrics
|
|
231
|
+
WHERE metric_name = 'process.memory.usage'
|
|
232
|
+
GROUP BY task_identifier
|
|
233
|
+
ORDER BY avg_memory DESC
|
|
234
|
+
LIMIT 20
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Available functions
|
|
238
|
+
|
|
239
|
+
TRQL provides a rich set of functions for data analysis.
|
|
240
|
+
|
|
241
|
+
### Aggregate functions
|
|
242
|
+
|
|
243
|
+
- `count()` - Count rows
|
|
244
|
+
- `countIf(col, cond)` - Count rows matching condition
|
|
245
|
+
- `countDistinct(col)` - Count unique values
|
|
246
|
+
- `sum(col)` - Sum of values
|
|
247
|
+
- `sumIf(col, cond)` - Sum values matching condition
|
|
248
|
+
- `avg(col)` - Average of values
|
|
249
|
+
- `min(col)` - Minimum value
|
|
250
|
+
- `max(col)` - Maximum value
|
|
251
|
+
- `median(col)` - Median value (50th percentile)
|
|
252
|
+
- `quantile(p)(col)` - Value at percentile p (0-1)
|
|
253
|
+
- `stddevPop(col)` - Population standard deviation
|
|
254
|
+
- `stddevSamp(col)` - Sample standard deviation
|
|
255
|
+
|
|
256
|
+
Example:
|
|
257
|
+
|
|
258
|
+
```sql
|
|
259
|
+
SELECT
|
|
260
|
+
task_identifier,
|
|
261
|
+
count() AS total_runs,
|
|
262
|
+
avg(usage_duration) AS avg_duration_ms,
|
|
263
|
+
median(usage_duration) AS median_duration_ms,
|
|
264
|
+
quantile(0.95)(usage_duration) AS p95_duration_ms
|
|
265
|
+
FROM runs
|
|
266
|
+
GROUP BY task_identifier
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Date/time functions
|
|
270
|
+
|
|
271
|
+
**Time bucketing:**
|
|
272
|
+
|
|
273
|
+
```sql
|
|
274
|
+
-- Auto-bucket by time period based on query's time range
|
|
275
|
+
SELECT timeBucket(), count() AS runs
|
|
276
|
+
FROM runs
|
|
277
|
+
GROUP BY timeBucket()
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Date extraction:**
|
|
281
|
+
|
|
282
|
+
```sql
|
|
283
|
+
SELECT
|
|
284
|
+
toYear(triggered_at) AS year,
|
|
285
|
+
toMonth(triggered_at) AS month,
|
|
286
|
+
toDayOfWeek(triggered_at) AS day_of_week,
|
|
287
|
+
toHour(triggered_at) AS hour
|
|
288
|
+
FROM runs
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Date truncation:**
|
|
292
|
+
|
|
293
|
+
```sql
|
|
294
|
+
SELECT
|
|
295
|
+
toStartOfDay(triggered_at) AS day,
|
|
296
|
+
count() AS runs_per_day
|
|
297
|
+
FROM runs
|
|
298
|
+
GROUP BY day
|
|
299
|
+
ORDER BY day DESC
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Date arithmetic:**
|
|
303
|
+
|
|
304
|
+
```sql
|
|
305
|
+
-- Add/subtract time
|
|
306
|
+
SELECT dateAdd('day', 7, triggered_at) AS week_later
|
|
307
|
+
FROM runs
|
|
308
|
+
|
|
309
|
+
-- Calculate differences
|
|
310
|
+
SELECT dateDiff('minute', executed_at, completed_at) AS duration_minutes
|
|
311
|
+
FROM runs
|
|
312
|
+
WHERE completed_at IS NOT NULL
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Common date functions:
|
|
316
|
+
|
|
317
|
+
- `now()` - Current date and time
|
|
318
|
+
- `today()` - Current date
|
|
319
|
+
- `toDate(dt)` - Convert to date
|
|
320
|
+
- `toStartOfDay(dt)`, `toStartOfHour(dt)`, `toStartOfMonth(dt)` - Truncate to start of period
|
|
321
|
+
- `formatDateTime(dt, format)` - Format datetime as string
|
|
322
|
+
|
|
323
|
+
### String functions
|
|
324
|
+
|
|
325
|
+
```sql
|
|
326
|
+
SELECT
|
|
327
|
+
lower(status) AS status_lower,
|
|
328
|
+
upper(status) AS status_upper,
|
|
329
|
+
concat(task_identifier, '-', status) AS combined,
|
|
330
|
+
substring(run_id, 1, 8) AS short_id,
|
|
331
|
+
length(task_identifier) AS name_length
|
|
332
|
+
FROM runs
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Common string functions:
|
|
336
|
+
|
|
337
|
+
- `length(s)` - String length
|
|
338
|
+
- `lower(s)`, `upper(s)` - Case conversion
|
|
339
|
+
- `concat(s1, s2, ...)` - Concatenate strings
|
|
340
|
+
- `substring(s, offset, len)` - Extract substring
|
|
341
|
+
- `trim(s)` - Remove whitespace
|
|
342
|
+
- `replace(s, from, to)` - Replace occurrences
|
|
343
|
+
- `startsWith(s, prefix)`, `endsWith(s, suffix)` - Check prefixes/suffixes
|
|
344
|
+
|
|
345
|
+
### Conditional functions
|
|
346
|
+
|
|
347
|
+
```sql
|
|
348
|
+
SELECT
|
|
349
|
+
run_id,
|
|
350
|
+
if(status = 'Failed', 1, 0) AS is_failed,
|
|
351
|
+
multiIf(
|
|
352
|
+
status = 'Completed', 'ok',
|
|
353
|
+
status = 'Failed', 'bad',
|
|
354
|
+
'other'
|
|
355
|
+
) AS status_category,
|
|
356
|
+
coalesce(completed_at, triggered_at) AS end_time
|
|
357
|
+
FROM runs
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
- `if(cond, then, else)` - Conditional expression
|
|
361
|
+
- `multiIf(c1, t1, c2, t2, ..., else)` - Multiple conditions (like CASE)
|
|
362
|
+
- `coalesce(a, b, ...)` - First non-null value
|
|
363
|
+
|
|
364
|
+
### Math functions
|
|
365
|
+
|
|
366
|
+
```sql
|
|
367
|
+
SELECT
|
|
368
|
+
round(compute_cost, 4) AS cost_rounded,
|
|
369
|
+
ceil(usage_duration / 1000) AS duration_seconds_up,
|
|
370
|
+
floor(usage_duration / 1000) AS duration_seconds_down,
|
|
371
|
+
abs(compute_cost) AS cost_abs
|
|
372
|
+
FROM runs
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Array functions
|
|
376
|
+
|
|
377
|
+
Useful for working with tags and other array columns:
|
|
378
|
+
|
|
379
|
+
```sql
|
|
380
|
+
SELECT
|
|
381
|
+
run_id,
|
|
382
|
+
tags,
|
|
383
|
+
length(tags) AS tag_count,
|
|
384
|
+
has(tags, 'user_12345') AS is_production,
|
|
385
|
+
arrayJoin(tags) AS individual_tag -- Expand array to rows
|
|
386
|
+
FROM runs
|
|
387
|
+
WHERE notEmpty(tags)
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### JSON functions
|
|
391
|
+
|
|
392
|
+
The `output`, `error`, and `metrics.attributes` columns are already JSON, so use dot notation to read or filter on them. You don't need `JSONExtract*` for these (those are for string columns).
|
|
393
|
+
|
|
394
|
+
```sql
|
|
395
|
+
SELECT
|
|
396
|
+
run_id,
|
|
397
|
+
output.message AS output_message,
|
|
398
|
+
output.count AS count,
|
|
399
|
+
output.externalId AS external_id
|
|
400
|
+
FROM runs
|
|
401
|
+
WHERE task_identifier = 'my-task'
|
|
402
|
+
AND output.externalId = 'something'
|
|
403
|
+
ORDER BY triggered_at DESC
|
|
404
|
+
LIMIT 100
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Query scopes
|
|
408
|
+
|
|
409
|
+
Control what data your query can access:
|
|
410
|
+
|
|
411
|
+
- **`environment`** (default) - Query runs in the current environment only
|
|
412
|
+
- **`project`** - Query runs across all environments in the project
|
|
413
|
+
- **`organization`** - Query runs across all projects in the organization
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
// Query across all environments in a project
|
|
417
|
+
const result = await query.execute("SELECT environment, count() FROM runs GROUP BY environment", {
|
|
418
|
+
scope: "project",
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Time ranges
|
|
423
|
+
|
|
424
|
+
We recommend avoiding adding `triggered_at` in the actual TRQL query. The dashboard, API, and SDK have a time filter that is applied automatically and is easier to work with. It means the queries can be executed with multiple periods easily.
|
|
425
|
+
|
|
426
|
+
### Using period shorthand
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
await query.execute("SELECT count() FROM runs", {
|
|
430
|
+
period: "4d", // Last 4 days
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Supported periods: "1h", "6h", "12h", "1d", "7d", "30d", "90d", etc.
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Using explicit dates
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
await query.execute("SELECT count() FROM runs", {
|
|
440
|
+
from: new Date("2024-01-01"),
|
|
441
|
+
to: new Date("2024-01-31"),
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// Or use Unix timestamps
|
|
445
|
+
await query.execute("SELECT count() FROM runs", {
|
|
446
|
+
from: Date.now() - 7 * 24 * 60 * 60 * 1000, // 7 days ago
|
|
447
|
+
to: Date.now(),
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Example queries
|
|
452
|
+
|
|
453
|
+
### Failed runs (in the last 24 hours)
|
|
454
|
+
|
|
455
|
+
```sql
|
|
456
|
+
SELECT
|
|
457
|
+
task_identifier,
|
|
458
|
+
run_id,
|
|
459
|
+
error,
|
|
460
|
+
triggered_at
|
|
461
|
+
FROM runs
|
|
462
|
+
WHERE status = 'Failed'
|
|
463
|
+
ORDER BY triggered_at DESC
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
With the time filter set to 24h.
|
|
467
|
+
|
|
468
|
+
### Task success rate by day
|
|
469
|
+
|
|
470
|
+
```sql
|
|
471
|
+
SELECT
|
|
472
|
+
toDate(triggered_at) AS day,
|
|
473
|
+
task_identifier,
|
|
474
|
+
countIf(status = 'Completed') AS completed,
|
|
475
|
+
countIf(status = 'Failed') AS failed,
|
|
476
|
+
round(completed / (completed + failed) * 100, 2) AS success_rate_pct
|
|
477
|
+
FROM runs
|
|
478
|
+
WHERE status IN ('Completed', 'Failed')
|
|
479
|
+
GROUP BY day, task_identifier
|
|
480
|
+
ORDER BY day DESC, task_identifier
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Top 10 most expensive runs
|
|
484
|
+
|
|
485
|
+
```sql
|
|
486
|
+
SELECT
|
|
487
|
+
run_id,
|
|
488
|
+
task_identifier,
|
|
489
|
+
compute_cost,
|
|
490
|
+
usage_duration,
|
|
491
|
+
triggered_at
|
|
492
|
+
FROM runs
|
|
493
|
+
WHERE compute_cost > 0
|
|
494
|
+
ORDER BY compute_cost DESC
|
|
495
|
+
LIMIT 10
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Average compute duration over time
|
|
499
|
+
|
|
500
|
+
```sql
|
|
501
|
+
SELECT
|
|
502
|
+
timeBucket() AS time,
|
|
503
|
+
task_identifier,
|
|
504
|
+
avg(usage_duration) AS avg_duration_ms,
|
|
505
|
+
count() AS run_count
|
|
506
|
+
FROM runs
|
|
507
|
+
WHERE usage_duration IS NOT NULL
|
|
508
|
+
GROUP BY time, task_identifier
|
|
509
|
+
ORDER BY time ASC
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### Runs by queue and machine
|
|
513
|
+
|
|
514
|
+
```sql
|
|
515
|
+
SELECT
|
|
516
|
+
queue,
|
|
517
|
+
machine,
|
|
518
|
+
count() AS run_count,
|
|
519
|
+
countIf(status = 'Completed') AS completed,
|
|
520
|
+
countIf(status = 'Failed') AS failed
|
|
521
|
+
FROM runs
|
|
522
|
+
GROUP BY queue, machine
|
|
523
|
+
ORDER BY queue, machine
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### CPU utilization over time
|
|
527
|
+
|
|
528
|
+
Track process CPU utilization bucketed over time.
|
|
529
|
+
|
|
530
|
+
```sql
|
|
531
|
+
SELECT
|
|
532
|
+
timeBucket(),
|
|
533
|
+
avg(metric_value) AS avg_cpu
|
|
534
|
+
FROM metrics
|
|
535
|
+
WHERE metric_name = 'process.cpu.utilization'
|
|
536
|
+
GROUP BY timeBucket
|
|
537
|
+
ORDER BY timeBucket
|
|
538
|
+
LIMIT 1000
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Memory usage by task (past 7d)
|
|
542
|
+
|
|
543
|
+
Average process memory usage per task identifier over the last 7 days.
|
|
544
|
+
|
|
545
|
+
```sql
|
|
546
|
+
SELECT
|
|
547
|
+
task_identifier,
|
|
548
|
+
avg(metric_value) AS avg_memory
|
|
549
|
+
FROM metrics
|
|
550
|
+
WHERE metric_name = 'process.memory.usage'
|
|
551
|
+
GROUP BY task_identifier
|
|
552
|
+
ORDER BY avg_memory DESC
|
|
553
|
+
LIMIT 20
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Available metric names
|
|
557
|
+
|
|
558
|
+
List all distinct metric names collected in your environment.
|
|
559
|
+
|
|
560
|
+
```sql
|
|
561
|
+
SELECT
|
|
562
|
+
metric_name,
|
|
563
|
+
count() AS sample_count
|
|
564
|
+
FROM metrics
|
|
565
|
+
GROUP BY metric_name
|
|
566
|
+
ORDER BY sample_count DESC
|
|
567
|
+
LIMIT 100
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## Best practices
|
|
571
|
+
|
|
572
|
+
1. **Use the built-in time filtering** - The dashboard, API, and SDK have a time filter that is applied automatically and is easier to work with. It means the queries can be executed with multiple periods easily.
|
|
573
|
+
2. **Use LIMIT** - Add a `LIMIT` clause to reduce the rows returned if you don't need everything.
|
|
574
|
+
3. **Use appropriate aggregations** - For large datasets, use `uniq()` instead of `uniqExact()` for approximate but faster counts
|
|
575
|
+
|
|
576
|
+
## Limits
|
|
577
|
+
|
|
578
|
+
We have several limits to prevent abuse and ensure performance:
|
|
579
|
+
|
|
580
|
+
- **Concurrency limit**: We limit the number of concurrent queries per organization.
|
|
581
|
+
- **Row limit**: We limit the number of rows returned to 10k.
|
|
582
|
+
- **Time restrictions**: We limit the time period you can query.
|
|
583
|
+
- **Time/Memory limit**: We limit the memory a query can use and the time it can run for. As well as other limits like AST complexity.
|
|
584
|
+
|
|
585
|
+
See [Limits](/limits) for current quota details.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Contributing"
|
|
3
|
+
description: "You can contribute to Trigger.dev in many ways."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Go to our [GitHub repository](https://github.com/triggerdotdev/trigger.dev) and open an issue or a pull request. We are always looking for contributors to help us improve Trigger.dev. You can contribute in many ways, including:
|
|
7
|
+
|
|
8
|
+
- Reporting bugs
|
|
9
|
+
- Suggesting new features
|
|
10
|
+
- Writing documentation
|
|
11
|
+
- Writing code
|
|
12
|
+
- Reviewing code
|
|
13
|
+
- Translating the app
|
|
14
|
+
- Sharing the app with others
|
|
15
|
+
- Giving feedback
|
|
16
|
+
- And more!
|