Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat: Add country-code to metric tags for ad fill instrumentation (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncloudioj authored Apr 5, 2023
1 parent f4e92ad commit 4150e34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/adm/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,17 @@ pub async fn get_tiles(
let settings = &state.settings;
let image_store = &state.img_store;
let pse = AdmPse::appropriate_from_settings(&device_info, settings);
let country_code = location
.country
.as_deref()
.unwrap_or_else(|| settings.fallback_country.as_ref());
let adm_url = Url::parse_with_params(
&pse.endpoint,
&[
("partner", pse.partner_id.as_str()),
("sub1", pse.sub1.as_str()),
("sub2", "newtab"),
(
"country-code",
&(location
.country
.clone()
.unwrap_or_else(|| settings.fallback_country.clone())),
),
("country-code", country_code),
("region-code", &location.region()),
(
"dma-code",
Expand Down Expand Up @@ -180,6 +178,9 @@ pub async fn get_tiles(
}
tags.add_extra("adm_url", adm_url);

// Add `country_code` for ad fill instrumentation.
tags.add_tag("geo.country_code", country_code);

metrics.incr_with_tags("tiles.adm.request", Some(tags));
let response: AdmTileResponse = match state.settings.test_mode {
crate::settings::TestModes::TestFakeResponse => {
Expand Down
2 changes: 2 additions & 0 deletions src/web/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ async fn metrics() {
assert!(get_metric.contains("ua.form_factor:desktop"));
assert!(get_metric.contains("ua.os.family:windows"));
assert!(!&metrics[1].contains("endpoint:mobile"));
assert!(&metrics[1].contains("geo.country_code"));

let req = test::TestRequest::get()
.uri("/v1/tiles")
Expand All @@ -894,6 +895,7 @@ async fn metrics() {
assert!(get_metric.contains("ua.form_factor:phone"));
assert!(get_metric.contains("ua.os.family:ios"));
assert!(&metrics[1].contains("endpoint:mobile"));
assert!(&metrics[1].contains("geo.country_code"));
}

#[actix_web::test]
Expand Down

0 comments on commit 4150e34

Please sign in to comment.