This is an automated email from the ASF dual-hosted git repository.

eladkal pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 2c6894921ab [v3-0-test] fix mypy errors in otel_tracer  (#52170) 
(#52175)
2c6894921ab is described below

commit 2c6894921ab070e2c5be2a97477e352c36ed3ea4
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jun 25 19:47:32 2025 +0300

    [v3-0-test] fix mypy errors in otel_tracer  (#52170) (#52175)
    
    (cherry picked from commit c6693cbd2880bc7727ec3455390d3549e8b2b873)
    
    Co-authored-by: Christos Bisias <christos...@gmail.com>
---
 airflow-core/src/airflow/traces/otel_tracer.py | 29 +++++++++++++-------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/airflow-core/src/airflow/traces/otel_tracer.py 
b/airflow-core/src/airflow/traces/otel_tracer.py
index d5e71e3f47e..34ee543a56d 100644
--- a/airflow-core/src/airflow/traces/otel_tracer.py
+++ b/airflow-core/src/airflow/traces/otel_tracer.py
@@ -19,6 +19,7 @@ from __future__ import annotations
 
 import logging
 import random
+from contextlib import AbstractContextManager
 from typing import TYPE_CHECKING
 
 from opentelemetry import trace
@@ -247,7 +248,7 @@ class OtelTrace:
         links=None,
         start_time=None,
         start_as_current: bool = True,
-    ):
+    ) -> AbstractContextManager[trace.span.Span] | trace.span.Span:
         if component is None:
             component = self.otel_service
 
@@ -260,24 +261,24 @@ class OtelTrace:
             links = []
 
         if start_as_current:
-            span = tracer.start_as_current_span(
-                name=span_name,
-                context=parent_context,
-                links=links,
-                start_time=datetime_to_nano(start_time),
-            )
-        else:
-            span = tracer.start_span(
+            return tracer.start_as_current_span(
                 name=span_name,
                 context=parent_context,
                 links=links,
                 start_time=datetime_to_nano(start_time),
             )
-            current_span_ctx = 
trace.set_span_in_context(NonRecordingSpan(span.get_span_context()))
-            # We have to manually make the span context as the active context.
-            # If the span needs to be injected into the carrier, then this is 
needed to make sure
-            # that the injected context will point to the span context that 
was just created.
-            attach(current_span_ctx)
+
+        span = tracer.start_span(
+            name=span_name,
+            context=parent_context,
+            links=links,
+            start_time=datetime_to_nano(start_time),
+        )
+        current_span_ctx = 
trace.set_span_in_context(NonRecordingSpan(span.get_span_context()))
+        # We have to manually make the span context as the active context.
+        # If the span needs to be injected into the carrier, then this is 
needed to make sure
+        # that the injected context will point to the span context that was 
just created.
+        attach(current_span_ctx)
         return span
 
     def inject(self) -> dict:

Reply via email to