Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the experimental OpenTelemetry formatter, so its payload method coerces values. #319

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
viktorianer wants to merge 1 commit into reidmorrison:master
base: master
Choose a base branch
Loading
from viktorianer:patch-the-experimental-formatter-so-its-payload-method-coerces-values

Conversation

@viktorianer
Copy link
Contributor

@viktorianer viktorianer commented Jul 29, 2025
edited
Loading

Ensures every attribute value is OTLP‐compatible. Hashes become a JSON string, nil is dropped, arrays become arrays of strings/numbers/bools.

Description of changes

This PR updates the OpenTelemetry formatter to ensure that all values in the log payload are compatible with the OpenTelemetry Protocol (OTLP) specification for log attributes.

The changes introduce methods, to recursively sanitize the payload hash.

The coercion rules are as follows:

  • Primitive types (String, Integer, Float, Boolean) are passed through unchanged.
  • nil values are dropped from the payload.
  • Array values are sanitized to ensure they only contain OTLP-compatible scalar types.
  • Hash values are converted into a JSON string.
  • All other object types are converted to their string representation.

This prevents potential errors when exporting logs to an OpenTelemetry collector by guaranteeing that all attributes adhere to the expected format. Example errors:

OpenTelemetry error: invalid log record attribute value type NilClass for key 'cached' on record: 
'{"host"=>"...", "application"=>"Semantic Logger", "environment"=>"staging", "pid"=>25, "thread"=>"10400", "duration_ms"=>0.7280009999813046, "duration"=>"0.728ms", "name"=>"ActiveRecord"}'
OpenTelemetry error: invalid log record attribute value type Hash for key 'binds' on record: 
'{"host"=>"...", "application"=>"Semantic Logger", "environment"=>"staging", "pid"=>25, "thread"=>"10400", "duration_ms"=>4.9787300000025425, "duration"=>"4.979ms", "name"=>"ActiveRecord", "message"=>"ActiveRecord::InternalMetadata Load"}'
OpenTelemetry error: invalid log record attribute value type ActiveSupport::HashWithIndifferentAccess for key 'params' on record: 
'{"host"=>"...", "application"=>"Semantic Logger", "environment"=>"staging", "pid"=>34, "thread"=>"puma threadpool 003", "duration_ms"=>349.21533600008115, "duration"=>"349.2ms", "named_tags"=>{:request_id=>"929eb898-888f-48c6-a406-4079b0933cd5"}, "name"=>"SellersController", "message"=>"Completed #show"}'

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Related to

Ensures every attribute value is OTLP‐compatible. Hashes become a JSON string, nil is dropped, arrays become arrays of strings/numbers/bools.
@viktorianer viktorianer changed the title (削除) Fix the experimental formatter so its payload method coerces values. (削除ここまで) (追記) Fix the experimental OpenTelemetry formatter, so its payload method coerces values. (追記ここまで) Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /