@@ -15,6 +15,7 @@ import { parameter } from "./parameter";
1515import type { FunctionInfo } from "./registry" ;
1616import compactObject from "./util/compactObject" ;
1717import { getTime , getTimeInMilliseconds } from "./util/getTime" ;
18+ import { shouldRecord } from "./recorderControl" ;
1819import { warn } from "./message" ;
1920
2021export default class Recording {
@@ -239,10 +240,24 @@ export default class Recording {
239240 private bufferedEvents = new Map < number , AppMap . Event > ( ) ;
240241
241242 public emit ( event : AppMap . Event ) {
243+ // Check here if we should record instead of requiring each
244+ // possible hook to check it.
245+ // This is also checked in recorder.record() to prevent
246+ // unnecessary event object creation. Checking this inside hooks,
247+ // (http, sqlite, pg, mysql, ...) will save some CPU cycles but
248+ // will complicate their code.
249+ if ( ! shouldRecord ( ) ) return ;
250+
242251 if ( ! this . running ) {
243252 warn ( "event emitted while recording not running" ) ;
244253 return ;
245254 }
255+
256+ if ( this . stream == undefined ) {
257+ warn ( "Event emitted while stream is closed" ) ;
258+ return ;
259+ }
260+
246261 // If the current buffer is alive more than allowed pass its events
247262 // to the stream and clear it recursively.
248263 if ( Recording . buffering && ! Recording . buffer . disposed && config ( ) . asyncTrackingTimeout != 0 ) {
0 commit comments