xchwan commented on PR #77283:
URL: https://github.com/apache/airflow/pull/77283#issuecomment-7116891174
Thanks a lot for tracking this down. It is a nasty fork deadlock, and the
root-cause note with the upstream link is really helpful.
What I checked (opentelemetry-sdk 1.45.2, Python 3.14, via `uv run --project
shared/observability`):
- The new test passes. With the old static `Resource(...)` restored, the
forked child deadlocks and the 10s alarm kills it, so the test catches the
regression.
- Mechanism: `TracerProvider`'s after-fork hook calls
`_get_process_dependent_resource()`, which uses `ThreadPoolExecutor.submit()`
and needs `_global_shutdown_lock`. Only the after-fork hook of
`concurrent.futures.thread` reinitialises that lock, and the hooks run in
registration order. `Resource.create()` imports that module before the provider
registers its hook, so the order comes out right.
- Semantics: `Resource.create({"service.name": ...})` merges user attributes
last, so the configured `otel_service` still wins. This branch only runs when
`OTEL_SERVICE_NAME`/`OTEL_RESOURCE_ATTRIBUTES` are unset. The resource now also
gets `telemetry.sdk.*` and `service.instance.id`, the same as the default path
(`TracerProvider(resource=None)` already calls `Resource.create({})`). That
looks like a nice consistency win.
- Metrics are not affected: `metrics/otel_logger.py` already calls
`Resource.create` before creating the `MeterProvider`.
- I first worried that OTEL_* variables in the environment could leak into
the subprocess. The autouse `clear_otel_env_vars` fixture in
`shared/observability/tests/conftest.py` already handles that. The test passes
with `OTEL_SERVICE_NAME` or `OTEL_RESOURCE_ATTRIBUTES` set, so nothing to
change there.
One suggestion inline: make the import order explicit, so the fix does not
depend on an import side effect inside the SDK. The test needs a small change
to go with it. I checked that variant both ways.
All of the above was run with opentelemetry-sdk 1.45.2, the version in
`uv.lock`.
--
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]