-
Notifications
You must be signed in to change notification settings - Fork 94
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
bug(replays): Add default user object and fill its ip-address #1805
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76fb514
Add default user object and fill its ip-address
cmanallen 932073b
Add {{auto}} handlers
cmanallen 254b032
Make ip-address normalization behavior generic
cmanallen 69b455a
Update changelog
cmanallen 1211fec
Remove unused value type
cmanallen 91a55f3
Add functions for defaulting auto in request and user types
cmanallen 2a3a65e
Merge branch 'master' into replays-default-user-with-ip
cmanallen 4316716
Merge branch 'master' into replays-default-user-with-ip
cmanallen 4e52e0c
ref: Smaller diff
jjbayer 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 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 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 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 |
---|---|---|
|
@@ -591,6 +591,20 @@ fn normalize_security_report( | |
|
||
/// Backfills IP addresses in various places. | ||
fn normalize_ip_addresses(event: &mut Event, client_ip: Option<&IpAddr>) { | ||
normalize_ip_addresses_generic( | ||
&mut event.request, | ||
&mut event.user, | ||
&event.platform, | ||
client_ip, | ||
) | ||
} | ||
|
||
pub fn normalize_ip_addresses_generic( | ||
request: &mut Annotated<Request>, | ||
user: &mut Annotated<User>, | ||
platform: &Annotated<String>, | ||
client_ip: Option<&IpAddr>, | ||
) { | ||
// NOTE: This is highly order dependent, in the sense that both the statements within this | ||
// function need to be executed in a certain order, and that other normalization code | ||
// (geoip lookup) needs to run after this. | ||
|
@@ -601,7 +615,7 @@ fn normalize_ip_addresses(event: &mut Event, client_ip: Option<&IpAddr>) { | |
|
||
// Resolve {{auto}} | ||
if let Some(client_ip) = client_ip { | ||
if let Some(ref mut request) = event.request.value_mut() { | ||
if let Some(ref mut request) = request.value_mut() { | ||
if let Some(ref mut env) = request.env.value_mut() { | ||
if let Some(&mut Value::String(ref mut http_ip)) = env | ||
.get_mut("REMOTE_ADDR") | ||
|
@@ -614,7 +628,7 @@ fn normalize_ip_addresses(event: &mut Event, client_ip: Option<&IpAddr>) { | |
} | ||
} | ||
|
||
if let Some(ref mut user) = event.user.value_mut() { | ||
if let Some(ref mut user) = user.value_mut() { | ||
if let Some(ref mut user_ip) = user.ip_address.value_mut() { | ||
if user_ip.is_auto() { | ||
*user_ip = client_ip.to_owned(); | ||
|
@@ -624,22 +638,21 @@ fn normalize_ip_addresses(event: &mut Event, client_ip: Option<&IpAddr>) { | |
} | ||
|
||
// Copy IPs from request interface to user, and resolve platform-specific backfilling | ||
let http_ip = event | ||
.request | ||
let http_ip = request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, here we could have two separate functions. One that resolves {{auto}}, and another one that copies IP addresses over. |
||
.value() | ||
.and_then(|request| request.env.value()) | ||
.and_then(|env| env.get("REMOTE_ADDR")) | ||
.and_then(Annotated::<Value>::as_str) | ||
.and_then(|ip| IpAddr::parse(ip).ok()); | ||
|
||
if let Some(http_ip) = http_ip { | ||
let user = event.user.value_mut().get_or_insert_with(User::default); | ||
let user = user.value_mut().get_or_insert_with(User::default); | ||
user.ip_address.value_mut().get_or_insert(http_ip); | ||
} else if let Some(client_ip) = client_ip { | ||
let user = event.user.value_mut().get_or_insert_with(User::default); | ||
let user = user.value_mut().get_or_insert_with(User::default); | ||
// auto is already handled above | ||
if user.ip_address.value().is_none() { | ||
let platform = event.platform.as_str(); | ||
let platform = platform.as_str(); | ||
|
||
// In an ideal world all SDKs would set {{auto}} explicitly. | ||
if let Some("javascript") | Some("cocoa") | Some("objc") = platform { | ||
|
This file contains 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"4" | ||
], | ||
"dist": "1.12", | ||
"platform": "Python", | ||
"platform": "javascript", | ||
"environment": "production", | ||
"release": "[email protected]", | ||
"tags": { | ||
|
This file contains 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"4" | ||
], | ||
"dist": "1.12", | ||
"platform": "Python", | ||
"platform": "javascript", | ||
"environment": "production", | ||
"release": "[email protected]", | ||
"tags": { | ||
|
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.
Thinking out loud, instead of a function with a large signature like this, we could decompose it into smaller functions. For instance, I'm noticing that we don't have to pass the
user
in. Instead, this function could return anOption<IpAddr>
and then the caller runsget_or_insert_with(|| infer_ip_address(/* ... */))
.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.
@jan-auer I did break out some of the functionality into different units but I kept this function with the large signature. I didn't want to duplicate implementation details across two modules. If there's a better way to do this let me know. I'd also like to expedite this particular pull if possible. Its preventing ip-address ingest in prod currently.