adonisjs-server-stats 1.9.0 → 1.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/README.md +23 -14
  2. package/dist/core/config-utils.d.ts +8 -0
  3. package/dist/core/constants.d.ts +4 -0
  4. package/dist/core/dashboard-data-controller.d.ts +16 -0
  5. package/dist/core/dashboard-data-helpers.d.ts +12 -0
  6. package/dist/core/debug-data-controller.d.ts +4 -0
  7. package/dist/core/define-config-helpers.d.ts +25 -0
  8. package/dist/core/feature-detect-helpers.d.ts +36 -0
  9. package/dist/core/formatters-helpers.d.ts +23 -0
  10. package/dist/core/index.js +596 -509
  11. package/dist/core/log-utils-helpers.d.ts +13 -0
  12. package/dist/core/metrics.d.ts +3 -28
  13. package/dist/core/pagination.d.ts +0 -9
  14. package/dist/core/server-stats-controller.d.ts +6 -0
  15. package/dist/core/split-pane.d.ts +18 -0
  16. package/dist/core/trace-utils.d.ts +5 -0
  17. package/dist/core/transmit-helpers.d.ts +7 -0
  18. package/dist/core/types-dashboard.d.ts +178 -0
  19. package/dist/core/types-diagnostics.d.ts +85 -0
  20. package/dist/core/types.d.ts +11 -443
  21. package/dist/react/{CacheSection-xH75hwXu.js → CacheSection-baMZotSn.js} +2 -2
  22. package/dist/react/CacheTab-2cw_rMzj.js +117 -0
  23. package/dist/react/{ConfigSection-D8BO1Ry9.js → ConfigSection-DGgqjAal.js} +1 -1
  24. package/dist/react/{ConfigTab-CcN-tfjv.js → ConfigTab-H3OnYqmK.js} +1 -1
  25. package/dist/react/CustomPaneTab-B6r7ha0u.js +98 -0
  26. package/dist/react/{EmailsSection-BzlsTdPs.js → EmailsSection-C-UZISG-.js} +2 -2
  27. package/dist/react/EmailsTab-DbK4Eobn.js +139 -0
  28. package/dist/react/{EventsSection-CGQWiIdV.js → EventsSection-C7RQW_LY.js} +2 -2
  29. package/dist/react/EventsTab-CfVr7AiM.js +57 -0
  30. package/dist/react/{FilterBar-DQRXpWrb.js → FilterBar-CQ7bD669.js} +15 -15
  31. package/dist/react/{JobsSection-D7AHQmZi.js → JobsSection-CQHNK_Ls.js} +2 -2
  32. package/dist/react/{JobsTab-B3Lfdqed.js → JobsTab-znzf6jzk.js} +54 -42
  33. package/dist/react/{LogsSection-Cly1dpvS.js → LogsSection-Dmm3rE2B.js} +9 -3
  34. package/dist/react/LogsTab-D8unMV5P.js +108 -0
  35. package/dist/react/{OverviewSection-CkBGFEWq.js → OverviewSection-ABP9ueBo.js} +1 -1
  36. package/dist/react/{QueriesSection-CfCpnNUD.js → QueriesSection-CnmSkznA.js} +2 -2
  37. package/dist/react/{QueriesTab-DbBmAqzO.js → QueriesTab-BQzcxEiW.js} +37 -40
  38. package/dist/react/RelatedLogs-3A8RuGKH.js +52 -0
  39. package/dist/react/RequestsSection-kW79_M7k.js +341 -0
  40. package/dist/react/{RoutesSection-CRqF-cNM.js → RoutesSection-BRhxrtjZ.js} +2 -2
  41. package/dist/react/RoutesTab-CpYH5lUw.js +68 -0
  42. package/dist/react/TimelineTab-DjLR35Ce.js +214 -0
  43. package/dist/react/index-CsImORX6.js +1121 -0
  44. package/dist/react/index.js +1 -1
  45. package/dist/react/react/components/{Dashboard/shared → shared}/FilterBar.d.ts +4 -3
  46. package/dist/react/react/components/shared/RelatedLogs.d.ts +7 -0
  47. package/dist/react/react/hooks/useDashboardData.d.ts +4 -8
  48. package/dist/react/style.css +1 -1
  49. package/dist/src/collectors/app_collector.d.ts +0 -8
  50. package/dist/src/collectors/app_collector.js +45 -52
  51. package/dist/src/collectors/auto_detect.d.ts +0 -23
  52. package/dist/src/collectors/auto_detect.js +33 -55
  53. package/dist/src/collectors/db_pool_collector.d.ts +14 -16
  54. package/dist/src/collectors/db_pool_collector.js +72 -57
  55. package/dist/src/collectors/log_collector.d.ts +0 -47
  56. package/dist/src/collectors/log_collector.js +36 -65
  57. package/dist/src/collectors/queue_collector.d.ts +0 -20
  58. package/dist/src/collectors/queue_collector.js +60 -76
  59. package/dist/src/collectors/redis_collector.d.ts +10 -10
  60. package/dist/src/collectors/redis_collector.js +69 -66
  61. package/dist/src/config/deprecation_migration.d.ts +7 -0
  62. package/dist/src/config/deprecation_migration.js +201 -0
  63. package/dist/src/controller/debug_controller.d.ts +1 -1
  64. package/dist/src/controller/debug_controller.js +87 -81
  65. package/dist/src/dashboard/cache_handlers.d.ts +14 -0
  66. package/dist/src/dashboard/cache_handlers.js +52 -0
  67. package/dist/src/dashboard/chart_aggregator.d.ts +0 -7
  68. package/dist/src/dashboard/chart_aggregator.js +68 -50
  69. package/dist/src/dashboard/coalesce_cache.d.ts +25 -0
  70. package/dist/src/dashboard/coalesce_cache.js +47 -0
  71. package/dist/src/dashboard/dashboard_controller.d.ts +11 -37
  72. package/dist/src/dashboard/dashboard_controller.js +52 -532
  73. package/dist/src/dashboard/dashboard_page_assets.d.ts +17 -0
  74. package/dist/src/dashboard/dashboard_page_assets.js +51 -0
  75. package/dist/src/dashboard/dashboard_store.d.ts +19 -217
  76. package/dist/src/dashboard/dashboard_store.js +115 -1069
  77. package/dist/src/dashboard/dashboard_types.d.ts +83 -0
  78. package/dist/src/dashboard/dashboard_types.js +4 -0
  79. package/dist/src/dashboard/detail_queries.d.ts +19 -0
  80. package/dist/src/dashboard/detail_queries.js +98 -0
  81. package/dist/src/dashboard/email_event_builder.d.ts +8 -0
  82. package/dist/src/dashboard/email_event_builder.js +65 -0
  83. package/dist/src/dashboard/explain_query.d.ts +8 -0
  84. package/dist/src/dashboard/explain_query.js +22 -0
  85. package/dist/src/dashboard/filter_handlers.d.ts +23 -0
  86. package/dist/src/dashboard/filter_handlers.js +56 -0
  87. package/dist/src/dashboard/filtered_queries.d.ts +15 -0
  88. package/dist/src/dashboard/filtered_queries.js +155 -0
  89. package/dist/src/dashboard/flush_manager.d.ts +25 -0
  90. package/dist/src/dashboard/flush_manager.js +107 -0
  91. package/dist/src/dashboard/format_helpers.d.ts +126 -0
  92. package/dist/src/dashboard/format_helpers.js +140 -0
  93. package/dist/src/dashboard/inspector_manager.d.ts +36 -0
  94. package/dist/src/dashboard/inspector_manager.js +102 -0
  95. package/dist/src/dashboard/integrations/config_inspector.js +11 -13
  96. package/dist/src/dashboard/integrations/queue_inspector.d.ts +3 -3
  97. package/dist/src/dashboard/integrations/queue_inspector.js +13 -10
  98. package/dist/src/dashboard/jobs_handlers.d.ts +14 -0
  99. package/dist/src/dashboard/jobs_handlers.js +61 -0
  100. package/dist/src/dashboard/knex_factory.d.ts +18 -0
  101. package/dist/src/dashboard/knex_factory.js +91 -0
  102. package/dist/src/dashboard/migrator.js +30 -153
  103. package/dist/src/dashboard/migrator_tables.d.ts +19 -0
  104. package/dist/src/dashboard/migrator_tables.js +153 -0
  105. package/dist/src/dashboard/overview_queries.d.ts +66 -0
  106. package/dist/src/dashboard/overview_queries.js +155 -0
  107. package/dist/src/dashboard/overview_query_runners.d.ts +25 -0
  108. package/dist/src/dashboard/overview_query_runners.js +84 -0
  109. package/dist/src/dashboard/overview_store_queries.d.ts +40 -0
  110. package/dist/src/dashboard/overview_store_queries.js +69 -0
  111. package/dist/src/dashboard/paginate_helper.d.ts +12 -0
  112. package/dist/src/dashboard/paginate_helper.js +33 -0
  113. package/dist/src/dashboard/query_explain_handler.d.ts +10 -0
  114. package/dist/src/dashboard/query_explain_handler.js +80 -0
  115. package/dist/src/dashboard/read_queries.d.ts +32 -0
  116. package/dist/src/dashboard/read_queries.js +107 -0
  117. package/dist/src/dashboard/saved_filter_queries.d.ts +10 -0
  118. package/dist/src/dashboard/saved_filter_queries.js +24 -0
  119. package/dist/src/dashboard/storage_stats.d.ts +41 -0
  120. package/dist/src/dashboard/storage_stats.js +81 -0
  121. package/dist/src/dashboard/write_queue.d.ts +106 -0
  122. package/dist/src/dashboard/write_queue.js +225 -0
  123. package/dist/src/data/data_access.d.ts +6 -36
  124. package/dist/src/data/data_access.js +43 -188
  125. package/dist/src/data/data_access_helpers.d.ts +130 -0
  126. package/dist/src/data/data_access_helpers.js +212 -0
  127. package/dist/src/debug/debug_store.js +37 -32
  128. package/dist/src/debug/email_collector.d.ts +1 -10
  129. package/dist/src/debug/email_collector.js +78 -81
  130. package/dist/src/debug/event_collector.d.ts +0 -9
  131. package/dist/src/debug/event_collector.js +79 -62
  132. package/dist/src/debug/query_collector.js +23 -19
  133. package/dist/src/debug/route_inspector.d.ts +1 -5
  134. package/dist/src/debug/route_inspector.js +50 -51
  135. package/dist/src/debug/trace_collector.d.ts +10 -2
  136. package/dist/src/debug/trace_collector.js +23 -16
  137. package/dist/src/debug/types.d.ts +5 -1
  138. package/dist/src/define_config.d.ts +0 -65
  139. package/dist/src/define_config.js +93 -333
  140. package/dist/src/edge/client/dashboard.js +2 -2
  141. package/dist/src/edge/client/debug-panel-deferred.js +1 -1
  142. package/dist/src/edge/client/stats-bar.js +1 -1
  143. package/dist/src/edge/client-vue/dashboard.js +5 -5
  144. package/dist/src/edge/client-vue/debug-panel-deferred.js +3 -3
  145. package/dist/src/edge/client-vue/stats-bar.js +3 -3
  146. package/dist/src/edge/plugin.d.ts +0 -16
  147. package/dist/src/edge/plugin.js +57 -64
  148. package/dist/src/engine/request_metrics.d.ts +1 -0
  149. package/dist/src/engine/request_metrics.js +32 -42
  150. package/dist/src/middleware/request_tracking_middleware.d.ts +3 -8
  151. package/dist/src/middleware/request_tracking_middleware.js +65 -91
  152. package/dist/src/provider/auth_middleware_detector.d.ts +16 -0
  153. package/dist/src/provider/auth_middleware_detector.js +97 -0
  154. package/dist/src/provider/boot_helpers.d.ts +20 -0
  155. package/dist/src/provider/boot_helpers.js +91 -0
  156. package/dist/src/provider/boot_initializer.d.ts +28 -0
  157. package/dist/src/provider/boot_initializer.js +35 -0
  158. package/dist/src/provider/dashboard_init.d.ts +30 -0
  159. package/dist/src/provider/dashboard_init.js +138 -0
  160. package/dist/src/provider/dashboard_setup.d.ts +25 -0
  161. package/dist/src/provider/dashboard_setup.js +78 -0
  162. package/dist/src/provider/diagnostics.d.ts +134 -0
  163. package/dist/src/provider/diagnostics.js +127 -0
  164. package/dist/src/provider/email_bridge.d.ts +43 -0
  165. package/dist/src/provider/email_bridge.js +80 -0
  166. package/dist/src/provider/email_helpers.d.ts +13 -0
  167. package/dist/src/provider/email_helpers.js +68 -0
  168. package/dist/src/provider/pino_hook.d.ts +17 -0
  169. package/dist/src/provider/pino_hook.js +35 -0
  170. package/dist/src/provider/provider_helpers_extra.d.ts +47 -0
  171. package/dist/src/provider/provider_helpers_extra.js +177 -0
  172. package/dist/src/provider/server_stats_provider.d.ts +39 -85
  173. package/dist/src/provider/server_stats_provider.js +131 -936
  174. package/dist/src/provider/shutdown_helpers.d.ts +43 -0
  175. package/dist/src/provider/shutdown_helpers.js +70 -0
  176. package/dist/src/provider/toolbar_setup.d.ts +57 -0
  177. package/dist/src/provider/toolbar_setup.js +141 -0
  178. package/dist/src/routes/dashboard_routes.d.ts +14 -0
  179. package/dist/src/routes/dashboard_routes.js +197 -0
  180. package/dist/src/routes/debug_routes.d.ts +14 -0
  181. package/dist/src/routes/debug_routes.js +101 -0
  182. package/dist/src/routes/register_routes.d.ts +0 -78
  183. package/dist/src/routes/register_routes.js +22 -347
  184. package/dist/src/routes/stats_routes.d.ts +5 -0
  185. package/dist/src/routes/stats_routes.js +14 -0
  186. package/dist/src/styles/components.css +177 -0
  187. package/dist/src/styles/dashboard.css +8 -90
  188. package/dist/src/styles/debug-panel.css +10 -31
  189. package/dist/src/types.d.ts +306 -15
  190. package/dist/vue/{CacheSection-Cx-hj09X.js → CacheSection-ITqvpfH5.js} +1 -1
  191. package/dist/vue/{ConfigSection-CMXyryf6.js → ConfigSection-DTn3GslE.js} +1 -1
  192. package/dist/vue/{EmailsSection-DgKl9xGT.js → EmailsSection-DtLJ4XoS.js} +1 -1
  193. package/dist/vue/{EventsSection-BNMCAim1.js → EventsSection-BOYYz0Ty.js} +1 -1
  194. package/dist/vue/{JobsSection-CCMgMlxd.js → JobsSection-BazTxcJL.js} +1 -1
  195. package/dist/vue/{LogsSection-CvOnTxUu.js → LogsSection-D55PjTKX.js} +9 -3
  196. package/dist/vue/{LogsTab-Bg3o0Mm6.js → LogsTab-47zEK7jL.js} +4 -1
  197. package/dist/vue/{OverviewSection-CHgaKtUR.js → OverviewSection-1uBKo-Tu.js} +1 -1
  198. package/dist/vue/{QueriesSection-BnHRD98z.js → QueriesSection-rpoZ4ogd.js} +1 -1
  199. package/dist/vue/RelatedLogs.vue_vue_type_script_setup_true_lang-CB2_TzYW.js +84 -0
  200. package/dist/vue/RequestsSection-x7LvT0MC.js +401 -0
  201. package/dist/vue/{RoutesSection-BrceOcKQ.js → RoutesSection-CCD0zZqQ.js} +1 -1
  202. package/dist/vue/TimelineTab-zj5Z5OdT.js +338 -0
  203. package/dist/vue/components/Dashboard/sections/RequestsSection.vue.d.ts +4 -0
  204. package/dist/vue/components/DebugPanel/tabs/TimelineTab.vue.d.ts +4 -0
  205. package/dist/vue/components/{Dashboard/sections/TimelineSection.vue.d.ts → shared/RelatedLogs.vue.d.ts} +5 -6
  206. package/dist/vue/composables/useDashboardData.d.ts +12 -23
  207. package/dist/vue/index-C8MxnS7Q.js +1232 -0
  208. package/dist/vue/index.js +1 -1
  209. package/dist/vue/style.css +1 -1
  210. package/package.json +1 -1
  211. package/dist/react/CacheTab-DYmsZJJ1.js +0 -123
  212. package/dist/react/CustomPaneTab-D7_o3Ec6.js +0 -104
  213. package/dist/react/EmailsTab-Uh2CQY3o.js +0 -153
  214. package/dist/react/EventsTab-CC6DQzEm.js +0 -63
  215. package/dist/react/LogsTab-BbYK-iyh.js +0 -103
  216. package/dist/react/RequestsSection-Cb5a6MlT.js +0 -209
  217. package/dist/react/RoutesTab-Bwreij3e.js +0 -74
  218. package/dist/react/TimelineSection-B2y06kRE.js +0 -158
  219. package/dist/react/TimelineTab-6hthfdBB.js +0 -193
  220. package/dist/react/WaterfallChart-Cj73WdfM.js +0 -100
  221. package/dist/react/index-CecA4IdQ.js +0 -1075
  222. package/dist/react/react/components/Dashboard/sections/TimelineSection.d.ts +0 -8
  223. package/dist/vue/RequestsSection-B-uSlM0f.js +0 -243
  224. package/dist/vue/TimelineSection-CfvnA2Oo.js +0 -186
  225. package/dist/vue/TimelineTab-Db6lKKsD.js +0 -250
  226. package/dist/vue/WaterfallChart.vue_vue_type_script_setup_true_lang-tZ13cNj1.js +0 -118
  227. package/dist/vue/index-oLxS08vN.js +0 -1235
