Kunal8954 opened a new pull request, #72887:
URL: https://github.com/apache/airflow/pull/72887

   Add a callback-based ``Stats.observable_gauge(name, callback, 
description=...)`` API to the Stats observability interface. Instead of a 
caller pushing a value at a moment in time (the existing ``Stats.gauge``), a 
callback is registered once and the metrics SDK invokes it on its own 
export/collection cadence, guaranteeing a fresh "current state" sample every 
collection cycle.
   
   Implemented in the OpenTelemetry backend (`SafeOtelLogger`) via 
`create_observable_gauge`: the user callback receives the collection timeout 
and yields `(value, attributes)` tuples, which are converted to OTel 
`Observation` objects internally. Callback exceptions are handled by the OTel 
SDK (logged, do not crash collection). `Stats.gauge` and all other existing 
Stats methods are unchanged and fully backward compatible.
   
   On non-OTel backends (StatsD, Datadog) and when no backend is configured, 
`observable_gauge` is a silent no-op — those backends do not support observable 
instruments. The prek metrics-registry hook is updated to classify 
`observable_gauge` as type `gauge`.
   
   Validation:
   - OTel backend tests: 7 new (registration, callback invocation, exception 
propagation, invalid/empty names, empty callback, timeout forwarding) — all pass
   - Stats facade/StatsD/Datadog tests: 5 new (delegation via module + `Stats` 
class, description passthrough, no-op behavior) — all pass
   - prek registry hook tests: 106 pass
   - ruff, mypy, `git diff --check`: clean
   
   closes: #72885
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — big-pickle
   
   Generated-by: big-pickle following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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