Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
skywalking-python
提交
ecefb9b5
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 搜索 >>
提交
ecefb9b5
编写于
5月 04, 2020
作者:
K
kezhenxu94
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complement exception handler and reorganize package structure
上级
fff26c22
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
68 addition
and
34 deletion
+68
-34
skywalking/__init__.py
skywalking/__init__.py
+3
-1
skywalking/agent/__init__.py
skywalking/agent/__init__.py
+2
-13
skywalking/agent/protocol/__init__.py
skywalking/agent/protocol/__init__.py
+30
-0
skywalking/agent/protocol/grpc/__init__.py
skywalking/agent/protocol/grpc/__init__.py
+8
-1
skywalking/agent/protocol/http/__init__.py
skywalking/agent/protocol/http/__init__.py
+0
-0
skywalking/decorators/__init__.py
skywalking/decorators/__init__.py
+12
-2
skywalking/loggings/__init__.py
skywalking/loggings/__init__.py
+1
-1
skywalking/trace/context/__init__.py
skywalking/trace/context/__init__.py
+1
-7
skywalking/trace/segment/__init__.py
skywalking/trace/segment/__init__.py
+0
-1
skywalking/trace/span/__init__.py
skywalking/trace/span/__init__.py
+3
-1
tests/main.py
tests/main.py
+8
-7
未找到文件。
skywalking/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -59,8 +59,10 @@ class Kind(Enum):
return
self
==
Kind
.
Exit
LogItem
=
namedtuple
(
'LogItem'
,
'key val'
)
class
Log
(
object
):
LogItem
=
namedtuple
(
'LogItem'
,
'key val'
)
def
__init__
(
self
,
timestamp
:
time
=
time
.
time
(),
items
:
List
[
LogItem
]
=
None
):
self
.
timestamp
=
timestamp
...
...
skywalking/agent/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -16,27 +16,16 @@
#
import
logging
from
abc
import
ABC
from
queue
import
Queue
from
threading
import
Thread
,
Event
from
skywalking
import
config
from
skywalking.agent.protocol
import
Protocol
from
skywalking.trace.context
import
Segment
logger
=
logging
.
getLogger
(
__name__
)
class
Protocol
(
ABC
):
def
connected
(
self
):
raise
NotImplementedError
()
def
heartbeat
(
self
):
raise
NotImplementedError
()
def
report
(
self
,
queue
:
Queue
):
raise
NotImplementedError
()
def
__heartbeat
():
while
not
__finished
.
is_set
():
if
connected
():
...
...
@@ -63,7 +52,7 @@ __protocol: Protocol
def
init
():
if
config
.
protocol
==
'grpc'
:
from
skywalking.agent.grpc
import
GrpcProtocol
from
skywalking.agent.
protocol.
grpc
import
GrpcProtocol
global
__protocol
__protocol
=
GrpcProtocol
()
elif
config
.
protocol
==
'http'
:
...
...
skywalking/agent/protocol/__init__.py
0 → 100644
浏览文件 @
ecefb9b5
#
# 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
abc
import
ABC
from
queue
import
Queue
class
Protocol
(
ABC
):
def
connected
(
self
):
raise
NotImplementedError
()
def
heartbeat
(
self
):
raise
NotImplementedError
()
def
report
(
self
,
queue
:
Queue
):
raise
NotImplementedError
()
skywalking/agent/grpc/__init__.py
→
skywalking/agent/
protocol/
grpc/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -14,12 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import
logging
from
queue
import
Queue
import
grpc
from
language_agent.Tracing_pb2
import
SegmentObject
,
SpanObject
from
common.Common_pb2
import
KeyStringValuePair
from
language_agent.Tracing_pb2
import
SegmentObject
,
SpanObject
,
Log
from
skywalking
import
config
from
skywalking.agent
import
Protocol
from
skywalking.client.grpc
import
GrpcServiceManagementClient
,
GrpcTraceSegmentReportService
...
...
@@ -69,6 +71,11 @@ class GrpcProtocol(Protocol):
spanType
=
span
.
kind
.
name
,
spanLayer
=
span
.
layer
.
name
,
componentId
=
span
.
component
.
value
,
isError
=
span
.
error_occurred
,
logs
=
[
Log
(
time
=
int
(
log
.
timestamp
*
1000
),
data
=
[
KeyStringValuePair
(
key
=
item
.
key
,
value
=
item
.
val
)
for
item
in
log
.
items
],
)
for
log
in
span
.
logs
]
)
for
span
in
segment
.
spans
],
)
...
...
skywalking/agent/http/__init__.py
→
skywalking/agent/
protocol/
http/__init__.py
浏览文件 @
ecefb9b5
文件已移动
skywalking/decorators/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -15,9 +15,10 @@
# limitations under the License.
#
import
traceback
from
functools
import
wraps
from
skywalking
import
Layer
,
Component
from
skywalking
import
Layer
,
Component
,
Log
,
LogItem
from
skywalking.trace.context
import
get_context
...
...
@@ -34,7 +35,16 @@ def trace(
with
context
.
new_local_span
(
op
=
_op
)
as
span
:
span
.
layer
=
layer
span
.
component
=
component
return
func
(
*
args
,
**
kwargs
)
# noinspection PyBroadException
try
:
result
=
func
(
*
args
,
**
kwargs
)
return
result
except
:
span
.
error_occurred
=
True
span
.
logs
=
[
Log
(
items
=
[
LogItem
(
key
=
'Traceback'
,
val
=
traceback
.
format_exc
()),
])]
raise
return
wrapper
...
...
skywalking/loggings/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -21,5 +21,5 @@ import logging
def
init
():
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
'%(name)-
24
s [%(threadName)-15s] [%(levelname)-8s] %(message)s'
,
format
=
'%(name)-
32
s [%(threadName)-15s] [%(levelname)-8s] %(message)s'
,
)
skywalking/trace/context/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -122,12 +122,6 @@ _thread_local.context = None
def
get_context
()
->
SpanContext
:
if
_thread_local
.
context
is
not
None
:
return
_thread_local
.
context
if
not
agent
.
connected
():
_thread_local
.
context
=
NoopContext
()
else
:
_thread_local
.
context
=
SpanContext
()
_thread_local
.
context
=
_thread_local
.
context
or
(
SpanContext
()
if
agent
.
connected
()
else
NoopContext
())
return
_thread_local
.
context
skywalking/trace/segment/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -35,6 +35,5 @@ class Segment(object):
self
.
spans
.
append
(
span
)
class
SegmentRef
(
object
):
pass
skywalking/trace/span/__init__.py
浏览文件 @
ecefb9b5
...
...
@@ -77,7 +77,9 @@ class Span(ABC):
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
stop
()
return
self
if
exc_tb
is
not
None
:
return
False
return
True
@
tostring
...
...
tests/main.py
浏览文件 @
ecefb9b5
...
...
@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from
time
import
sleep
from
skywalking
import
agent
,
config
,
Component
,
Layer
...
...
@@ -24,16 +25,16 @@ if __name__ == '__main__':
config
.
init
(
collector
=
"127.0.0.1:11800"
,
service
=
'Python Service 1'
)
agent
.
init
()
agent
.
start
()
sleep
(
3
)
@
trace
()
def
test_decorator
():
sleep
(
1
)
@
trace
()
def
test_nested_decorator
():
test_decorator
()
sleep
(
3
)
for
_
in
range
(
1
,
20
):
...
...
@@ -46,21 +47,21 @@ if __name__ == '__main__':
s2
.
component
=
Component
.
Http
s2
.
layer
=
Layer
.
Http
print
(
s2
)
sleep
(
1
)
sleep
(
0.5
)
with
context
.
new_exit_span
(
op
=
'https://github.com/3'
,
peer
=
'127.0.0.1:80'
)
as
s3
:
s3
.
component
=
Component
.
Http
s3
.
layer
=
Layer
.
Http
print
(
s3
)
sleep
(
1
)
sleep
(
0.5
)
with
context
.
new_entry_span
(
op
=
'https://github.com/4'
)
as
s4
:
s4
.
component
=
Component
.
Http
s4
.
layer
=
Layer
.
Http
print
(
s4
)
sleep
(
1
)
sleep
(
0.5
)
with
context
.
new_exit_span
(
op
=
'https://github.com/5'
,
peer
=
'127.0.0.1:80'
)
as
s5
:
s5
.
component
=
Component
.
Http
s5
.
layer
=
Layer
.
Http
print
(
s5
)
sleep
(
1
)
sleep
(
1
)
sleep
(
0.5
)
sleep
(
0.5
)
print
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录