<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno" -->

---
title: Tracing query performance with Knex.js | daily.dev
description: A short code snippet shows how to trace and measure Knex.js query performance using Node's native perf_hooks API instead of relying on Knex's query and...
canonical: https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Tracing query performance with Knex.js | daily.dev
og:description: A short code snippet shows how to trace and measure Knex.js query performance using Node's native perf_hooks API instead of relying on Knex's query and...
og:url: https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno
og:image: https://api.daily.dev/og/posts/r1NSSTKnO.png
og:image:alt: Tracing query performance with Knex.js
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracing query performance with Knex.js

**[Yagiz Nizipli](https://daily.dev/sources/yagiz)** · 1 min read · 0 upvotes · 0 comments

## Summary

A short code snippet shows how to trace and measure Knex.js query performance using Node's native perf_hooks API instead of relying on Knex's query and query-response events alone. It sets performance marks on query start and end, then measures and logs the duration and SQL of each query via a PerformanceObserver.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.yagiz.co/tracing-query-performance-with-knex-js>

## Questions this post answers

### How can I measure the execution time of individual Knex.js queries in Node.js?

Use Node's built-in perf_hooks module to mark and measure query timing instead of manually timing with Date.now(). Listen to Knex's query and query-response events on the underlying database instance, call performance.mark() with the query's unique __knexQueryUid on start and end, then use performance.measure() with the SQL string as the label. A PerformanceObserver logs each measured entry's duration and SQL to the console.

_For teams debugging slow SQL in Node services, daily.dev surfaces practical query-tracing techniques like this one._

## Similar posts on daily.dev

- [OpenTelemetry tutorial for Node.js: traces and metrics from scratch](https://daily.dev/posts/opentelemetry-tutorial-for-node-js-traces-and-metrics-from-scratch-lyccljggd) · Flavio Copes · 2 upvotes · 0 comments
- [Monitoring Node.js Express Application Performance with AppSignal](https://daily.dev/posts/monitoring-node-js-express-application-performance-with-appsignal-56vwr9jtp) · AppSignal · 1 upvotes · 0 comments
- [There's better ways than Monkey-Patching: A Path to Node.js Observability with Tracing Channels](https://daily.dev/posts/there-s-better-ways-than-monkey-patching-a-path-to-node-js-observability-with-tracing-channels-jkolnb9ux) · Sentry Engineering · 7 upvotes · 0 comments
- [JavaScript Event Loop Explained: Queue Tracing and Debugging Guide](https://daily.dev/posts/javascript-event-loop-explained-queue-tracing-and-debugging-guide-sa0thbcrm) · SitePoint · 148 upvotes · 4 comments

---

Tags: [#nodejs](https://daily.dev/tags/nodejs), [#performance](https://daily.dev/tags/performance)

[View this post on daily.dev](https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Tracing query performance with Knex.js","url":"https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno"},"datePublished":"2026-09-13T19:57:32.788Z","dateModified":"2026-10-15T02:22:59.061Z","description":"A short code snippet shows how to trace and measure Knex.js query performance using Node's native perf_hooks API instead of relying on Knex's query and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b97d6c017dfe795fef1b446d155cd517?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b97d6c017dfe795fef1b446d155cd517?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Yagiz Nizipli","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Yagiz Nizipli","logo":"https://media.daily.dev/image/upload/s--9Cscmaqk--/f_auto,q_auto/v1789329427/logos/yagiz?_a=BAMAMicg0","url":"https://daily.dev/sources/yagiz"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"nodejs,performance","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Yagiz Nizipli","item":"https://daily.dev/sources/yagiz"},{"@type":"ListItem","position":3,"name":"Tracing query performance with Knex.js"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/tracing-query-performance-with-knex-js-r1nsstkno#faq","mainEntity":[{"@type":"Question","name":"How can I measure the execution time of individual Knex.js queries in Node.js?","acceptedAnswer":{"@type":"Answer","text":"Use Node's built-in perf_hooks module to mark and measure query timing instead of manually timing with Date.now(). Listen to Knex's query and query-response events on the underlying database instance, call performance.mark() with the query's unique __knexQueryUid on start and end, then use performance.measure() with the SQL string as the label. A PerformanceObserver logs each measured entry's duration and SQL to the console. For teams debugging slow SQL in Node services, daily.dev surfaces practical query-tracing techniques like this one."}}]}
```