@@ -1,46 +1,64 @@
1
1
  import { log } from '../utils/logger.js';
2
+ /** Resolve middleware items from a MiddlewareStore or array. */
3
+ function resolveMiddlewareItems(middleware) {
4
+ if (!middleware)
5
+ return [];
6
+ if (Array.isArray(middleware))
7
+ return middleware;
8
+ if (typeof middleware.all === 'function')
9
+ return middleware.all();
10
+ return [];
11
+ }
12
+ /** Resolve a single middleware item to its display name. */
13
+ function resolveMiddlewareName(m) {
14
+ if (typeof m === 'string')
15
+ return m;
16
+ if (typeof m === 'function')
17
+ return m.name || null;
18
+ if (m?.name) {
19
+ const args = m.args?.length ? `(${JSON.stringify(m.args).slice(1, -1)})` : '';
20
+ return m.name + args;
21
+ }
22
+ return null;
23
+ }
2
24
  /**
3
25
  * Reads the router's route table at boot time and caches it.
4
- * Static data computed once — routes don't change after boot.
5
26
  */
6
27
  export class RouteInspector {
7
28
  routes = [];
8
- /**
9
- * Inspect the router and cache all routes.
10
- * Call this in the provider's `ready()` hook.
11
- */
12
29
  inspect(router) {
13
30
  try {
14
- // AdonisJS router exposes routes via toJSON()
15
31
  const routeData = router.toJSON();
16
32
  this.routes = [];
17
- // routeData is a map of domains -> routes
18
33
  for (const domain in routeData) {
19
34
  const domainRoutes = routeData[domain];
20
35
  if (!Array.isArray(domainRoutes))
21
36
  continue;
22
- for (const route of domainRoutes) {
23
- const methods = Array.isArray(route.methods)
24
- ? route.methods.filter((m) => m !== 'HEAD')
25
- : [];
26
- const handler = this.resolveHandler(route.handler);
27
- const middlewareList = this.resolveMiddleware(route.middleware);
28
- for (const method of methods) {
29
- this.routes.push({
30
- method,
31
- pattern: route.pattern || '/',
32
- name: route.name || null,
33
- handler,
34
- middleware: middlewareList,
35
- });
36
- }
37
- }
37
+ this.#processDomainRoutes(domainRoutes);
38
38
  }
39
39
  }
40
40
  catch (err) {
41
41
  log.warn(`route inspector: could not read routes — ${err?.message || 'unknown error'}`);
42
42
  }
43
43
  }
44
+ #processDomainRoutes(domainRoutes) {
45
+ for (const route of domainRoutes) {
46
+ const methods = Array.isArray(route.methods)
47
+ ? route.methods.filter((m) => m !== 'HEAD')
48
+ : [];
49
+ const handler = this.resolveHandler(route.handler);
50
+ const middlewareList = this.resolveMiddleware(route.middleware);
51
+ for (const method of methods) {
52
+ this.routes.push({
53
+ method,
54
+ pattern: route.pattern || '/',
55
+ name: route.name || null,
56
+ handler,
57
+ middleware: middlewareList,
58
+ });
59
+ }
60
+ }
61
+ }
44
62
  resolveHandler(handler) {
45
63
  if (!handler)
46
64
  return 'unknown';
@@ -48,44 +66,25 @@ export class RouteInspector {
48
66
  return handler;
49
67
  if (typeof handler === 'function')
50
68
  return handler.name || 'closure';
51
- // Lazy import handler
69
+ return this.#resolveObjectHandler(handler);
70
+ }
71
+ #resolveObjectHandler(handler) {
52
72
  if (handler.reference) {
53
73
  const ref = handler.reference;
54
74
  if (typeof ref === 'string')
55
75
  return ref;
56
- if (Array.isArray(ref) && ref.length >= 2) {
76
+ if (Array.isArray(ref) && ref.length >= 2)
57
77
  return `${ref[0]}#${ref[1]}`;
58
- }
59
78
  }
60
- // Handle object with name
61
- if (handler.name)
62
- return handler.name;
63
- return 'unknown';
79
+ return handler.name || 'unknown';
64
80
  }
