View as Markdown
Logfire icon

Logfire ACTION

Run SQL Query

Executes an arbitrary SQL query against Logfire's records (unified logs + traces, one row per span) or metrics tables and returns the results. Use this for any analysis, search, or aggregation over your telemetry — recent activity, error hunting, latency analysis, counts, etc. To discover what columns are available before writing a query, run SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'records' (or 'metrics') with this same tool — there is no separate schema-discovery tool. Useful columns on records include start_timestamp, span_name, message, level, service_name, duration, is_exception, exception_type, and exception_message. Example — find exceptions: SELECT span_name, exception_type, exception_message FROM records WHERE is_exception = true ORDER BY start_timestamp DESC. Example — count by level: SELECT level, count(*) AS n FROM records GROUP BY level ORDER BY n DESC. After using Record Log Entry to write data, use this tool to confirm what was recorded. See the SQL reference and query API docs.
  • Action
  • Read only
  • API key
  • SDK
  • MCP

IMPLEMENTATION

Call this tool

Connect a user's Logfire account once, then configure and run Run SQL Query from your backend or agent.

import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "logfire-run-sql-query",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    logfire: { authProvisionId: "apn_xxxxxxx" },
    sql: "SQL Query",
    minTimestamp: "Min Timestamp",
  },
})

console.log(result)

SCHEMA

Inputs

Pipedream supplies the connected account. Your application provides the operation-specific values below. Dynamic inputs are resolved against that user's account.

Run SQL Query inputs
Property Type Description
sql SQL Query string
The SQL query to run, e.g. SELECT start_timestamp, message, level FROM records ORDER BY start_timestamp DESC LIMIT 20.
Required
minTimestamp Min Timestamp string
ISO 8601 timestamp to bound the query's start time, e.g. 2025-01-15T00:00:00Z. Defaults to 24 hours before now if not provided.
Optional
maxTimestamp Max Timestamp string
ISO 8601 timestamp to bound the query's end time, e.g. 2025-01-15T23:59:59Z. Defaults to now if not provided.
Optional
limit Limit integer
Maximum number of rows to return. Defaults to 100, max 10000.
Optional

REFERENCE

Tool details

Behavior hints are published with the component in the Pipedream registry and surface as MCP tool annotations, so an agent can reason about a tool before it calls it.

Registry key
logfire-run-sql-query
Version
0.0.2
App
Logfire
Authentication
API key
Read-only
Yes
Destructive
No
Open world
Yes