未验证 提交 0cf54f51 编写于 作者: K kezhenxu94

Fix bug and setup dist process

上级 ae179637
......@@ -4,3 +4,6 @@
*~
**/*_pb2*
__pycache__
build/
dist/
skywalking_python.egg-info/
include browser/*.py
include common/*.py
include language_agent/*.py
include management/*.py
include profile/*.py
include service_mesh_probe/*.py
\ No newline at end of file
......@@ -24,6 +24,12 @@ setup:
gen:
python3 -m grpc_tools.protoc -I protocol --python_out=. --grpc_python_out=. protocol/**/*.proto
touch browser/__init__.py
touch common/__init__.py
touch language_agent/__init__.py
touch management/__init__.py
touch profile/__init__.py
touch service_mesh_probe/__init__.py
lint: clean
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
......@@ -35,6 +41,9 @@ license: clean
test: gen
python3 -m unittest -v
install: gen
python3 setup.py install --force
clean:
rm -rf browser
rm -rf common
......
......@@ -15,32 +15,25 @@
# limitations under the License.
#
import inspect
from skywalking import Layer, Component
from skywalking.trace.context import get_context
def install():
from http.server import BaseHTTPRequestHandler
_handle = BaseHTTPRequestHandler.handle
def _sw_handle(this: BaseHTTPRequestHandler):
http_methods = ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH')
for method in http_methods:
if hasattr(this, 'do_' + method) and inspect.ismethod(getattr(this, 'do_' + method)):
_do_method = getattr(this, 'do_' + method)
def _sw_do_method():
context = get_context()
with context.new_entry_span(op=this.path) as span:
span.layer = Layer.Http
span.component = Component.Http
span.peer = '%s:%s' % this.client_address
_do_method()
setattr(this, 'do_' + method, _sw_do_method)
_handle(this)
BaseHTTPRequestHandler.handle = _sw_handle
import pathlib
from setuptools import setup, find_packages
HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
setup(
name="skywalking-python",
version="0.1.1",
description="Python Agent for Apache SkyWalking",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/SkyAPM/SkyAPM-python/",
author="Apache",
author_email="dev@skywalking.apache.org",
license="Apache 2.0",
packages=find_packages(exclude=("tests",)),
include_package_data=True,
install_requires=[],
)
......@@ -42,7 +42,7 @@ class Layer(Enum):
class Kind(Enum):
Local = 0
Entry = 1
Exit = 1
Exit = 2
@property
def is_local(self):
......
......@@ -28,6 +28,6 @@ def install():
logger.debug('installing plugin %s', modname)
plugin = importer.find_module(modname).load_module(modname)
if not hasattr(plugin, 'install') or inspect.ismethod(getattr(plugin, 'install')):
logger.warning('no `install` method in plugin %s, thus the plugin won\'t be installed')
logger.warning('no `install` method in plugin %s, thus the plugin won\'t be installed', modname)
continue
plugin.install()
#
# 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 logging
import traceback
from skywalking import Layer, Component
from skywalking.trace.context import get_context
logger = logging.getLogger(__name__)
def install():
# noinspection PyBroadException
try:
from http.server import BaseHTTPRequestHandler
_handle = BaseHTTPRequestHandler.handle
def _sw_handle(this: BaseHTTPRequestHandler):
http_methods = ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH')
for method in http_methods:
if hasattr(this, 'do_' + method) and inspect.ismethod(getattr(this, 'do_' + method)):
_do_method = getattr(this, 'do_' + method)
def _sw_do_method():
context = get_context()
with context.new_entry_span(op=this.path) as span:
span.layer = Layer.Http
span.component = Component.Http
span.peer = '%s:%s' % this.client_address
_do_method()
setattr(this, 'do_' + method, _sw_do_method)
_handle(this)
BaseHTTPRequestHandler.handle = _sw_handle
except Exception:
logger.warning('failed to install plugin %s', __name__)
traceback.print_exc()
......@@ -14,34 +14,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import logging
import traceback
from skywalking import Layer, Component
from skywalking.trace import tags
from skywalking.trace.context import get_context
from skywalking.trace.tags import Tag
logger = logging.getLogger(__name__)
def install():
from urllib.request import OpenerDirector
from urllib.error import HTTPError
# noinspection PyBroadException
try:
from urllib.request import OpenerDirector
from urllib.error import HTTPError
_open = OpenerDirector.open
_open = OpenerDirector.open
def _sw_open(this: OpenerDirector, fullurl, data, timeout):
context = get_context()
with context.new_exit_span(op=fullurl.selector, peer=fullurl.host) as span:
span.layer = Layer.Http
span.component = Component.Http
try:
res = _open(this, fullurl, data, timeout)
span.tag(Tag(key=tags.HttpMethod, val=fullurl.get_method()))
span.tag(Tag(key=tags.HttpUrl, val=fullurl.full_url))
span.tag(Tag(key=tags.HttpStatus, val=res.code))
if res.code >= 400:
span.error_occurred = True
except HTTPError as e:
span.raised()
raise e
return res
def _sw_open(this: OpenerDirector, fullurl, data, timeout):
context = get_context()
with context.new_exit_span(op=fullurl.selector, peer=fullurl.host) as span:
span.layer = Layer.Http
span.component = Component.Http
try:
res = _open(this, fullurl, data, timeout)
span.tag(Tag(key=tags.HttpMethod, val=fullurl.get_method()))
span.tag(Tag(key=tags.HttpUrl, val=fullurl.full_url))
span.tag(Tag(key=tags.HttpStatus, val=res.code))
if res.code >= 400:
span.error_occurred = True
except HTTPError as e:
span.raised()
raise e
return res
OpenerDirector.open = _sw_open
OpenerDirector.open = _sw_open
except Exception:
logger.warning('failed to install plugin %s', __name__)
traceback.print_exc()
......@@ -18,6 +18,7 @@
from collections import namedtuple
Tag = namedtuple('Tag', 'key val overridable')
Tag.__new__.__defaults__ = (None, None, False)
HttpUrl = 'url'
HttpMethod = 'http.method'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册