Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
skywalking-python
提交
1c26c13e
S
skywalking-python
项目概览
apache
/
skywalking-python
通知
60
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skywalking-python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
1c26c13e
编写于
8月 08, 2020
作者:
H
huawei
提交者:
GitHub
8月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Core][Feature] Add cross thread propagation (#62)
上级
4f7b2510
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
9 deletion
+42
-9
README.md
README.md
+10
-1
skywalking/decorators.py
skywalking/decorators.py
+27
-0
tests/plugin/sw_flask/services/consumer.py
tests/plugin/sw_flask/services/consumer.py
+5
-8
未找到文件。
README.md
浏览文件 @
1c26c13e
...
...
@@ -86,7 +86,7 @@ with context.new_local_span(op='https://github.com/apache') as span:
from
time
import
sleep
from
skywalking
import
Component
from
skywalking.decorators
import
trace
from
skywalking.decorators
import
trace
,
runnable
from
skywalking.trace.context
import
SpanContext
,
get_context
@
trace
()
# the operation name is the method name('some_other_method') by default
...
...
@@ -99,6 +99,15 @@ def some_method():
some_other_method
()
@
runnable
()
# cross thread propagation
def
some_method
():
some_other_method
()
from
threading
import
Thread
t
=
Thread
(
target
=
some_method
)
t
.
start
()
context
:
SpanContext
=
get_context
()
with
context
.
new_entry_span
(
op
=
str
(
'https://github.com/apache/skywalking'
))
as
span
:
span
.
component
=
Component
.
Flask
...
...
skywalking/decorators.py
浏览文件 @
1c26c13e
...
...
@@ -44,3 +44,30 @@ def trace(
return
wrapper
return
decorator
def
runnable
(
op
:
str
=
None
,
layer
:
Layer
=
Layer
.
Unknown
,
component
:
Component
=
Component
.
Unknown
,
):
def
decorator
(
func
):
snapshot
=
get_context
().
capture
()
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
_op
=
op
or
"Thread/"
+
func
.
__name__
context
=
get_context
()
with
context
.
new_local_span
(
op
=
_op
)
as
span
:
context
.
continued
(
snapshot
)
span
.
layer
=
layer
span
.
component
=
component
try
:
func
(
*
args
,
**
kwargs
)
except
Exception
:
span
.
raised
()
raise
return
wrapper
return
decorator
tests/plugin/sw_flask/services/consumer.py
浏览文件 @
1c26c13e
...
...
@@ -18,6 +18,7 @@
import
requests
from
skywalking
import
agent
,
config
from
skywalking.decorators
import
runnable
if
__name__
==
'__main__'
:
config
.
service_name
=
'consumer'
...
...
@@ -34,17 +35,13 @@ if __name__ == '__main__':
from
skywalking.trace.context
import
get_context
get_context
().
put_correlation
(
"correlation"
,
"correlation"
)
def
post
(
snap
):
with
get_context
().
new_local_span
(
"/test"
):
get_context
().
continued
(
snap
)
requests
.
post
(
"http://provider:9091/users"
)
snapshot
=
get_context
().
capture
()
@
runnable
(
op
=
"/test"
)
def
post
():
requests
.
post
(
"http://provider:9091/users"
)
from
threading
import
Thread
t
=
Thread
(
target
=
post
,
args
=
(
snapshot
,)
)
t
=
Thread
(
target
=
post
)
t
.
start
()
t
.
join
()
res
=
requests
.
post
(
"http://provider:9091/users"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录