You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "rjgoyln (via GitHub)" <gi...@apache.org> on 2026/07/30 11:49:21 UTC
[PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
rjgoyln opened a new pull request, #70758:
URL: https://github.com/apache/airflow/pull/70758
## Summary
Airflow uses a custom OpenTelemetry `IdGenerator` so spans from DAG runs and task runs
share the same trace. Previously, this generator was only applied when Airflow created
the `TracerProvider`, so deployments using auto-instrumentation or vendor distros lost
trace linkage.
This change registers the generator as a standard OpenTelemetry entry point, allowing it
to be enabled with `OTEL_PYTHON_ID_GENERATOR=airflow`, and adds a fallback that patches
an existing `TracerProvider` when possible.
## Changes
- Register `OverrideableRandomIdGenerator` as an
`opentelemetry_id_generator` entry point.
- Add a fallback in `configure_otel()` to patch an existing
`TracerProvider` and emit a warning.
- Document auto-instrumentation usage and fallback behavior.
- Add tests for entry point registration and fallback.
- Add newsfragment: `70388.improvement.rst`.
## Notes
- The entry point is registered only in `airflow-core`, since only it overrides span IDs.
- Workers receive propagated `traceparent` values and do not need ID overrides.
## Scope
This PR addresses **Issue 1** of #70388 only. Issues 2 and 3 remain for future work.
* related: #70388
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
- [ ] Yes (please specify the tool below)
<!--
Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "tailg8nj (via GitHub)" <gi...@apache.org>.
tailg8nj commented on code in PR #70758:
URL: https://github.com/apache/airflow/pull/70758#discussion_r3685779485
##########
airflow-core/pyproject.toml:
##########
@@ -211,6 +211,11 @@ dependencies = [
[project.scripts]
airflow = "airflow.__main__:main"
+# Lets OpenTelemetry auto-instrumentation and vendor distros select Airflow's id generator
+# with OTEL_PYTHON_ID_GENERATOR=airflow, instead of reaching into a private module.
+[project.entry-points.opentelemetry_id_generator]
Review Comment:
I'm not well versed in how this project is composed w.r.t the shared observability code, but should this entry point be listed here https://github.com/apache/airflow/blob/main/shared/observability/pyproject.toml ?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "xBis7 (via GitHub)" <gi...@apache.org>.
xBis7 commented on PR #70758:
URL: https://github.com/apache/airflow/pull/70758#issuecomment-6010475358
@tailg8nj I just remembered this older comment of yours
https://github.com/apache/airflow/pull/69633#discussion_r3640039700
Same question as here.
> I believe this to be fairly well documented in the linked issue.
The issue documents what distros and auto-instrumentation are, how they work and what is the standard process of using them.
I've been asking you what Airflow gains by supporting this, and not how OTel intends them to be used.
If Airflow documents that it supports an external provider and also supports Dag run traces, people are going to use both of them and if there are bugs they will then expect the Airflow community to fix them. So accepting an external provider means to also make sure that the existing functionality doesn't break.
> How else do you suggest we address issues 1 and 2 from the linked issue?
I'm not arguing against the changes, we can discuss them later. I'm asking what are the gains and if they are worth the long-term commitment.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "rjgoyln (via GitHub)" <gi...@apache.org>.
rjgoyln commented on code in PR #70758:
URL: https://github.com/apache/airflow/pull/70758#discussion_r3689958778
##########
airflow-core/pyproject.toml:
##########
@@ -211,6 +211,11 @@ dependencies = [
[project.scripts]
airflow = "airflow.__main__:main"
+# Lets OpenTelemetry auto-instrumentation and vendor distros select Airflow's id generator
+# with OTEL_PYTHON_ID_GENERATOR=airflow, instead of reaching into a private module.
+[project.entry-points.opentelemetry_id_generator]
Review Comment:
It can't be registered in `shared/` because that folder is not a published distribution, it's just forcefully vendored into the consumer builds at compile time.
Therefore, the entry point must be declared in the actual installed package `apache-airflow-core` so OpenTelemetry can discover it at runtime.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "tailg8nj (via GitHub)" <gi...@apache.org>.
tailg8nj commented on PR #70758:
URL: https://github.com/apache/airflow/pull/70758#issuecomment-5876341113
> I looked at the linked issue. Can you explain the motivation behind using an external tracer_provider? Maybe an example use-case?
I believe this to be fairly well documented in the linked issue. Open telemetry offers a way for vendors to ship distributions that preconfigure their preferred settings of the SDK and other auto-instrumentation features. These are not limited to: collector endpoint, format and compression, additional span processors, propagation strategies (like setting trace state), framework and library instrumentation preferences (like urllib, requests, httpx, celery, etc). It is a well supported valid way of setting up your Python asset w/o code.
Whether or not internal spans eventually get added can be address by the vendors themselves.
How else do you suggest we address issues 1 and 2 from the linked issue?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "rjgoyln (via GitHub)" <gi...@apache.org>.
rjgoyln commented on PR #70758:
URL: https://github.com/apache/airflow/pull/70758#issuecomment-5779080122
Rebased onto `main` and pushed as `f55fedb`; everything below is in that commit.
### On the ordering against `otel_on`
This is deliberate. Airflow's span emission is not gated on `otel_on`; that flag only controls whether Airflow creates its own provider. If a distro owns the provider, the spans still reach it when `otel_on=False`, so putting this behind the flag would leave those spans with random IDs. I added a comment and a parametrised test to make this explicit.
### On the exporter settings
Agreed — this is now documented in the warning, `traces.rst`, and the newsfragment. The existing exporter settings were already ineffective with a foreign provider, so the early return avoids constructing a provider that could not be installed. I also documented why adding another span processor to the borrowed provider would be incorrect.
### On the import paths
Confirmed. The task SDK already imports this module, so the check is kept at the `configure_otel` entry point. I’ve documented that coupling there.
Happy to switch the check to duck typing if you prefer.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #70758:
URL: https://github.com/apache/airflow/pull/70758#discussion_r4065970534
##########
shared/observability/src/airflow_shared/observability/traces/__init__.py:
##########
@@ -248,7 +248,36 @@ def _load_exporter_from_env() -> SpanExporter:
return ep.load()()
+def _adopt_existing_tracer_provider() -> bool:
+ """
+ Attach Airflow's id generator to a TracerProvider installed by somebody else.
+
+ OpenTelemetry auto-instrumentation and vendor distros set the global provider before
+ ``configure_otel`` runs, and ``set_tracer_provider`` then only logs a warning instead
+ of replacing it -- silently dropping the generator that Airflow's span id propagation
+ depends on. Prefer selecting the generator through the ``opentelemetry_id_generator``
+ entry point (``OTEL_PYTHON_ID_GENERATOR=airflow``): a ``Tracer`` captures the generator
+ it is built with, so anything already created by the time we get here keeps the
+ original one.
+ """
+ provider = trace.get_tracer_provider()
+ if not isinstance(provider, TracerProvider):
+ return False
+ if not isinstance(provider.id_generator, OverrideableRandomIdGenerator):
+ provider.id_generator = OverrideableRandomIdGenerator()
+ log.warning(
+ "A TracerProvider was already installed; patched in %s so Airflow span ids "
+ "keep propagating. Set OTEL_PYTHON_ID_GENERATOR=airflow to have it applied "
+ "when the provider is built instead.",
+ OverrideableRandomIdGenerator.__name__,
+ )
+ return True
+
+
def configure_otel(conf: ConfigParser):
+ if _adopt_existing_tracer_provider():
Review Comment:
This runs before `otel_on` is read on line 281, so the adoption happens whether or not Airflow tracing is enabled.
The case I'd want to be sure about: a deployment under `opentelemetry-instrument` that has deliberately set `otel_on=False`. Today `configure_otel` does nothing for them. After this change their `TracerProvider.id_generator` is replaced and every component start logs the warning from line 268, recommending an environment variable for a feature they have switched off.
`test_patches_id_generator_onto_existing_provider` parametrizes `otel_on=[True, False]` and asserts the patch in both, so this reads as intentional rather than accidental — could you record the reasoning in a comment here? My instinct is that the adoption belongs behind the `otel_on` check, but you have thought about this more than I have.
Separately, this `return` also skips the entire exporter and span-processor setup below. I think that is the right call — a vendor distro has already configured its own exporters and a second one would be worse — but an operator with `otel_host` / `otel_port` in their config gets no indication those settings have stopped applying. Worth a sentence in the warning on line 268 and in the new docs section.
##########
airflow-core/pyproject.toml:
##########
@@ -211,6 +211,11 @@ dependencies = [
[project.scripts]
airflow = "airflow.__main__:main"
+# Lets OpenTelemetry auto-instrumentation and vendor distros select Airflow's id generator
+# with OTEL_PYTHON_ID_GENERATOR=airflow, instead of reaching into a private module.
+[project.entry-points.opentelemetry_id_generator]
Review Comment:
Worth a note here about a coupling that isn't visible from this file.
The same source is importable by three paths — `airflow._shared.observability.traces`, `airflow.sdk._shared.observability.traces` (task-sdk symlinks the same directory) and `airflow_shared.observability.traces` — and Python treats each as a separate module with its own `OverrideableRandomIdGenerator` class object. So the `isinstance` check in `_adopt_existing_tracer_provider` only succeeds when the entry-point-loaded class and the checking code came through the same path.
That holds right now: `settings.py:42` is the only caller of `configure_otel` and imports `airflow._shared…`, matching this entry point exactly. But if task-sdk ever calls it, the check fails silently and a second generator gets patched in over a perfectly good one, with a misleading warning.
Either a duck-typed check on the generator side, or a comment here recording that this path must match whatever `configure_otel` imports, would keep that from being a surprise later.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed pull request #70758: Support OpenTelemetry auto-instrumentation and vendor distros
URL: https://github.com/apache/airflow/pull/70758
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support OpenTelemetry auto-instrumentation and vendor distros [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #70758:
URL: https://github.com/apache/airflow/pull/70758#issuecomment-5839159794
Hello @rjgoyln - thank you for your contributions to Apache Airflow!
The Airflow community has introduced a limit of **5 open pull requests at a time** for contributors without write access to the repository. You currently have 24 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
* #70758 - Support OpenTelemetry auto-instrumentation and vendor distros
* #70840 - Honor OTEL_PROPAGATORS when propagating trace context across Airflow
* #70936 - Fix API client errors losing detail behind a reverse proxy
* #70940 - Fix airflowctl config lint filters matching partial config names
* #71194 - Stop failing reschedule-mode sensors on a stale executor success
* #71868 - Drop the cncf.kubernetes provider dependency from airflow-core tests
* #72041 - Drop the git provider dependency from airflow-core tests
* #72053 - Fail deferred sensors on non-timeout errors when soft_fail is set
* #72249 - Drop the celery provider dependency from airflow-core tests
* #72301 - Honor config_file in deferrable Kubernetes tasks
* #72591 - Fix Dataproc job not cancelled when killing a deferred task
* #72595 - Stop the scheduler deadlocking with the triggerer on deferred-task timeouts
* #72596 - Make the scheduler's HITL and orphan sweeps retry transient DB errors
* #72758 - Keep the triggerer running when a trigger constructor raises
* #72814 - Stop failing scheduled tasks when a serialized Dag is briefly missing
* #73022 - Stop fetching the run conf once per task instance in the scheduler
* #73076 - Catch format-string arguments passed to exception constructors
* #73131 - Fail deferrable KPO when a GC'd pod takes its XCom with it
* #73166 - Block new EM102 f-string exception messages in prek
* #73170 - Fail the local yml mounts prek hook when synchronization fails
* #73204 - Fix provider.yaml doc URL check with several suspended providers
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
* #70620 - Batch upstream map-length lookups when resolving mapped kwargs
* #71850 - Re-anchor custom queued deadline references when a Dag run is cleared
* #73221 - Make the default task failure email say what failed
This is **not** a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.
What we ask you to do is to make your **first prioritization decision**: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or `gh pr reopen <PR_NUMBER> --repo apache/airflow`. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.
While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.
Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.
---
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk 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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org