ZJ-lucky-0915 opened a new pull request, #77084:
URL: https://github.com/apache/airflow/pull/77084

   `common.ai` exposes LLM usage through OpenTelemetry spans, a per-task `usage`
   XCom, and the UI cost tab, but none of these produce Airflow metrics.
   
   This adds an opt-in `[common.ai] emit_usage_metrics` setting. When enabled,
   usage is aggregated per task attempt and per model, then emitted as:
   
   - `common_ai.llm_requests`
   - `common_ai.llm_input_tokens`
   - `common_ai.llm_output_tokens`
   - `common_ai.llm_cost` (only when a price is known)
   
   Metrics carry only `provider` and `model` tags to keep StatsD cardinality
   bounded. Off by default; no behaviour change.
   
   This first slice adds the config option, the `emit_usage_metrics()` helper, 
and
   unit tests for the disabled/enabled paths. Wiring the existing usage call 
sites
   (`utils/logging.py`, agent and batch paths) will follow in this PR once the
   metric names and aggregation level are confirmed.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: OpenAI Codex following the [Airflow Gen-AI 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   I reviewed the generated code, ran the new unit tests (2 passed), and 
confirmed
   `ruff check` passes.
   


-- 
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]

Reply via email to