@@ -15,14 +15,35 @@ import { OTLPExporter, type ExporterConfig } from "./export/exporter.ts";
1515import { EntropyChecker } from "./sanitization/entropy-checker.ts" ;
1616import { applyDriverPatches , removeDriverPatches } from "./instrumentation/drivers/index.ts" ;
1717import { QueryAnalyzer , type QueryAnalyzerOptions } from "./analysis/query-analyzer.ts" ;
18- import { SlowQueryMonitor , type SlowQueryOptions , type SlowQueryRecord } from "./analysis/slow-query-monitor.ts" ;
18+ import {
19+ SlowQueryMonitor ,
20+ type SlowQueryOptions ,
21+ type SlowQueryRecord ,
22+ } from "./analysis/slow-query-monitor.ts" ;
1923import { GcMonitor , type GcMonitorOptions , type GcPressureEvent } from "./profiling/gc-monitor.ts" ;
20- import { PoolMonitor , type PoolMonitorOptions , type PoolLike , type PoolExhaustionEvent , type SlowAcquireEvent } from "./profiling/pool-monitor.ts" ;
21- import { createRequestContext , runWithContext , type RequestContext } from "./instrumentation/correlation.ts" ;
22- import { TransactionMonitor , type TransactionMonitorOptions , type TransactionEvent } from "./analysis/transaction-monitor.ts" ;
24+ import {
25+ PoolMonitor ,
26+ type PoolMonitorOptions ,
27+ type PoolLike ,
28+ type PoolExhaustionEvent ,
29+ type SlowAcquireEvent ,
30+ } from "./profiling/pool-monitor.ts" ;
31+ import {
32+ createRequestContext ,
33+ runWithContext ,
34+ type RequestContext ,
35+ } from "./instrumentation/correlation.ts" ;
36+ import {
37+ TransactionMonitor ,
38+ type TransactionMonitorOptions ,
39+ type TransactionEvent ,
40+ } from "./analysis/transaction-monitor.ts" ;
2341import { CacheMonitor , type CacheMonitorOptions } from "./analysis/cache-monitor.ts" ;
2442import { DnsMonitor , type DnsMonitorOptions } from "./instrumentation/dns-monitor.ts" ;
25- import { AdaptiveSampler , type AdaptiveSamplerOptions } from "./instrumentation/adaptive-sampler.ts" ;
43+ import {
44+ AdaptiveSampler ,
45+ type AdaptiveSamplerOptions ,
46+ } from "./instrumentation/adaptive-sampler.ts" ;
2647import { StaticScanner } from "./analysis/static-scanner.ts" ;
2748import { HttpInstrumentation } from "./instrumentation/http.ts" ;
2849import { FsInstrumentation } from "./instrumentation/fs.ts" ;
@@ -672,7 +693,11 @@ export class DiagnosticAgent extends EventEmitter {
672693 traced . traceId ,
673694 ) ;
674695 if ( slow ) {
675- aggregator . record ( "slow-query" , slow . durationMs , slow as unknown as Record < string , unknown > ) ;
696+ aggregator . record (
697+ "slow-query" ,
698+ slow . durationMs ,
699+ slow as unknown as Record < string , unknown > ,
700+ ) ;
676701 this . emit ( "slow-query" , slow ) ;
677702 }
678703 }
@@ -688,7 +713,11 @@ export class DiagnosticAgent extends EventEmitter {
688713 this . transactionMonitor = new TransactionMonitor ( this . transactionMonitorOptions ) ;
689714 this . transactionMonitor . attach ( this . engine ) ;
690715 this . transactionMonitor . on ( "transaction" , ( event : TransactionEvent ) => {
691- aggregator . record ( "transaction" , event . durationMs , event as unknown as Record < string , unknown > ) ;
716+ aggregator . record (
717+ "transaction" ,
718+ event . durationMs ,
719+ event as unknown as Record < string , unknown > ,
720+ ) ;
692721 this . emit ( "transaction" , event ) ;
693722 } ) ;
694723 }
@@ -697,7 +726,11 @@ export class DiagnosticAgent extends EventEmitter {
697726 this . cacheMonitor = new CacheMonitor ( this . cacheMonitorOptions ) ;
698727 this . cacheMonitor . attach ( this . engine ) ;
699728 this . cacheMonitor . on ( "cache-degraded" , ( event ) => {
700- aggregator . record ( "cache-degraded" , event . hitRate , event as unknown as Record < string , unknown > ) ;
729+ aggregator . record (
730+ "cache-degraded" ,
731+ event . hitRate ,
732+ event as unknown as Record < string , unknown > ,
733+ ) ;
701734 this . emit ( "cache-degraded" , event ) ;
702735 } ) ;
703736 }
@@ -727,11 +760,19 @@ export class DiagnosticAgent extends EventEmitter {
727760 if ( this . dnsMonitorOptions !== null ) {
728761 this . dnsMonitor = new DnsMonitor ( this . dnsMonitorOptions ) ;
729762 this . dnsMonitor . on ( "dns" , ( event ) => {
730- this . aggregator ! . record ( "dns" , event . durationMs , event as unknown as Record < string , unknown > ) ;
763+ this . aggregator ! . record (
764+ "dns" ,
765+ event . durationMs ,
766+ event as unknown as Record < string , unknown > ,
767+ ) ;
731768 this . emit ( "dns" , event ) ;
732769 } ) ;
733770 this . dnsMonitor . on ( "slow-dns" , ( event ) => {
734- this . aggregator ! . record ( "slow-dns" , event . durationMs , event as unknown as Record < string , unknown > ) ;
771+ this . aggregator ! . record (
772+ "slow-dns" ,
773+ event . durationMs ,
774+ event as unknown as Record < string , unknown > ,
775+ ) ;
735776 this . emit ( "slow-dns" , event ) ;
736777 } ) ;
737778 this . dnsMonitor . enable ( ) ;
@@ -758,7 +799,11 @@ export class DiagnosticAgent extends EventEmitter {
758799 if ( this . gcMonitorOptions !== null ) {
759800 this . gcMonitor = new GcMonitor ( this . gcMonitorOptions ) ;
760801 this . gcMonitor . on ( "gc-pressure" , ( event : GcPressureEvent ) => {
761- this . aggregator ! . record ( "gc-pressure" , event . totalPauseMs , event as unknown as Record < string , unknown > ) ;
802+ this . aggregator ! . record (
803+ "gc-pressure" ,
804+ event . totalPauseMs ,
805+ event as unknown as Record < string , unknown > ,
806+ ) ;
762807 this . emit ( "gc-pressure" , event ) ;
763808 } ) ;
764809 this . gcMonitor . start ( ) ;
@@ -767,11 +812,19 @@ export class DiagnosticAgent extends EventEmitter {
767812 if ( this . poolMonitorOptions !== null ) {
768813 this . poolMonitor = new PoolMonitor ( this . poolMonitorOptions ) ;
769814 this . poolMonitor . on ( "pool-exhaustion" , ( event : PoolExhaustionEvent ) => {
770- this . aggregator ! . record ( "pool-exhaustion" , event . waitingCount , event as unknown as Record < string , unknown > ) ;
815+ this . aggregator ! . record (
816+ "pool-exhaustion" ,
817+ event . waitingCount ,
818+ event as unknown as Record < string , unknown > ,
819+ ) ;
771820 this . emit ( "pool-exhaustion" , event ) ;
772821 } ) ;
773822 this . poolMonitor . on ( "slow-acquire" , ( event : SlowAcquireEvent ) => {
774- this . aggregator ! . record ( "slow-acquire" , event . waitMs , event as unknown as Record < string , unknown > ) ;
823+ this . aggregator ! . record (
824+ "slow-acquire" ,
825+ event . waitMs ,
826+ event as unknown as Record < string , unknown > ,
827+ ) ;
775828 this . emit ( "slow-acquire" , event ) ;
776829 } ) ;
777830 }
@@ -838,11 +891,26 @@ export class DiagnosticAgent extends EventEmitter {
838891 this . leakMonitor = null ;
839892 this . queryAnalyzer = null ;
840893 this . slowQueryMonitor = null ;
841- if ( this . gcMonitor ) { this . gcMonitor . stop ( ) ; this . gcMonitor = null ; }
842- if ( this . poolMonitor ) { this . poolMonitor . stop ( ) ; this . poolMonitor = null ; }
843- if ( this . transactionMonitor ) { this . transactionMonitor . stop ( ) ; this . transactionMonitor = null ; }
844- if ( this . cacheMonitor ) { this . cacheMonitor . stop ( ) ; this . cacheMonitor = null ; }
845- if ( this . dnsMonitor ) { this . dnsMonitor . disable ( ) ; this . dnsMonitor = null ; }
894+ if ( this . gcMonitor ) {
895+ this . gcMonitor . stop ( ) ;
896+ this . gcMonitor = null ;
897+ }
898+ if ( this . poolMonitor ) {
899+ this . poolMonitor . stop ( ) ;
900+ this . poolMonitor = null ;
901+ }
902+ if ( this . transactionMonitor ) {
903+ this . transactionMonitor . stop ( ) ;
904+ this . transactionMonitor = null ;
905+ }
906+ if ( this . cacheMonitor ) {
907+ this . cacheMonitor . stop ( ) ;
908+ this . cacheMonitor = null ;
909+ }
910+ if ( this . dnsMonitor ) {
911+ this . dnsMonitor . disable ( ) ;
912+ this . dnsMonitor = null ;
913+ }
846914 this . adaptiveSampler = null ;
847915
848916 // Remove debug console listeners added by useConsoleLogger (if any).
@@ -895,15 +963,21 @@ export class DiagnosticAgent extends EventEmitter {
895963 } ) ;
896964 add ( "slow-query" , ( s ) => {
897965 const ev = s as SlowQueryRecord ;
898- console . warn ( `${ prefix } SLOW [${ ev . durationMs . toFixed ( 1 ) } ms > ${ ev . thresholdMs } ms] driver=${ ev . driver } — ${ ev . sanitizedQuery } ` ) ;
966+ console . warn (
967+ `${ prefix } SLOW [${ ev . durationMs . toFixed ( 1 ) } ms > ${ ev . thresholdMs } ms] driver=${ ev . driver } — ${ ev . sanitizedQuery } ` ,
968+ ) ;
899969 } ) ;
900970 add ( "gc-pressure" , ( g ) => {
901971 const ev = g as GcPressureEvent ;
902- console . warn ( `${ prefix } GC [${ ev . totalPauseMs . toFixed ( 1 ) } ms | ${ ev . pausePct . toFixed ( 1 ) } % of ${ ev . windowMs } ms window] ${ ev . gcCount } cycles` ) ;
972+ console . warn (
973+ `${ prefix } GC [${ ev . totalPauseMs . toFixed ( 1 ) } ms | ${ ev . pausePct . toFixed ( 1 ) } % of ${ ev . windowMs } ms window] ${ ev . gcCount } cycles` ,
974+ ) ;
903975 } ) ;
904976 add ( "pool-exhaustion" , ( p ) => {
905977 const ev = p as PoolExhaustionEvent ;
906- console . warn ( `${ prefix } POOL [${ ev . driver } ] waiting=${ ev . waitingCount } idle=${ ev . idleCount } total=${ ev . totalCount } ` ) ;
978+ console . warn (
979+ `${ prefix } POOL [${ ev . driver } ] waiting=${ ev . waitingCount } idle=${ ev . idleCount } total=${ ev . totalCount } ` ,
980+ ) ;
907981 } ) ;
908982 add ( "slow-acquire" , ( s ) => {
909983 const ev = s as SlowAcquireEvent ;
@@ -1004,11 +1078,7 @@ export class DiagnosticAgent extends EventEmitter {
10041078 * Creates and returns a `RequestContext` for manual use (e.g. background jobs, queue workers).
10051079 * Pass the returned context to `runWithContext(ctx, fn)` to propagate tracing.
10061080 */
1007- public createContext (
1008- method ?: string ,
1009- url ?: string ,
1010- traceparent ?: string ,
1011- ) : RequestContext {
1081+ public createContext ( method ?: string , url ?: string , traceparent ?: string ) : RequestContext {
10121082 return createRequestContext ( method , url , traceparent ) ;
10131083 }
10141084
0 commit comments