-
-
Notifications
You must be signed in to change notification settings - Fork 522
Handle more extra attribute types when logging #2815
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |
| expect(log_event[:attributes][:mailer][:value]).to eq("UserMailer") | ||
| expect(log_event[:attributes][:duration_ms][:value]).to be > 0 | ||
| expect(log_event[:attributes][:perform_deliveries][:value]).to be true | ||
| expect(log_event[:attributes][:delivery_method][:value]).to eq(:test) | ||
| expect(log_event[:attributes][:delivery_method][:value]).to eq("\"test\"") | ||
| expect(log_event[:attributes]["sentry.origin"][:value]).to eq("auto.log.rails.log_subscriber") | ||
| expect(log_event[:attributes][:date]).to be_present | ||
| end | ||
|
|
@@ -76,7 +76,7 @@ | |
|
|
||
| log_event = sentry_logs.find { |log| log[:body] == "Email delivered via NotificationMailer" } | ||
| expect(log_event).not_to be_nil | ||
| expect(log_event[:attributes][:delivery_method][:value]).to eq(:smtp) | ||
| expect(log_event[:attributes][:delivery_method][:value]).to eq("\"smtp\"") | ||
| end | ||
|
|
||
| it "includes date when available" do | ||
|
|
@@ -179,12 +179,12 @@ | |
| expect(log_event).not_to be_nil | ||
| expect(log_event[:attributes][:params]).to be_present | ||
|
|
||
| params = log_event[:attributes][:params][:value] | ||
| params = JSON.parse(log_event[:attributes][:params][:value]) | ||
|
|
||
| expect(params).to include(user_id: 123, safe_param: "value") | ||
| expect(params[:password]).to eq("[FILTERED]") | ||
| expect(params[:api_key]).to eq("[FILTERED]") | ||
| expect(params).to include(email_address: "[email protected]", subject: "Welcome!") | ||
| expect(params).to include("user_id" => 123, "safe_param" => "value") | ||
| expect(params["password"]).to eq("[FILTERED]") | ||
| expect(params["api_key"]).to eq("[FILTERED]") | ||
| expect(params).to include("email_address" => "[email protected]", "subject" => "Welcome!") | ||
| end | ||
| end | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug: The
rescueblock inattribute_hashincorrectly returns the original non-serializable object, causing a crash later during final payload serialization.Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
When a non-serializable object is passed as an attribute to a
LogEvent, theattribute_hashmethod attempts to serialize it withJSON.generate. This fails and is caught by arescueblock. However, therescueblock then returns the original, non-serializable object within the attribute hash. This hash is embedded in the event payload. When the transport layer later attempts to serialize the entire event envelope,JSON.generateis called again on the full payload, which now contains the non-serializable object. This second serialization attempt fails with an unhandled exception, preventing the event from being sent.💡 Suggested Fix
In the
rescueblock of theattribute_hashmethod, instead of returning the raw non-serializablevalue, convert it to a string representation using a method likevalue.to_sorvalue.inspect. This ensures the value is always serializable before being added to the event payload.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
8030622There 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 fine, previously it would crash too but at the transport level which now works when we can convert to JSON.