Skip to content

Source Code Mapping

Query Doctor can link every query captured by pg_stat_statements back to the application code that produced it — the source file, line number, HTTP route, and request method. This is powered by SQLCommenter tags that your ORM appends as structured SQL comments.

An SQLCommenter-enabled ORM wraps each query in a comment containing key-value metadata:

/* file='%2Fhome%2Fuser%2Fproject%2Fsrc%2Fusers%2Fservice.ts%3A42%3A5',route='%2Fapi%2Fusers',method='GET',db_driver='drizzle' */
SELECT id, name FROM users WHERE active = true;

When Query Doctor reads pg_stat_statements, its analyzer extracts these tags and displays them all alongside the query in the Live Queries detail view. Every tag is shown as a key-value pair, but the file tag gets special treatment — when present, Query Doctor renders it as a clickable link that opens the exact file and line in your IDE (see Configuring your IDE below).

TagDescription
fileSource file, line, and column (path:line:column)
func_nameEnclosing function/method — edit-stable, omitted for anonymous call sites
routeHTTP route that triggered the query
methodHTTP request method (GET, POST, etc.)
db_driverORM / driver identifier
Custom tagsAny arbitrary key-value pairs you attach

Trace context (OpenTelemetry span and trace IDs) is included automatically when a tracer is active.

The file tag pins a query to a path:line:column captured at the analyzed revision. Line and column numbers drift as code above the call site changes, so mapping captured queries back to source against a different revision can silently misattribute them.

The func_name tag records the enclosing function or method of the call site (e.g. reactionsRepo.findFavorites). A symbol name doesn’t move when lines shift above it, so it’s a stable join key for mapping captured queries to the source methods that produced them — without checking out the exact commit the capture ran against.

The symbol comes from the same build-time stack frame as file, so it carries the same reliability envelope. Integrations capture it when present and fall back to file:line otherwise — minified or bundled production builds may mangle or drop function names, in which case the tag is omitted. (symbol is accepted as an alternate spelling.)

Install a tracking integration for your database driver or ORM:

Once the integration is in place, new queries that hit the database will carry the comment tags. Existing entries in pg_stat_statements won’t have them.

When a query has a file tag, the path is rendered as a clickable link. To have it open directly in your editor, configure the IDE selector:

  1. Open the Live Queries page.
  2. Click the settings icon in the toolbar.
  3. Choose your Preferred IDE.
  4. For JetBrains IDEs, also set the Project path (the local root of your project) so that relative paths resolve correctly.
  • Cursor
  • VS Code

Uses the vscode://file/path:line:column protocol.