From 4f408ec65a3867278322a189b4eb20f1ab51f508 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 29 Aug 2024 11:33:51 -0400 Subject: [PATCH] collab: Record `geoip_country_code` on HTTP request spans (#17092) This PR attaches the `geoip_country_code` that we source from Cloudflare's `CF-IPCountry` header to the HTTP request spans. This will allow us to see where traffic is originating geographically. Release Notes: - N/A --- crates/collab/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index 7c49552d02..b3ceb72b52 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -1,10 +1,12 @@ use anyhow::anyhow; +use axum::headers::HeaderMapExt; use axum::{ extract::MatchedPath, http::{Request, Response}, routing::get, Extension, Router, }; +use collab::api::CloudflareIpCountryHeader; use collab::llm::{db::LlmDatabase, log_usage_periodically}; use collab::migrations::run_database_migrations; use collab::user_backfiller::spawn_user_backfiller; @@ -150,10 +152,16 @@ async fn main() -> Result<()> { .get::() .map(MatchedPath::as_str); + let geoip_country_code = request + .headers() + .typed_get::() + .map(|header| header.to_string()); + tracing::info_span!( "http_request", method = ?request.method(), matched_path, + geoip_country_code, user_id = tracing::field::Empty, login = tracing::field::Empty, authn.jti = tracing::field::Empty,