Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
skywalking-python
提交
43987a56
S
skywalking-python
项目概览
apache
/
skywalking-python
通知
61
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,发现更多精彩内容 >>
未验证
提交
43987a56
编写于
7月 18, 2020
作者:
H
Humbertzhang
提交者:
GitHub
7月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add plugin for Django Agent (#37)
上级
38d93b30
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
404 addition
and
0 deletion
+404
-0
skywalking/__init__.py
skywalking/__init__.py
+1
-0
skywalking/plugins/sw_django/__init__.py
skywalking/plugins/sw_django/__init__.py
+72
-0
tests/plugin/sw_django/__init__.py
tests/plugin/sw_django/__init__.py
+16
-0
tests/plugin/sw_django/docker-compose.yml
tests/plugin/sw_django/docker-compose.yml
+60
-0
tests/plugin/sw_django/expected.data.yml
tests/plugin/sw_django/expected.data.yml
+91
-0
tests/plugin/sw_django/services/__init__.py
tests/plugin/sw_django/services/__init__.py
+16
-0
tests/plugin/sw_django/services/consumer.py
tests/plugin/sw_django/services/consumer.py
+53
-0
tests/plugin/sw_django/services/provider.py
tests/plugin/sw_django/services/provider.py
+53
-0
tests/plugin/sw_django/test_django.py
tests/plugin/sw_django/test_django.py
+42
-0
未找到文件。
skywalking/__init__.py
浏览文件 @
43987a56
...
...
@@ -27,6 +27,7 @@ class Component(Enum):
Flask
=
7001
Requests
=
7002
PyMysql
=
7003
Django
=
7004
class
Layer
(
Enum
):
...
...
skywalking/plugins/sw_django/__init__.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
import
logging
from
skywalking
import
Layer
,
Component
from
skywalking.trace
import
tags
from
skywalking.trace.carrier
import
Carrier
from
skywalking.trace.context
import
get_context
from
skywalking.trace.tags
import
Tag
logger
=
logging
.
getLogger
(
__name__
)
def
install
():
try
:
from
django.core.handlers.base
import
BaseHandler
from
django.core.handlers
import
exception
_get_response
=
BaseHandler
.
get_response
_handle_uncaught_exception
=
exception
.
handle_uncaught_exception
def
_sw_get_response
(
this
:
BaseHandler
,
request
):
if
request
is
None
:
resp
=
_get_response
(
this
,
request
)
return
resp
context
=
get_context
()
carrier
=
Carrier
()
for
item
in
carrier
:
if
item
.
key
.
capitalize
()
in
request
.
headers
:
item
.
val
=
request
.
headers
[
item
.
key
.
capitalize
()]
with
context
.
new_entry_span
(
op
=
request
.
path
,
carrier
=
carrier
)
as
span
:
span
.
layer
=
Layer
.
Http
span
.
component
=
Component
.
Django
span
.
peer
=
'%s:%s'
%
(
request
.
META
.
get
(
'REMOTE_ADDR'
),
request
.
META
.
get
(
'REMOTE_PORT'
)
or
"80"
)
span
.
tag
(
Tag
(
key
=
tags
.
HttpMethod
,
val
=
request
.
method
))
span
.
tag
(
Tag
(
key
=
tags
.
HttpUrl
,
val
=
request
.
build_absolute_uri
()))
resp
=
_get_response
(
this
,
request
)
span
.
tag
(
Tag
(
key
=
tags
.
HttpStatus
,
val
=
resp
.
status_code
))
if
resp
.
status_code
>=
400
:
span
.
error_occurred
=
True
return
resp
def
_sw_handle_uncaught_exception
(
request
,
resolver
,
exc_info
):
if
exc_info
is
not
None
:
entry_span
=
get_context
().
active_span
()
if
entry_span
is
not
None
:
entry_span
.
raised
()
return
_handle_uncaught_exception
(
request
,
resolver
,
exc_info
)
BaseHandler
.
get_response
=
_sw_get_response
exception
.
handle_uncaught_exception
=
_sw_handle_uncaught_exception
except
Exception
:
logger
.
warning
(
'failed to install plugin %s'
,
__name__
)
tests/plugin/sw_django/__init__.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
tests/plugin/sw_django/docker-compose.yml
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
version
:
'
2.1'
services
:
collector
:
extends
:
service
:
collector
file
:
../docker/docker-compose.base.yml
provider
:
extends
:
service
:
agent
file
:
../docker/docker-compose.base.yml
ports
:
-
9091:9091
volumes
:
-
./services/provider.py:/app/provider.py
command
:
[
'
bash'
,
'
-c'
,
'
pip
install
django
&&
python3
/app/provider.py
runserver
0.0.0.0:9091'
]
depends_on
:
collector
:
condition
:
service_healthy
healthcheck
:
test
:
[
"
CMD"
,
"
bash"
,
"
-c"
,
"
cat
<
/dev/null
>
/dev/tcp/127.0.0.1/9091"
]
interval
:
5s
timeout
:
60s
retries
:
120
consumer
:
extends
:
service
:
agent
file
:
../docker/docker-compose.base.yml
ports
:
-
9090:9090
volumes
:
-
./services/consumer.py:/app/consumer.py
command
:
[
'
bash'
,
'
-c'
,
'
pip
install
django
&&
python3
/app/consumer.py
runserver
0.0.0.0:9090'
]
depends_on
:
collector
:
condition
:
service_healthy
provider
:
condition
:
service_healthy
networks
:
beyond
:
tests/plugin/sw_django/expected.data.yml
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
segmentItems
:
-
serviceName
:
provider
segmentSize
:
1
segments
:
-
segmentId
:
not
null
spans
:
-
operationName
:
/users
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
Http
tags
:
-
key
:
http.method
value
:
POST
-
key
:
url
value
:
http://provider:9091/users
-
key
:
status.code
value
:
'
200'
refs
:
-
parentEndpoint
:
/users
networkAddress
:
provider:9091
refType
:
CrossProcess
parentSpanId
:
1
parentTraceSegmentId
:
not
null
parentServiceInstance
:
not
null
parentService
:
consumer
traceId
:
not
null
startTime
:
gt
0
endTime
:
gt
0
componentId
:
7004
spanType
:
Entry
peer
:
not
null
skipAnalysis
:
false
-
serviceName
:
consumer
segmentSize
:
1
segments
:
-
segmentId
:
not
null
spans
:
-
operationName
:
/users
operationId
:
0
parentSpanId
:
0
spanId
:
1
spanLayer
:
Http
tags
:
-
key
:
http.method
value
:
POST
-
key
:
url
value
:
http://provider:9091/users
-
key
:
status.code
value
:
'
200'
startTime
:
gt
0
endTime
:
gt
0
componentId
:
7002
spanType
:
Exit
peer
:
provider:9091
skipAnalysis
:
false
-
operationName
:
/users
operationId
:
0
parentSpanId
:
-1
spanId
:
0
spanLayer
:
Http
tags
:
-
key
:
http.method
value
:
GET
-
key
:
url
value
:
http://0.0.0.0:9090/users
-
key
:
status.code
value
:
'
200'
startTime
:
gt
0
endTime
:
gt
0
componentId
:
7004
spanType
:
Entry
peer
:
not
null
skipAnalysis
:
false
\ No newline at end of file
tests/plugin/sw_django/services/__init__.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
tests/plugin/sw_django/services/consumer.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
import
sys
import
requests
from
skywalking
import
agent
,
config
from
django.conf
import
settings
from
django.conf.urls
import
url
from
django.http
import
JsonResponse
config
.
service_name
=
"consumer"
config
.
logging_level
=
"DEBUG"
agent
.
start
()
settings
.
configure
(
DEBUG
=
True
,
ROOT_URLCONF
=
__name__
,
ALLOWED_HOSTS
=
[
'*'
],
)
def
index
(
request
):
res
=
requests
.
post
(
"http://provider:9091/users"
)
return
JsonResponse
(
res
.
json
())
urlpatterns
=
(
url
(
'users'
,
index
),
)
if
__name__
==
"__main__"
:
from
django.core.management
import
execute_from_command_line
execute_from_command_line
(
sys
.
argv
)
tests/plugin/sw_django/services/provider.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
import
sys
import
time
from
skywalking
import
agent
,
config
from
django.conf
import
settings
from
django.conf.urls
import
url
from
django.http
import
JsonResponse
config
.
service_name
=
"provider"
config
.
logging_level
=
"DEBUG"
agent
.
start
()
settings
.
configure
(
DEBUG
=
True
,
ROOT_URLCONF
=
__name__
,
ALLOWED_HOSTS
=
[
'*'
],
)
def
index
(
request
):
time
.
sleep
(
0.5
)
return
JsonResponse
({
"song"
:
"Despacito"
,
"artist"
:
"Luis Fonsi"
})
urlpatterns
=
(
url
(
"users"
,
index
),
)
if
__name__
==
"__main__"
:
from
django.core.management
import
execute_from_command_line
execute_from_command_line
(
sys
.
argv
)
tests/plugin/sw_django/test_django.py
0 → 100644
浏览文件 @
43987a56
#
# 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.
#
import
inspect
import
time
import
unittest
from
os.path
import
dirname
from
testcontainers.compose
import
DockerCompose
from
tests.plugin
import
BasePluginTest
class
TestPlugin
(
BasePluginTest
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
compose
=
DockerCompose
(
filepath
=
dirname
(
inspect
.
getfile
(
cls
)))
cls
.
compose
.
start
()
cls
.
compose
.
wait_for
(
cls
.
url
((
'consumer'
,
'9090'
),
'users'
))
def
test_plugin
(
self
):
time
.
sleep
(
3
)
self
.
validate
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录