Trasys
Node.js SDK

Trasys Query Language (TQL)

Query your traces, logs, metrics, and AI events using TQL, a SQL-like query language for filtering and searching the observability data Trasys collects daily.

Trasys Query Language (TQL)

TQL is a query language for searching and filtering the observability data collected by Trasys. The syntax is close to SQL but adapted for trace and event data.

This page covers the core TQL structure. Provider-specific functions, aggregation operators, and advanced query patterns are documented separately in the TQL reference.

Basic structure

SELECT <fields>
FROM   <data_source>
WHERE  <conditions>
LIMIT  <n>

Example queries

Find slow requests:

SELECT trace_id, http.route, http.duration_ms, user_id
FROM   spans
WHERE  http.duration_ms > 2000
  AND  service = 'payment-service'
  AND  time > now() - 1h
LIMIT  100

Find expensive AI calls:

SELECT trace_id, gen_ai.request.model, gen_ai.usage.input_tokens, trasys.ai.cost_usd
FROM   ai_spans
WHERE  trasys.ai.cost_usd > 0.10
  AND  time > now() - 24h
ORDER BY trasys.ai.cost_usd DESC
LIMIT  50

Find errors for a specific user:

SELECT trace_id, http.route, http.status_code, time
FROM   spans
WHERE  user_id = 'usr_abc123'
  AND  http.status_code >= 500
  AND  time > now() - 7d

Data sources

SourceContains
spansAll HTTP, database, gRPC, and queue spans
ai_spansAI provider calls — tokens, cost, model, finish reason
logsStructured log records
metricsCounter, gauge, and histogram data points
health_checksHealth check results over time

Filtering (WHERE)

OperatorDescription
=, !=Exact match
>, >=, <, <=Numeric comparison
LIKE 'pattern%'Prefix or pattern match
IN ('a', 'b', 'c')Set membership
IS NULL, IS NOT NULLPresence check
AND, OR, NOTBoolean logic

Time filtering

WHERE time > now() - 30m      -- last 30 minutes
WHERE time > now() - 6h       -- last 6 hours
WHERE time > now() - 7d       -- last 7 days
WHERE time BETWEEN '2024-01-01' AND '2024-01-31'

Field reference

Spans

FieldTypeDescription
trace_idstringW3C trace ID
span_idstringSpan ID
servicestringService name
http.routestringNormalized route, e.g. /users/:id
http.methodstringGET, POST, etc.
http.status_codenumberHTTP status code
http.duration_msnumberRequest duration in milliseconds
db.systemstringpostgresql, mongodb, etc.
db.statementstringSanitized SQL or query
db.slow_querybooleantrue when above slow threshold
user_idstringFrom trasys.user.id
session_idstringFrom trasys.session.id
environmentstringproduction, staging, etc.
timetimestampSpan end time

AI spans

FieldTypeDescription
gen_ai.systemstringopenai, anthropic, gemini, etc.
gen_ai.request.modelstringModel name
gen_ai.usage.input_tokensnumberPrompt token count
gen_ai.usage.output_tokensnumberCompletion token count
gen_ai.response.finish_reasonsstringstop, length, tool_calls
trasys.ai.cost_usdnumberEstimated cost in USD

Logs

FieldTypeDescription
messagestringLog message
severitystringdebug, info, warn, error, fatal
trace_idstringCorrelated trace
user_idstringCorrelated user
error.typestringError class name
error.messagestringError message

Aggregations

SELECT
  http.route,
  COUNT(*)                         AS request_count,
  AVG(http.duration_ms)            AS avg_latency,
  PERCENTILE(http.duration_ms, 95) AS p95_latency,
  SUM(CASE WHEN http.status_code >= 500 THEN 1 ELSE 0 END) AS errors
FROM   spans
WHERE  service = 'api-gateway'
  AND  time > now() - 1h
GROUP BY http.route
ORDER BY errors DESC

Saved queries

Queries can be saved in the dashboard and referenced in alert conditions by their slug:

error_rate("payment-service") > 0.05

This references the built-in error_rate aggregation function. Custom saved queries can be referenced similarly once defined.


The full TQL reference — all built-in functions, aggregation operators, and provider-specific fields — is maintained separately and will be expanded as TQL evolves.

On this page