diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a8812807..abc273aa 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -28,7 +28,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.5, 3.6, 3.7, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8, 3.9] fail-fast: false env: SW_PYTHON_VERSION: ${{ matrix.python-version }} @@ -42,16 +42,12 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Set up dependencies - if: ${{ matrix.python-version != '3.5' }} run: make setup install - name: Lint codes - if: ${{ matrix.python-version != '3.5' }} run: make lint - name: Check license header - if: ${{ matrix.python-version != '3.5' }} run: make license - name: Run unit tests - if: ${{ matrix.python-version != '3.5' }} run: make test CheckStatus: diff --git a/README.md b/README.md index 1900fb14..c3a8c8d5 100755 --- a/README.md +++ b/README.md @@ -100,6 +100,16 @@ def some_method(): some_other_method() +@trace(op='async_functions_are_also_supported') +async def async_func(): + return 'asynchronous' + + +@trace() +async def async_func2(): + return await async_func() + + @runnable() # cross thread propagation def some_method(): some_other_method() diff --git a/skywalking/config.py b/skywalking/config.py index e4c4cbee..4ade9a27 100644 --- a/skywalking/config.py +++ b/skywalking/config.py @@ -23,7 +23,7 @@ if TYPE_CHECKING: from typing import List -RE_IGNORE_PATH = re.compile('^$') # type: 're.Pattern' +RE_IGNORE_PATH = re.compile('^$') # type: re.Pattern service_name = os.getenv('SW_AGENT_NAME') or 'Python Service Name' # type: str service_instance = os.getenv('SW_AGENT_INSTANCE') or str(uuid.uuid1()).replace('-', '') # type: str diff --git a/skywalking/decorators.py b/skywalking/decorators.py index 81c48932..005210f6 100644 --- a/skywalking/decorators.py +++ b/skywalking/decorators.py @@ -33,23 +33,23 @@ def trace( def decorator(func): _op = op or func.__name__ context = get_context() + + span = context.new_local_span(op=_op) + span.layer = layer + span.component = component + [span.tag(tag) for tag in tags or []] + if inspect.iscoroutinefunction(func): @wraps(func) async def wrapper(*args, **kwargs): - with context.new_local_span(op=_op) as span: - span.layer = layer - span.component = component - [span.tag(tag) for tag in tags or []] + with span: return await func(*args, **kwargs) return wrapper else: @wraps(func) def wrapper(*args, **kwargs): - with context.new_local_span(op=_op) as span: - span.layer = layer - span.component = component - [span.tag(tag) for tag in tags or []] + with span: return func(*args, **kwargs) return wrapper diff --git a/skywalking/trace/span.py b/skywalking/trace/span.py index c1931682..24fa0f28 100644 --- a/skywalking/trace/span.py +++ b/skywalking/trace/span.py @@ -83,7 +83,7 @@ def raised(self) -> 'Span': def log(self, ex: Exception) -> 'Span': self.error_occurred = True - self.logs.append(Log(items=LogItem(key='Traceback', val=str(ex)))) + self.logs.append(Log(items=[LogItem(key='Traceback', val=str(ex))])) return self def tag(self, tag: Tag) -> 'Span': @@ -230,7 +230,7 @@ class NoopSpan(Span): def __init__(self, context: 'SpanContext' = None, kind: 'Kind' = None): Span.__init__(self, context=context, kind=kind) - def extract(self, carrier: 'Carrier') -> 'Span': + def extract(self, carrier: 'Carrier'): if carrier is not None: self.context._correlation = carrier.correlation_carrier.correlation