-
-
Notifications
You must be signed in to change notification settings - Fork 532
fix: Add block syntax support to StructuredLogger for compatibility #2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,8 +59,8 @@ def initialize(config) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def trace(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def trace(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at DEBUG level | ||
|
|
@@ -70,8 +70,8 @@ def trace(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def debug(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def debug(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at INFO level | ||
|
|
@@ -81,8 +81,8 @@ def debug(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def info(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def info(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at WARN level | ||
|
|
@@ -92,8 +92,8 @@ def info(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def warn(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def warn(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at ERROR level | ||
|
|
@@ -103,8 +103,8 @@ def warn(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def error(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def error(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at FATAL level | ||
|
|
@@ -114,8 +114,8 @@ def error(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def fatal(message, parameters = [], **attributes) | ||
| log(__method__, message, parameters: parameters, **attributes) | ||
| def fatal(message = nil, parameters = [], **attributes, &block) | ||
| log(__method__, message, parameters: parameters, **attributes, &block) | ||
| end | ||
|
|
||
| # Logs a message at the specified level | ||
|
|
@@ -126,7 +126,8 @@ def fatal(message, parameters = [], **attributes) | |
| # @param attributes [Hash] Additional attributes to include with the log | ||
| # | ||
| # @return [LogEvent, nil] The created log event or nil if logging is disabled | ||
| def log(level, message, parameters:, **attributes) | ||
| def log(level, message = nil, parameters:, **attributes, &block) | ||
| message = yield if message.nil? && block_given? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nil message causes NoMethodError in LogEventLow Severity Making |
||
| case parameters | ||
| when Array then | ||
| Sentry.capture_log(message, level: level, severity: LEVELS[level], parameters: parameters, **attributes) | ||
|
Comment on lines
126
to
133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Suggested FixUpdate the method definitions in Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DebugStructuredLogger not updated for block syntax support
Medium Severity
DebugStructuredLoggeroverrides all the same log-level methods andlogwith the old signatures —messageis required and no&blockis accepted. After this change, calling block syntax likelogger.info { "Hello" }on aDebugStructuredLoggerinstance raises anArgumentErrorbecause it still expects a mandatorymessageargument and silently ignores the block. This breaks the compatibility goal for anyone using the debug logger variant.Additional Locations (1)
sentry-ruby/lib/sentry/structured_logger.rb#L128-L130