You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/12/11 00:17:45 UTC

[skywalking-python] branch master updated: chore: polish #92 and minor fix to logs (#97)

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

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git


The following commit(s) were added to refs/heads/master by this push:
     new bc83671  chore: polish #92 and minor fix to logs (#97)
bc83671 is described below

commit bc83671abd4bb84b53e72026314770cd2f783fd3
Author: Zhenxu Ke <ke...@apache.org>
AuthorDate: Fri Dec 11 08:17:37 2020 +0800

    chore: polish #92 and minor fix to logs (#97)
---
 .github/workflows/build.yaml |  6 +-----
 README.md                    | 10 ++++++++++
 skywalking/config.py         |  2 +-
 skywalking/decorators.py     | 16 ++++++++--------
 skywalking/trace/span.py     |  4 ++--
 5 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index a881280..abc273a 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 1900fb1..c3a8c8d 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 e4c4cbe..4ade9a2 100644
--- a/skywalking/config.py
+++ b/skywalking/config.py
@@ -23,7 +23,7 @@ from typing import TYPE_CHECKING
 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 81c4893..005210f 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 c193168..24fa0f2 100644
--- a/skywalking/trace/span.py
+++ b/skywalking/trace/span.py
@@ -83,7 +83,7 @@ class Span(ABC):
 
     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