xchwan commented on code in PR #77283:
URL: https://github.com/apache/airflow/pull/77283#discussion_r4673292223
##########
shared/observability/src/airflow_shared/observability/traces/__init__.py:
##########
@@ -211,7 +211,10 @@ def _get_backcompat_config(conf: ConfigParser) ->
tuple[str | None, Resource | N
if not os.environ.get("OTEL_SERVICE_NAME") and not
os.environ.get("OTEL_RESOURCE_ATTRIBUTES"):
service_name = conf.get("traces", "otel_service", fallback=None)
if service_name:
- resource = Resource({"service.name": service_name})
+ # ``Resource.create()``, not ``Resource(...)``: it imports
``concurrent.futures.thread``, so that
+ # module's at-fork hooks are registered before
``TracerProvider``'s and the forked child does not
+ # deadlock (open-telemetry/opentelemetry-python#5789).
+ resource = Resource.create({"service.name": service_name})
Review Comment:
Right now the fix works because `Resource.create()` happens to import
`concurrent.futures.thread` (through `ThreadPoolExecutor` in
`get_aggregated_resources`) before `TracerProvider` registers its at-fork hook.
If a later SDK release stops importing it there, the deadlock comes back
without any change on our side. Would you consider making that explicit at
module level?
```python
# Must be imported before TracerProvider is created: its at-fork hook
reinitialises the lock
# that TracerProvider's own after-fork hook needs, and at-fork hooks run in
registration order.
import concurrent.futures.thread # noqa: F401
```
With that import, the precondition in the test always fails, because it runs
after `configure_otel` is imported. Moving it above that import keeps the test
meaningful:
```python
from opentelemetry import trace
assert "concurrent.futures.thread" not in sys.modules, (
"precondition: concurrent.futures.thread imported before the Airflow
traces module; "
"the test would not exercise the fork-hook ordering"
)
from airflow_shared.observability.traces import configure_otel
```
I tried both together. The test passes with your fix (with or without the
explicit import), and it still deadlocks and fails with the old static
`Resource` and no import. Keeping `Resource.create()` also seems good to me,
for consistency with the default path. What do you think?
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @xchwan before posting
--
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]