65
81
  resolveMiddleware(middleware) {
66
- if (!middleware)
67
- return [];
68
- // AdonisJS v6 middleware is a Middleware instance from @poppinss/middleware.
69
- // Call .all() to get the Set of middleware items.
70
- const items = !Array.isArray(middleware) && typeof middleware.all === 'function'
71
- ? middleware.all()
72
- : Array.isArray(middleware)
73
- ? middleware
74
- : [];
82
+ const items = resolveMiddlewareItems(middleware);
75
83
  const result = [];
76
84
  for (const m of items) {
77
- if (typeof m === 'string') {
78
- result.push(m);
79
- }
80
- else if (typeof m === 'function') {
81
- if (m.name)
82
- result.push(m.name);
83
- }
84
- else if (m?.name) {
85
- const args = m.args?.length ? `(${JSON.stringify(m.args).slice(1, -1)})` : '';
86
- result.push(m.name + args);
87
- }
88
- // Skip unnamed global middleware (router.use lazy imports) — same for every route
85
+ const name = resolveMiddlewareName(m);
86
+ if (name)
87
+ result.push(name);
89
88
  }
90
89
  return result;
91
90
  }
@@ -1,4 +1,12 @@
1
1
  import type { TraceSpan, TraceRecord, Emitter } from './types.js';
