Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions skywalking/trace/span/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def raised(self) -> 'Span':
])]
return self

def log(self, ex: Exception) -> 'Span':
self.error_occurred = True
self.logs.append(Log(items=LogItem(key='Traceback', val=str(ex))))
return self

def tag(self, tag: Tag) -> 'Span':
if not tag.overridable:
self.tags.append(deepcopy(tag))
Expand Down
16 changes: 14 additions & 2 deletions tests/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import inspect
import os
import unittest
from abc import ABC
from collections import namedtuple
from os.path import dirname

import requests
from requests import Response
Expand All @@ -31,6 +32,13 @@
class BasePluginTest(unittest.TestCase, ABC):
compose = None # type: DockerCompose

@classmethod
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(inspect.getfile(cls)))
cls.compose.start()

cls.compose.wait_for(cls.url(cls.collector_address()))

@classmethod
def tearDownClass(cls):
cls.compose.stop()
Expand All @@ -57,8 +65,12 @@ def collector_address(cls):
# type: () -> ServicePort
return ServicePort(service='collector', port='12800')

def validate(self, expected_file_name):
def validate(self, expected_file_name=None):
# type: (str) -> Response

if expected_file_name is None:
expected_file_name = os.path.join(dirname(inspect.getfile(self.__class__)), 'expected.data.yml')

with open(expected_file_name) as expected_data_file:
response = requests.post(
url=self.__class__.url(self.__class__.collector_address(), path='/dataValidate'),
Expand Down
11 changes: 5 additions & 6 deletions tests/plugin/sw_flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import inspect
import time
import unittest
from os.path import abspath, dirname
from os.path import dirname

from testcontainers.compose import DockerCompose

Expand All @@ -28,15 +27,15 @@
class TestPlugin(BasePluginTest):
@classmethod
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
cls.compose = DockerCompose(filepath=dirname(inspect.getfile(cls)))
cls.compose.start()

cls.compose.wait_for(cls.url(('consumer', '9090'), 'users'))

def test_request_plugin(self):
def test_plugin(self):
time.sleep(3)

self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
self.validate()


if __name__ == '__main__':
Expand Down
13 changes: 2 additions & 11 deletions tests/plugin/sw_http/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,22 @@
# limitations under the License.
#

import os
import time
import unittest
from os.path import abspath, dirname

import requests
from testcontainers.compose import DockerCompose

from tests.plugin import BasePluginTest


class TestPlugin(BasePluginTest):
@classmethod
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
cls.compose.start()

cls.compose.wait_for(cls.url(cls.collector_address()))

def test_request_plugin(self):
def test_plugin(self):
print('traffic: ', requests.post(url=self.url(('consumer', '9090'))))

time.sleep(3)

self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
self.validate()


if __name__ == '__main__':
Expand Down
13 changes: 2 additions & 11 deletions tests/plugin/sw_http_wsgi/test_http_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,22 @@
# limitations under the License.
#

import os
import time
import unittest
from os.path import abspath, dirname

import requests
from testcontainers.compose import DockerCompose

from tests.plugin import BasePluginTest


class TestPlugin(BasePluginTest):
@classmethod
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
cls.compose.start()

cls.compose.wait_for(cls.url(cls.collector_address()))

def test_request_plugin(self):
def test_plugin(self):
print('traffic: ', requests.post(url=self.url(('consumer', '9090'))))

time.sleep(3)

self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
self.validate()


if __name__ == '__main__':
Expand Down
13 changes: 2 additions & 11 deletions tests/plugin/sw_requests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,22 @@
# limitations under the License.
#

import os
import time
import unittest
from os.path import abspath, dirname

import requests
from testcontainers.compose import DockerCompose

from tests.plugin import BasePluginTest


class TestPlugin(BasePluginTest):
@classmethod
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))
cls.compose.start()

cls.compose.wait_for(cls.url(cls.collector_address()))

def test_request_plugin(self):
def test_plugin(self):
print('traffic: ', requests.post(url=self.url(('consumer', '9090'))))

time.sleep(3)

self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml'))
self.validate()


if __name__ == '__main__':
Expand Down