fix: move logger.debug with JSON stringify under if debug #722
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Optimize logging by conditionally executing
JSON.stringifyin debug logs based on log level inscore/index.tsandspan-processor.ts.logger.debugcalls withJSON.stringifyunderifcondition checkingisLevelEnabled(LogLevel.DEBUG)inscore/index.tsandspan-processor.ts.isLevelEnabled(level: LogLevel): booleanmethod toLoggerclass inlogger/index.tsto check if a log level is enabled.LogLevelinscore/index.tsandspan-processor.ts.This description was created by
for 9074c70. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
Optimized debug logging performance by conditionally executing
JSON.stringifyoperations only when DEBUG level logging is enabled.isLevelEnabled(level: LogLevel)method to theLoggerclass to expose log level checking for performance optimizationJSON.stringifycalls inscore/index.tsandspan-processor.tswithisLevelEnabled(LogLevel.DEBUG)guardsConfidence Score: 5/5
isLevelEnabled()method correctly delegates to the existing privateshouldLog()method, maintaining consistency. All usages properly guard expensiveJSON.stringifyoperations, and the implementation follows existing patterns in the codebase.Important Files Changed
isLevelEnabled()method to expose log level checking for performance optimizationJSON.stringifyin debug log underisLevelEnabledcheck for performanceJSON.stringifyin debug log underisLevelEnabledcheck for performanceSequence Diagram
sequenceDiagram participant App as Application Code participant SM as ScoreManager/SpanProcessor participant Logger as Logger Instance participant Console as Console Output App->>SM: create() or processEndedSpan() SM->>Logger: isLevelEnabled(LogLevel.DEBUG) Logger->>Logger: Check if DEBUG >= config.level alt DEBUG is enabled Logger-->>SM: true SM->>SM: Execute JSON.stringify(largeObject) SM->>Logger: debug(message, stringifiedData) Logger->>Logger: shouldLog(DEBUG) Logger->>Console: console.debug(formatted message) else DEBUG is disabled Logger-->>SM: false Note over SM: Skip JSON.stringify - performance saved! SM->>SM: Continue execution end(2/5) Greptile learns from your feedback when you react with thumbs up/down!