2
+ /** Input for adding a span to the current trace. */
3
+ export interface AddSpanInput {
4
+ label: string;
5
+ category: TraceSpan['category'];
6
+ startOffset: number;
7
+ duration: number;
8
+ metadata?: Record<string, unknown>;
9
+ }
2
10
  /**
3
11
  * Wrap an async function in a traced span.
4
12
  *
@@ -32,9 +40,9 @@ export declare class TraceCollector {
32
40
  /** Start a new trace context for an HTTP request. */
33
41
  startTrace(callback: () => Promise<void>): Promise<void>;
34
42
  /** Finish the current trace and save it to the ring buffer. Returns the record, or null if no context. */
35
- finishTrace(method: string, url: string, statusCode: number): TraceRecord | null;
43
+ finishTrace(method: string, url: string, statusCode: number, httpRequestId?: string): TraceRecord | null;
36
44
  /** Add a span to the current trace (if active). */
37
- addSpan(label: string, category: TraceSpan['category'], startOffset: number, duration: number, metadata?: Record<string, unknown>): void;
45
+ addSpan(input: AddSpanInput): void;
38
46
  /** Wrap a function in a traced span with automatic nesting. */
39
47
  span<T>(label: string, category: TraceSpan['category'], fn: () => Promise<T>): Promise<T>;
