ZJ-lucky-0915 opened a new issue, #76969: URL: https://github.com/apache/airflow/issues/76969
### Description `common.ai` already exposes LLM usage in three places: OpenTelemetry spans (`gen_ai.usage.*` / `gen_ai.aggregated_usage.*` in `observability.py`), a per-task `usage` XCom, and the task-instance UI cost tab. None of them produce Airflow metrics. Users running StatsD or Prometheus can therefore see how long a task took, but not how many tokens it consumed or what it cost. OpenTelemetry is optional and frequently disabled, and an XCom is per task instance rather than something that can be aggregated across a DAG run or a deployment. Proposal: add an opt-in `[common.ai] emit_usage_metrics` setting that emits Airflow `Stats` counters for LLM usage. ### Proposed behaviour New configuration option, off by default (no behaviour change for existing deployments): ```ini [common.ai] emit_usage_metrics = False ### Use case/motivation Cost control is a first-class operational concern for LLM pipelines. Teams want to alert on token burn rate, build per-model cost dashboards, and compare models before/after a prompt change. Today that requires enabling OpenTelemetry and querying a tracing backend; deployments that already export Airflow metrics to StatsD or Prometheus get nothing. I want to aggregate token usage and cost per model across DAG runs without requiring a tracing backend. ### Related issues _No response_ ### Are you willing to submit a PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
