Skip to content

Commit 8b44f0e

Browse files
committed
[Plugin] added pyramid plugin
1 parent 65c6e4a commit 8b44f0e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ py==1.9.0
3838
pymongo==3.11.0
3939
PyMySQL==0.10.0
4040
pyparsing==2.4.7
41+
pyramid==1.10.5
4142
pytest==6.0.1
4243
pytz==2020.1
4344
PyYAML==5.3.1

skywalking/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Component(Enum):
3939
Urllib3 = 7006
4040
Sanic = 7007
4141
AioHttp = 7008
42+
Pyramid = 7009
4243

4344

4445
class Layer(Enum):

skywalking/plugins/sw_pyramid.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from skywalking import Layer, Component
19+
from skywalking.trace import tags
20+
from skywalking.trace.carrier import Carrier
21+
from skywalking.trace.context import get_context
22+
from skywalking.trace.tags import Tag
23+
24+
25+
def install():
26+
from pyramid.router import Router
27+
28+
def _sw_invoke_request(self, request, *args, **kwargs):
29+
context = get_context()
30+
carrier = Carrier()
31+
32+
for item in carrier:
33+
val = request.headers.get(item.key)
34+
35+
if val is not None:
36+
item.val = val
37+
38+
with context.new_entry_span(op=request.path, carrier=carrier) as span:
39+
span.layer = Layer.Http
40+
span.component = Component.Pyramid
41+
span.peer = request.remote_host or request.remote_addr
42+
43+
span.tag(Tag(key=tags.HttpMethod, val=request.method))
44+
span.tag(Tag(key=tags.HttpUrl, val=str(request.url)))
45+
46+
resp = _invoke_request(self, request, *args, **kwargs)
47+
48+
span.tag(Tag(key=tags.HttpStatus, val=resp.status_code, overridable=True))
49+
50+
if resp.status_code >= 400:
51+
span.error_occurred = True
52+
53+
return resp
54+
55+
_invoke_request = Router.invoke_request
56+
Router.invoke_request = _sw_invoke_request

0 commit comments

Comments
 (0)