40
48
  /** Hook into db:query events and console.warn to auto-create spans. */
@@ -5,7 +5,7 @@ import { RingBuffer } from './ring_buffer.js';
5
5
  /**
6
6
  * Module-level singleton reference for the `trace()` helper.
7
7
  */
8
- let globalTraceCollector = null;
8
+ const globalRef = { current: null };
9
9
  /**
10
10
  * Wrap an async function in a traced span.
11
11
  *
@@ -22,9 +22,9 @@ let globalTraceCollector = null;
22
22
  * ```
23
23
  */
24
24
  export async function trace(label, fn) {
25
- if (!globalTraceCollector)
25
+ if (!globalRef.current)
26
26
  return fn();
27
- return globalTraceCollector.span(label, 'custom', fn);
27
+ return globalRef.current.span(label, 'custom', fn);
28
28
  }
29
29
  /**
30
30
  * Collects per-request traces using AsyncLocalStorage.
@@ -41,7 +41,7 @@ export class TraceCollector {
41
41
  originalConsoleWarn = null;
42
42
  constructor(maxTraces = 200) {
43
43
  this.buffer = new RingBuffer(maxTraces);
44
- globalTraceCollector = this; // eslint-disable-line @typescript-eslint/no-this-alias
44
+ globalRef.current = this;
45
45
  }
46
46
  /** Start a new trace context for an HTTP request. */
