Skip to content

Conversation

@sumerman
Copy link
Contributor

@sumerman sumerman commented Jan 25, 2026

Important

Optimize logging by conditionally executing JSON.stringify in debug logs based on log level in score/index.ts and span-processor.ts.

  • Behavior:
    • Move logger.debug calls with JSON.stringify under if condition checking isLevelEnabled(LogLevel.DEBUG) in score/index.ts and span-processor.ts.
  • Logger:
    • Add isLevelEnabled(level: LogLevel): boolean method to Logger class in logger/index.ts to check if a log level is enabled.
  • Misc:
    • Import LogLevel in score/index.ts and span-processor.ts.

This description was created by Ellipsis 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.stringify operations only when DEBUG level logging is enabled.

  • Added isLevelEnabled(level: LogLevel) method to the Logger class to expose log level checking for performance optimization
  • Wrapped JSON.stringify calls in score/index.ts and span-processor.ts with isLevelEnabled(LogLevel.DEBUG) guards
  • Prevents expensive serialization operations when debug logging is disabled, improving runtime performance in production environments

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are a well-implemented performance optimization with clear benefits and no logical errors. The new isLevelEnabled() method correctly delegates to the existing private shouldLog() method, maintaining consistency. All usages properly guard expensive JSON.stringify operations, and the implementation follows existing patterns in the codebase.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/src/logger/index.ts Added isLevelEnabled() method to expose log level checking for performance optimization
packages/client/src/score/index.ts Wrapped expensive JSON.stringify in debug log under isLevelEnabled check for performance
packages/otel/src/span-processor.ts Wrapped expensive JSON.stringify in debug log under isLevelEnabled check for performance

Sequence 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
Loading

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@vercel
Copy link

vercel bot commented Jan 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
langfuse-js Ready Ready Preview Jan 25, 2026 0:55am

Request Review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@sumerman sumerman merged commit d7efa64 into main Jan 25, 2026
8 of 10 checks passed
@sumerman sumerman deleted the valeriy/if-debug-logging branch January 25, 2026 13:00
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.

2 participants