Skip to content

Conversation

@sridhar-5
Copy link

@sridhar-5 sridhar-5 commented Jun 21, 2025

closes #4695

  • Introduced a new logging namespace - slowQuery
  • Added a new Logger Option - slowQueryThreshold [ Configurable ] - Default 200ms.
  • Logging all the Queries that takes beyond the threshold of >=200 ms if slowQuery or query is added in debugMode options.
  • Modified the log level to 'warning` for the slow queries.
  • Modified the meta data color of slow queries to yellow

This is my first contribution to Mikro ORM, i do not have a lot of experience with typescript either, i tried to do this while learning the same. So please feel free to let me know if i missed some nuances, i'm happy to address the feedback.

Added logs for slow queries that exceed
the configurable threshold (default 200ms). Slow queries are logged
with 'slowQuery' namespace and highlighted with yellow metadata.

closes mikro-orm#4695
@sridhar-5 sridhar-5 force-pushed the slow-query-logging branch from a604e3a to 8c75e78 Compare June 22, 2025 06:09
@sridhar-5 sridhar-5 force-pushed the slow-query-logging branch from 8c75e78 to 8a83bee Compare June 22, 2025 06:22
@sridhar-5
Copy link
Author

sridhar-5 commented Jun 23, 2025

@B4nan - could i please get a review on this ?

@codecov
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.74%. Comparing base (fb4f889) to head (8a83bee).
Report is 24 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #6725    +/-   ##
========================================
  Coverage   99.74%   99.74%            
========================================
  Files         267      267            
  Lines       19755    19782    +27     
  Branches     4327     4679   +352     
========================================
+ Hits        19704    19731    +27     
  Misses         51       51            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@B4nan
Copy link
Member

B4nan commented Jun 25, 2025

thanks! so how is this supposed to work in production when logs are disabled? we need a way to log stuff to the file system specifically for the slow query logs (regardless of how the default logging is set up), your PR only adds the new logger namespace. you can already set up a file logger but that means all logs would go there, maybe we could allow having multiple loggers, and set them up with different namespaces. slow query logging could be enabled automatically this way (logging to a txt file only the slow queries, regardless of the debug ORM option)

@sridhar-5
Copy link
Author

sridhar-5 commented Jun 25, 2025

Oh! Okay, so we want the slowQuery logs to appear even with the debug logs are disabled in the production. Got it. I can make those changes. Thanks for the feedback @B4nan .

@B4nan
Copy link
Member

B4nan commented Jul 1, 2025

I am not sure if this should be enabled by default, but to me this is a production feature, and in production you don't usually enable query logging, since it would slow down the app and pollute the app logs like crazy. I'd say the best way to support this would be allowing multiple loggers, they can log to different places (console, file, some 3rd party service), based on different settings (log levels). Alternatively, only the slow query logs could be treated as a special case, but the former approach sounds cleaner. I haven't been thinking much about this, also not sure how it works in other ORMs, let's first agree on how this could look like before spending more time with implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Log long running queries

2 participants