Skip to content
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

feat: Add client hints for requestmeta #1802

Merged
merged 39 commits into from
Feb 9, 2023
Merged

feat: Add client hints for requestmeta #1802

merged 39 commits into from
Feb 9, 2023

Conversation

TBS1996
Copy link
Contributor

@TBS1996 TBS1996 commented Jan 31, 2023

Second PR about supporting client hints. #1183
previous PR: #1752

This PR adds support for client hints on the requestmeta struct, which means that the client hints can be sent as part of an event json as an optional field. This means that more information will be extracted from the client hints rather than the user agent string, as relay will first attempt to check the client hints and only falling back to the user agent string if no client hints are found.

@TBS1996 TBS1996 mentioned this pull request Jan 31, 2023
9 tasks
TBS1996 added a commit that referenced this pull request Feb 3, 2023
This PR renames two functions:

* `RawUserAgentInfo::new()` -> `RawUserAgentInfo::from_headers()`
* Fix typo in `samplingresult_from_rules_and_proccessing_flag`.

This is a separate PR to avoid too many diffs in #1802.

#skip-changelog

#[cfg(test)]
// TODO: Remove Dsn here?
pub fn new(dsn: relay_common::Dsn) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to mod tests{}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'd suggest to keep PRs focused on their scope. More small and focused PRs is better than a few big PRs.

@@ -63,6 +64,8 @@ pub struct StoreConfig {

/// The SDK's sample rate as communicated via envelope headers.
pub client_sample_rate: Option<f64>,

pub client_hints: ClientHints<String>,
Copy link
Contributor Author

@TBS1996 TBS1996 Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added clienthints as a separate field due to backwards compatibility wrt serialization. If this is not necessary for StoreConfig, let me know, and i'll instead use RawUserAgentInfo here.

let mut ua = RawUserAgentInfo::default();

for (key, value) in request.headers() {
ua.extract_header(key.as_str(), value.to_str().ok().map(str::to_string));
Copy link
Contributor Author

@TBS1996 TBS1996 Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is a bit inelegant, but since RawUserAgentInfo is defined in another crate I would have had to import Request library in General to make this a method of RawUserAgentInfo. Since the other Header type is defined by us, we could perhaps implement From<HttpRequest> to make it prettier.

@TBS1996 TBS1996 marked this pull request as ready for review February 6, 2023 16:58
@TBS1996 TBS1996 requested a review from a team February 6, 2023 16:58
relay-general/src/user_agent.rs Outdated Show resolved Hide resolved
relay-general/src/user_agent.rs Outdated Show resolved Hide resolved
relay-general/src/user_agent.rs Outdated Show resolved Hide resolved
relay-general/src/user_agent.rs Outdated Show resolved Hide resolved
relay-server/src/actors/processor.rs Outdated Show resolved Hide resolved
Comment on lines 204 to 205
#[serde(default, skip_serializing_if = "ClientHints::is_empty")]
client_hints: ClientHints<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this a bit upwards and place it next to user_agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I was worried there would be serialization issues, but i guess with json it doesnt matter


#[cfg(test)]
// TODO: Remove Dsn here?
pub fn new(dsn: relay_common::Dsn) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'd suggest to keep PRs focused on their scope. More small and focused PRs is better than a few big PRs.

relay-server/src/extractors/request_meta.rs Outdated Show resolved Hide resolved
relay-server/src/extractors/request_meta.rs Outdated Show resolved Hide resolved
relay-server/src/extractors/request_meta.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
relay-general/src/protocol/replay.rs Outdated Show resolved Hide resolved
user_agent: Some("sentry/agent".to_string()),
no_cache: false,
start_time: Instant::now(),
client_hints: ClientHints::default(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests which use non-default client_hints? To find out what tests would be affected, change to a non-default value here and see if any tests break.

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please apply the last couple of nitpicks (if they make sense) and write PR description that includes why we are doing this, and what changes it makes to data passing through sentry.

relay-general/src/user_agent.rs Outdated Show resolved Hide resolved
relay-general/src/user_agent.rs Show resolved Hide resolved
relay-general/src/user_agent.rs Show resolved Hide resolved
@TBS1996 TBS1996 merged commit d2d0d9f into master Feb 9, 2023
@TBS1996 TBS1996 deleted the feat/reqmetahints branch February 9, 2023 11:37
jan-auer added a commit that referenced this pull request Feb 9, 2023
* master:
  feat: Add client hints for requestmeta (#1802)
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.

None yet

3 participants