-
Notifications
You must be signed in to change notification settings - Fork 256
feat: Use logger.warn for log attribute validation #1825
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: main
Are you sure you want to change the base?
feat: Use logger.warn for log attribute validation #1825
Conversation
Update the way users are notified about invalid log record attribute keys and values by using OpenTelemetry.logger.warn instead of OpenTelemetry.handle_error. Also, include the key with the invalid type in the message.
@@ -139,10 +139,10 @@ def validate_attributes(attrs) | |||
# Future refactor opportunity: https://github.com/open-telemetry/opentelemetry-ruby/issues/1739 | |||
attrs.keep_if do |k, v| | |||
if !Internal.valid_key?(k) | |||
OpenTelemetry.handle_error(message: "invalid log record attribute key type #{k.class} on record: '#{body}'") | |||
OpenTelemetry.logger.warn("Invalid log record attribute key type #{k.class} for key #{k.inspect} on record: '#{body}'. Attribute keys must be Strings. Dropping attribute.") |
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.
This is going to produce very noisy log output.
Do we log warnings in the SDK for traces?
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.
Great point. The Trace SDK does not use the logger to warn, instead, we handle the error like the current behavior in the logger. I wonder if updating the message for the handle_error
call would be sufficient to let people know about the problem?
Here's the equivalent Trace SDK code:
opentelemetry-ruby/sdk/lib/opentelemetry/sdk/internal.rb
Lines 51 to 63 in 98c629e
def valid_attributes?(owner, kind, attrs) | |
attrs.nil? || attrs.each do |k, v| | |
if !valid_key?(k) | |
OpenTelemetry.handle_error(message: "invalid #{kind} attribute key type #{k.class} on span '#{owner}'") | |
return false | |
elsif !valid_value?(v) | |
OpenTelemetry.handle_error(message: "invalid #{kind} attribute value type #{v.class} for key '#{k}' on span '#{owner}'") | |
return false | |
end | |
end | |
true | |
end |
Update the way users are notified about invalid log record attribute keys and values by using OpenTelemetry.logger.warn instead of OpenTelemetry.handle_error. Also, include the key with the invalid type in the message.
Relates to #1781