0BVer commented on code in PR #77283:
URL: https://github.com/apache/airflow/pull/77283#discussion_r4690407892


##########
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:
   Thanks, this is a good suggestion. You are right that the fix currently 
depends on
   `Resource.create()` happening to import `concurrent.futures.thread` inside 
the SDK, and an
   explicit import at module level removes that dependency. I will add it 
together with the test
   change (the assertion moved above the `configure_otel` import).
   
   One question on top of that. With the explicit import in place, the hook 
order no longer
   depends on `Resource.create()`, so I could change `Resource.create({...})` 
back to
   `Resource({...})` and keep this PR limited to the deadlock: the resource 
would stay identical
   to `main` (no added `telemetry.sdk.*` and `service.instance.id` attributes), 
and the regression
   test would pin the import line, since removing it makes the test fail. On 
the other hand, you
   pointed out that `Resource.create()` keeps this path consistent with the 
default one, which is
   a fair argument too. Do you have a preference?
   
   For reference, I tried the import-only variant locally on Python 3.11 to 
3.14 with SDK 1.45.2:
   the test passes, and it fails with a deadlock once the import is removed. I 
have not run that
   variant in a real Airflow process, whereas your kind cluster run used 
`Resource.create()`.
   
   ---
   Drafted-by: Claude Code (Sonnet 5.5); reviewed by @0BVer 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]

Reply via email to