47
47
  startTrace(callback) {
@@ -55,7 +55,7 @@ export class TraceCollector {
55
55
  return this.als.run(ctx, callback);
56
56
  }
57
57
  /** Finish the current trace and save it to the ring buffer. Returns the record, or null if no context. */
58
- finishTrace(method, url, statusCode) {
58
+ finishTrace(method, url, statusCode, httpRequestId) {
59
59
  const ctx = this.als.getStore();
60
60
  if (!ctx)
61
61
  return null;
@@ -70,12 +70,13 @@ export class TraceCollector {
70
70
  spans: ctx.spans,
71
71
  warnings: ctx.warnings,
72
72
  timestamp: Date.now(),
73
+ httpRequestId: httpRequestId ?? undefined,
73
74
  };
74
75
  this.buffer.push(record);
75
76
  return record;
76
77
  }
77
78
  /** Add a span to the current trace (if active). */
78
- addSpan(label, category, startOffset, duration, metadata) {
79
+ addSpan(input) {
79
80
  const ctx = this.als.getStore();
80
81
  if (!ctx)
81
82
  return;
@@ -84,11 +85,11 @@ export class TraceCollector {
84
85
  ctx.spans.push({
85
86
  id: String(ctx.nextSpanId++),
86
87
  parentId: ctx.currentSpanId,
87
- label,
88
- category,
89
- startOffset: round(startOffset),
90
- duration: round(duration),
91
- metadata,
88
+ label: input.label,
89
+ category: input.category,
90
+ startOffset: round(input.startOffset),
91
+ duration: round(input.duration),
92
+ metadata: input.metadata,
92
93
  });
93
94
  }
94
95
  /** Wrap a function in a traced span with automatic nesting. */
@@ -130,10 +131,16 @@ export class TraceCollector {
130
131
  ? data.duration[0] * 1e3 + data.duration[1] / 1e6
131
132
  : 0;
132
133
  const offset = performance.now() - ctx.requestStart - duration;
133
- this.addSpan(data.sql || 'query', 'db', offset, duration, {
134
- method: data.method,
135
- model: data.model,
136
- connection: data.connection,
134
+ this.addSpan({
135
+ label: data.sql || 'query',
136
+ category: 'db',
137
+ startOffset: offset,
138
+ duration,
139
+ metadata: {
140
+ method: data.method,
141
+ model: data.model,
142
+ connection: data.connection,
143
+ },
137
144
  });
138
145
  };
139
146
  emitter.on('db:query', this.dbHandler);
@@ -159,7 +166,7 @@ export class TraceCollector {
159
166
  this.dbHandler = null;
160
167
  this.emitter = null;
161
168
  this.originalConsoleWarn = null;
162
- globalTraceCollector = null;
169
+ globalRef.current = null;
163
170
  }
164
171
  getTraces() {
165
172
  return this.buffer.toArray().reverse();
@@ -1,5 +1,5 @@
1
1
  /** Callback type for emitter event handlers. */
2
- export type EmitterHandler = (...args: any[]) => void;
2
+ export type EmitterHandler = (...args: unknown[]) => void;
3
3
  /**
4
4
  * Minimal interface for the AdonisJS event emitter.
5
5
  *
@@ -246,6 +246,10 @@ export interface TraceRecord {
246
246
  spans: TraceSpan[];
247
247
  /** Warnings captured via `console.warn` during this request. */
248
248
  warnings: string[];
249
+ /** Log entries correlated to this request. */
250
+ logs?: Record<string, unknown>[];
251
+ /** Unique HTTP request identifier used for log correlation. */
252
+ httpRequestId?: string;
249
253
  /** Unix timestamp in **milliseconds** when the request started. */
250
254
  timestamp: number;
251
255
  }
@@ -1,67 +1,2 @@
1
1
  import type { ResolvedServerStatsConfig, ServerStatsConfig } from './types.js';
2
- /**
3
- * Define the server stats configuration with full type safety.
4
- *
5
- * All top-level fields are optional. Sensible defaults are applied
6
- * for any omitted fields:
7
- *
8
- * | Field | Default |
9
- * |---------------|--------------------------------|
10
- * | `intervalMs` | `3000` |
11
- * | `transport` | `'transmit'` |
12
- * | `channelName` | `'admin/server-stats'` |
13
- * | `endpoint` | `'/admin/api/server-stats'` |
14
- * | `collectors` | `'auto'` |
15
- * | `skipInTest` | `true` |
16
- *
17
- * New simplified aliases (Phase 1) are also supported. When both the
18
- * old name and its alias are provided, the **new name takes precedence**.
19
- *
20
- * | Alias | Resolves to |
21
- * |------------------|------------------|
22
- * | `pollInterval` | `intervalMs` |
23
- * | `realtime` | `transport` |
24
- * | `statsEndpoint` | `endpoint` |
25
- * | `authorize` | `shouldShow` |
26
- * | `toolbar` | `devToolbar` |
27
- * | `dashboard` | `devToolbar` |
28
- * | `advanced` | various |
29
- *
30
- * This is the main entry point for configuring `adonisjs-server-stats`.
31
- * Call it in `config/server_stats.ts` and export the result as default.
32
- *
33
- * @example
34
- * ```ts
35
- * // config/server_stats.ts — minimal (all defaults)
36
- * import { defineConfig } from 'adonisjs-server-stats'
37
- *
38
- * export default defineConfig({})
39
- * ```
40
- *
41
- * @example
42
- * ```ts
43
- * // config/server_stats.ts — explicit collectors
44
- * import { defineConfig } from 'adonisjs-server-stats'
45
- * import { processCollector, httpCollector } from 'adonisjs-server-stats/collectors'
46
- *
47
- * export default defineConfig({
48
- * intervalMs: 3000,
49
- * transport: 'transmit',
50
- * collectors: [processCollector(), httpCollector()],
51
- * })
52
- * ```
53
- *
54
- * @example
55
- * ```ts
56
- * // config/server_stats.ts — new simplified aliases
57
- * import { defineConfig } from 'adonisjs-server-stats'
58
- *
59
- * export default defineConfig({
60
- * pollInterval: 3000,
61
- * realtime: true,
62
- * toolbar: true,
63
- * dashboard: true,
64
- * })
65
- * ```
66
- */
67
2
  export declare function defineConfig(config: ServerStatsConfig): ResolvedServerStatsConfig;