Skip to content

Commit

Permalink
collab: Record geoip_country_code on HTTP request spans (#17092)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxdeviant authored Aug 29, 2024
1 parent 4d6bb52 commit 4f408ec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/collab/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -150,10 +152,16 @@ async fn main() -> Result<()> {
.get::<MatchedPath>()
.map(MatchedPath::as_str);

let geoip_country_code = request
.headers()
.typed_get::<CloudflareIpCountryHeader>()
.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,
Expand Down

0 comments on commit 4f408ec

Please sign in to comment.