Skip to content

Commit ce29729

Browse files
committed
修复trace和asyncio共用时的问题
1 parent b5740d5 commit ce29729

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

skywalking/decorators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
from functools import wraps
1919
from typing import List
20+
import inspect
2021

2122
from skywalking import Layer, Component
2223
from skywalking.trace.context import get_context
2324
from skywalking.trace.tags import Tag
2425

2526

27+
2628
def trace(
2729
op: str = None,
2830
layer: Layer = Layer.Unknown,
@@ -31,7 +33,7 @@ def trace(
3133
):
3234
def decorator(func):
3335
@wraps(func)
34-
def wrapper(*args, **kwargs):
36+
async def wrapper(*args, **kwargs):
3537
_op = op or func.__name__
3638
context = get_context()
3739
with context.new_local_span(op=_op) as span:
@@ -40,6 +42,8 @@ def wrapper(*args, **kwargs):
4042
[span.tag(tag) for tag in tags or []]
4143
try:
4244
result = func(*args, **kwargs)
45+
if inspect.isawaitable(result):
46+
return async await result
4347
return result
4448
except Exception:
4549
span.raised()

0 commit comments

Comments
 (0)