kacpermuda opened a new pull request, #58672:
URL: https://github.com/apache/airflow/pull/58672
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
## TLDR
Automatically inject OpenLineage lineage metadata into triggered DAG run
conf when OpenLineage is available and enabled, improving lineage tracking
across DAG boundaries.. **The implementation** never modifies non-OpenLineage
parts of conf, gracefully handles all error cases, and preserves original conf
if anything goes wrong. Users can opt out by setting
`openlineage_inject_parent_info=False`. Because it's safe and only works for
users with enabled OL we can keep default=`True`.
### User Impact by Scenario
#### All Users
- **Non-OpenLineage configuration**: **Never modified under any
circumstances**
- **Error handling**: If any exception occurs during injection (import
errors, unexpected errors), the original conf is returned and a warning is
logged
- **Opt-out**: Set `openlineage_inject_parent_info=False` to completely
disable this feature
#### Users with OpenLineage disabled or not installed
- **Conf**: DAG run conf is **never modified**
- **Overhead**: Only a lightweight check to detect if OpenLineage is
available (debug-level log message)
- **Behavior**: Function returns immediately with original configuration
unchanged
#### Users on older OpenLineage Provider versions (< 2.8.0)
- **Conf**: DAG run conf is **never modified**
- **Logging**: An informational log message indicates that injection is not
supported and suggests upgrading to
`apache-airflow-providers-openlineage>=2.8.0`
- **Behavior**: Function catches version incompatibility and returns
original configuration unchanged
#### Users on compatible OpenLineage Provider versions (>= 2.8.0)
- **Conf**: OpenLineage metadata is added to DagRun conf under the
`openlineage` key
- **Existing OpenLineage keys**: If you already have `openlineage` part in
your conf, they are **preserved and merged** (parent/root identifiers are not
overwritten if they already exist)
- **Behavior**: Metadata about the parent task (run ID, job name, namespace,
root run info) is injected to enable lineage tracking
### Testing
Added comprehensive test coverage for both Airflow 2 and Airflow 3:
- Injection disabled when flag is `False`
- Provider not accessible scenarios
- Version compatibility checks (older vs newer versions)
- Exception handling during injection
- Successful injection with various configuration types (None, empty dict,
dict with existing keys)
All tests follow consistent patterns with parametrization and helper
functions for maintainability.
Also saved `trigger_run_id` as TriggerDagRunOperator's attribute to be used
by OL listener.
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a
newsfragment file, named `{pr_number}.significant.rst` or
`{issue_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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]