howardyoo commented on code in PR #37948: URL: https://github.com/apache/airflow/pull/37948#discussion_r1518461640
########## airflow/traces/tracer.py: ########## @@ -0,0 +1,256 @@ +# +# 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. +from __future__ import annotations + +import logging +import socket +import typing +from typing import ( + TYPE_CHECKING, + Callable, +) + +from airflow.configuration import conf +from airflow.typing_compat import Protocol + +log = logging.getLogger(__name__) + + +def gen_context(trace_id, span_id): + """Generate span context from trace_id and span_id.""" + from airflow.traces.otel_tracer import gen_context as otel_gen_context + + return otel_gen_context(trace_id, span_id) + + +def gen_links_from_kv_list(list): + """Generate links from kv list of {trace_id:int, span_id:int}.""" + from airflow.traces.otel_tracer import gen_links_from_kv_list + + return gen_links_from_kv_list(list) + + +def span(func): + """Decorate a function with span.""" + + def wrapper(*args, **kwargs): + func_name = func.__name__ + qual_name = func.__qualname__ + module_name = func.__module__ + if "." in qual_name: + component = f"{qual_name.rsplit('.', 1)[0]}" + else: + component = module_name + with Trace.start_span(span_name=func_name, component=component): + return func(*args, **kwargs) + + return wrapper + + +class DummyContext: Review Comment: Ok, I see - I'll replace the context with "Empty", as the idea is more towards providing `empty` object. -- 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]
