feat: Add the parsing of HF_HUB_USER_AGENT_ORIGIN environment variable for telemetry (#3027)

* feat: Add the parsing of HF_HUB_USER_AGENT_ORIGIN environment variable to add info about the environment running TGI. That is useful to track usage in case of collaborations for example.

* fix: trufflehog
This commit is contained in:
Hugo Larcher 2025-02-19 21:09:12 +01:00 committed by GitHub
parent 9c89d0070e
commit 230aa25641
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View File

@ -17,4 +17,5 @@ jobs:
- name: Secret Scanning - name: Secret Scanning
uses: trufflesecurity/trufflehog@853e1e8d249fd1e29d0fcc7280d29b03df3d643d uses: trufflesecurity/trufflehog@853e1e8d249fd1e29d0fcc7280d29b03df3d643d
with: with:
extra_args: --results=verified,unknown # exclude buggy postgres detector that is causing false positives and not relevant to our codebase
extra_args: --results=verified,unknown --exclude-detectors=postgres

View File

@ -1877,6 +1877,8 @@ pub async fn run(
// Only send usage stats when TGI is run in container and the function returns Some // Only send usage stats when TGI is run in container and the function returns Some
let is_container = matches!(usage_stats::is_container(), Ok(true)); let is_container = matches!(usage_stats::is_container(), Ok(true));
// retrieve the huggingface_hub user agent origin if set, and add the origin to telemetry
let origin = std::env::var("HF_HUB_USER_AGENT_ORIGIN").ok();
let user_agent = match (usage_stats_level, is_container) { let user_agent = match (usage_stats_level, is_container) {
(usage_stats::UsageStatsLevel::On | usage_stats::UsageStatsLevel::NoStack, true) => { (usage_stats::UsageStatsLevel::On | usage_stats::UsageStatsLevel::NoStack, true) => {
let reduced_args = usage_stats::Args::new( let reduced_args = usage_stats::Args::new(
@ -1899,6 +1901,7 @@ pub async fn run(
max_client_batch_size, max_client_batch_size,
usage_stats_level, usage_stats_level,
backend.name(), backend.name(),
origin,
); );
Some(usage_stats::UserAgent::new(reduced_args)) Some(usage_stats::UserAgent::new(reduced_args))
} }

View File

@ -98,6 +98,7 @@ pub struct Args {
max_client_batch_size: usize, max_client_batch_size: usize,
usage_stats_level: UsageStatsLevel, usage_stats_level: UsageStatsLevel,
backend_name: &'static str, backend_name: &'static str,
origin: Option<String>,
} }
impl Args { impl Args {
@ -122,6 +123,7 @@ impl Args {
max_client_batch_size: usize, max_client_batch_size: usize,
usage_stats_level: UsageStatsLevel, usage_stats_level: UsageStatsLevel,
backend_name: &'static str, backend_name: &'static str,
origin: Option<String>,
) -> Self { ) -> Self {
Self { Self {
model_config, model_config,
@ -143,6 +145,7 @@ impl Args {
max_client_batch_size, max_client_batch_size,
usage_stats_level, usage_stats_level,
backend_name, backend_name,
origin,
} }
} }
} }