Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kaylareopelle
Copy link
Contributor

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

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.")
Copy link
Contributor

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?

Copy link
Contributor Author

@kaylareopelle kaylareopelle Apr 11, 2025

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:

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

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