Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sentry-ruby/lib/sentry/log_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def serialize_body
else
sprintf(body, *parameters)
end
rescue StandardError => e
# a template that can't be formatted must not drop the whole batch
Sentry.sdk_logger&.debug(LOGGER_PROGNAME) { "Failed to format log message: #{e.message}" }
body
end

def serialize_attributes
Expand Down
15 changes: 15 additions & 0 deletions sentry-ruby/spec/sentry/log_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,20 @@

expect(hash[:attributes]).not_to have_key("sentry.origin")
end

{
"a literal % next to a named token" => ["Disk 100% full on %{host}", { host: "web-1" }],
"a literal % next to %s" => ["%s is 100% done", { parameters: ["import"] }],
"a token without its attribute" => ["%{user} logged in from %{ip}", { user: "jane" }]
}.each do |description, (body, attributes)|
it "keeps the raw body when the template has #{description}" do
event = described_class.new(level: :info, body: body, attributes: attributes)

hash = event.to_h

expect(hash[:body]).to eq(body)
expect(hash[:attributes]["sentry.message.template"]).to eq({ value: body, type: "string" })
end
end
end
end
Loading