-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an alternative OpenTelemetry implementation for traces that follows standard otel practices #43941
base: main
Are you sure you want to change the base?
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
I'm confirming, but otel traces might have been experimental still, and if that's the case we are free to change them for a good reason, and your description certainly sounds like one! |
If I may, can you add some indication to the title that this is related to OTel Traces specifically? We also have OTel Metrics implemented and it would be nice to minimize confusion. |
@ferruzzi I adjusted the title. The only change in this patch that is related to metrics, it's https://github.com/apache/airflow/pull/43941/files#diff-1cca954ec0be1aaf2c212e718c004cb0902a96ac60043bf0c97a782dee52cc32R85-R86 If you think that it's out of scope, then I can remove it. |
My initial approach wasn't considering scheduler HA. I've updated the patch accordingly. There have been two main challenges
To avoid breaking things, each scheduler will have a list of the spans that it started and will be solely responsible for ending them. We will save two new attributes on the The new columns will be
Possible scenarios with 2 scheduler (this can easily work with more)
Note that with the current airflow otel implementation, you can't create sub-spans from tasks. All dagrun spans are visualized like this
I'll do some testing to make sure nothing has been broken from merging with main and I'll move the PR out of draft. |
Hi @ashb,
Please take a look when you get a chance and let me know how it looks. I'll push some commits for moving the dagrun/scheduler span changes to new methods, to make the code more readable.
This will get us to the old implementation where we can't create spans from under tasks. If a task has already been run and it created spans, then these spans will be lost when we recreate the task span. This is happening for a few reasons
The only way to get the spans back, will be to rerun the task. |
I'm aware this is waiting on my for a review, I will look at this when I can, but I've got some critical bits of AIP-72 (Task Execution Interface) to land first. |
This is my first time contributing to Airflow and I'm not sure if there should be an AIP or a mailing discussion for such changes. I'd appreciate any feedback.
Issue description
related: #40802
There are some OpenTelemetry standard practices that help keep the usage consistent across multiple projects. According to those
To explain more, this is what the flow of operations should be
dagrun
spani. Get the
dagrun
span contextdagrun
context, startti
spani. Get the
ti
span contextti
span context create task-sub spanti
span endsdagrun
span endsAirflow follows a different approach
dag_run
and thetask_instance
This is the flow of the current implementation
The current approach makes it impossible to create spans from under tasks while using the existing airflow code. To achieve that, you need to use https://github.com/howardyoo/airflow_otel_provider which has to generate the same trace id and span id as airflow otherwise the spans won't be properly associated. This isn't easily maintainable and it also makes it hard for people that are familiar with otel but new to airflow, to start using the feature.
These are some references to OpenTelemetry docs
https://opentelemetry.io/docs/concepts/context-propagation/
https://opentelemetry.io/docs/languages/python/propagation/
https://www.w3.org/TR/trace-context/
Implementation description
For the dagrun and ti spans, I've reused the attributes from the original implementation. I found in my testing that the span timings were occasionally off. That was due to the fact that the time conversion to nanoseconds wasn't considering that the timezone isn't always present.
To be able to propagate the context of a span, and use it to create subspan, the span must be active.
For example, for a dag run, the span can't be created at the end but
Same goes for a task and any sub-spans.
With this approach, we can use the new otel methods for creating spans directly from under a task without the need of the
airflow_otel_provider
. These spans will be children of the task span.Check
test_otel_dag.py
for an example of usage.In scheduler HA, multiple schedulers might process a dag, that is running for a long time. The OpenTelemetry philosophy is that spans can't be shared between processes. The process that starts a span should also be the only one that can end it.
To workaround that while staying consistent with the otel spec, each scheduler will keep track of the spans that it starts and will also be solely responsible for ending them.
Let's assume that we are expecting these spans to be created and exported
With the existing airflow implementation, the spans will be
Here are some possible scenarios and how the dag spans will look like, assuming that the dag creates the same spans as above
Scheduler1 processes a dag from start to finish.
Scheduler1 starts a dag and sometime during the run, Scheduler2 picks up the processing and finishes the dag.
Through a db update, Scheduler2 will notify whoever scheduler started the spans, to end them.
Scheduler1 starts a dag and while the dag is running, exits gracefully. Scheduler2 picks up the processing and finishes the dag while the initial scheduler is no longer running.
Scheduler1 will end all active spans that it has a record of and update the db, while exiting. Scheduler2 will create continued spans. This will result in 2 or more spans in place of a long span, but the total duration will be the same. The continued span will be the new parent.
Scheduler1 starts a dag and while the dag is running, exits forcefully. Scheduler2 picks up the processing and finishes the dag while the initial scheduler is no longer running.
Scheduler1 didn't have time to end any spans. Once the new scheduler picks up that the scheduler that started the spans, is unhealthy, it will recreate the lost spans.
Testing
otel_tracer
methods and updated the existing onesPythonVirtualenvOperator
without issuesThe integration test can be used with otel and jaeger as well. To do that, follow the steps on this comment.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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 newsfragments.