ersalil opened a new pull request, #68023:
URL: https://github.com/apache/airflow/pull/68023
## Summary
`name_is_otel_safe()` declares `-> bool` but was leaking
`InvalidStatsNameException` from `stat_name_otel_handler()`, crashing the
scheduler whenever a DAG contained a non-ASCII task or TaskGroup name (e.g.
`preço_task`, `tâche`, `aufgäbe`) and OTel metrics were enabled.
## Why
`stat_name_otel_handler()` is documented to raise
`InvalidStatsNameException` for names that violate the OTel instrument-name
spec (ASCII only). `name_is_otel_safe()` called it without catching that
exception, so the exception propagated into the scheduler's critical section
(`_executable_task_instances_to_queued`) and brought the process down in a
CrashLoopBackOff.
A `-> bool` function must never raise — returning `False` is the correct way
to signal "this name is not safe".
## Fix
Wrapped the `stat_name_otel_handler()` call inside `name_is_otel_safe()`
with `try/except InvalidStatsNameException`, log a `warning`, and return
`False`. No changes needed at call sites — `incr()`, `decr()`, and `timing()`
already skip the metric when `name_is_otel_safe()` returns `False`. Aligns with
the existing log + skip pattern used by `SafeStatsdLogger` and
`SafeDogStatsdLogger` via the `validate_stat` decorator.
## Testing
- Renamed `test_invalid_stat_names_are_caught` →
`test_invalid_stat_names_are_skipped` and updated the assertion from
`pytest.raises(InvalidStatsNameException)` to `assert result is None` to
reflect the corrected behaviour.
- Added `test_non_ascii_stat_names_are_skipped_without_raising` with three
parametrized cases (Portuguese `ç`, French `â`, German `ä`) directly
reproducing the reported crash scenario.
closes: #68018
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Sonnet 4.6)
This PR was prepared with Gen-AI assistance (Claude). I reviewed all
generated code.
--
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]