-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add background Soap server to test suite. * Better exception capture & logging in metric thread * Initial suds-jurko instrumentation * Basic Soap request tests. * Add SoapData section; Add soap as registered span * Cleanup and organize package dependencies * New test dependencies for Travis * Version sensitive class & method * Add requests to test bundle * Remove unicode characters; silence spyne logging * Exception & fault logging plus tests * Move exception logging out to span * Python 2 <-> 3 compatibility change * Moar HTTP tags. * Remove debug remnant and fix logger call
- Loading branch information
1 parent
d64d14d
commit abac9cb
Showing
14 changed files
with
407 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import absolute_import | ||
import instana | ||
from instana.log import logger | ||
import opentracing | ||
import opentracing.ext.tags as ext | ||
import wrapt | ||
|
||
|
||
try: | ||
import suds # noqa | ||
|
||
if (suds.version.__version__ <= '0.6'): | ||
class_method = 'SoapClient.send' | ||
else: | ||
class_method = '_SoapClient.send' | ||
|
||
@wrapt.patch_function_wrapper('suds.client', class_method) | ||
def send_with_instana(wrapped, instance, args, kwargs): | ||
context = instana.internal_tracer.current_context() | ||
|
||
# If we're not tracing, just return | ||
if context is None: | ||
return wrapped(*args, **kwargs) | ||
|
||
try: | ||
span = instana.internal_tracer.start_span("soap", child_of=context) | ||
span.set_tag('soap.action', instance.method.name) | ||
span.set_tag(ext.HTTP_URL, instance.method.location) | ||
span.set_tag(ext.HTTP_METHOD, 'POST') | ||
|
||
instana.internal_tracer.inject(span.context, opentracing.Format.HTTP_HEADERS, | ||
instance.options.headers) | ||
|
||
rv = wrapped(*args, **kwargs) | ||
|
||
except Exception as e: | ||
span.log_exception(e) | ||
span.set_tag(ext.HTTP_STATUS_CODE, 500) | ||
raise | ||
else: | ||
span.set_tag(ext.HTTP_STATUS_CODE, 200) | ||
return rv | ||
finally: | ||
span.finish() | ||
|
||
logger.debug("Instrumenting suds-jurko") | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# See setup.py for dependencies | ||
-e .[test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
fysom>=2.1.2 | ||
opentracing>=1.2.1 | ||
basictracer>=2.2.0 | ||
autowrapt>=1.0 | ||
# See setup.py for dependencies | ||
-e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup(name='instana', | ||
version='0.7.12', | ||
download_url='https://github.com/instana/python-sensor', | ||
url='https://www.instana.com/', | ||
license='MIT', | ||
author='Instana Inc.', | ||
author_email='[email protected]', | ||
description='Metrics sensor and trace collector for Instana', | ||
packages=find_packages(exclude=['tests', 'examples']), | ||
long_description="The instana package provides Python metrics and traces for Instana.", | ||
zip_safe=False, | ||
setup_requires=['nose>=1.0', 'flask>=0.12.2'], | ||
install_requires=['autowrapt>=1.0', | ||
'fysom>=2.1.2', | ||
'opentracing>=1.2.1,<1.3', | ||
'basictracer>=2.2.0'], | ||
entry_points={'django': ['django.core.handlers.base = instana.django:hook'], | ||
'django19': ['django.core.handlers.base = instana.django:hook19'], | ||
'flask': ['flask = instana.flaskana:hook'], | ||
'runtime': ['string = instana.runtime:hook']}, | ||
test_suite='nose.collector', | ||
keywords=['performance', 'opentracing', 'metrics', 'monitoring'], | ||
classifiers=[ | ||
version='0.7.12', | ||
download_url='https://github.com/instana/python-sensor', | ||
url='https://www.instana.com/', | ||
license='MIT', | ||
author='Instana Inc.', | ||
author_email='[email protected]', | ||
description='Metrics sensor and trace collector for Instana', | ||
packages=find_packages(exclude=['tests', 'examples']), | ||
long_description="The instana package provides Python metrics and traces for Instana.", | ||
zip_safe=False, | ||
install_requires=['autowrapt>=1.0', | ||
'fysom>=2.1.2', | ||
'opentracing>=1.2.1,<1.3', | ||
'basictracer>=2.2.0'], | ||
entry_points={'django': ['django.core.handlers.base = instana.django:hook'], | ||
'django19': ['django.core.handlers.base = instana.django:hook19'], | ||
'flask': ['flask = instana.flaskana:hook'], | ||
'runtime': ['string = instana.runtime:hook']}, | ||
extras_require={ | ||
'test': [ | ||
'nose>=1.0', | ||
'flask>=0.12.2', | ||
'requests>=2.17.1', | ||
'spyne>=2.9', | ||
'lxml>=3.4', | ||
'suds-jurko>=0.6' | ||
], | ||
}, | ||
test_suite='nose.collector', | ||
keywords=['performance', 'opentracing', 'metrics', 'monitoring'], | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Framework :: Django', | ||
'Framework :: Flask', | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# vim: set fileencoding=UTF-8 : | ||
import logging | ||
from spyne import Application, rpc, ServiceBase, Iterable, Integer, Unicode, Fault | ||
from spyne.protocol.soap import Soap11 | ||
from spyne.server.wsgi import WsgiApplication | ||
from wsgiref.simple_server import make_server | ||
from instana.wsgi import iWSGIMiddleware | ||
|
||
# Simple in test suite SOAP server to test suds client instrumentation against. | ||
# Configured to listen on localhost port 4132 | ||
# WSDL: http://localhost:4232/?wsdl | ||
|
||
class StanSoapService(ServiceBase): | ||
@rpc(Unicode, Integer, _returns=Iterable(Unicode)) | ||
def ask_question(ctx, question, answer): | ||
"""Ask Stan a question! | ||
<b>Ask Stan questions as a Service</b> | ||
@param name the name to say hello to | ||
@param times the number of times to say hello | ||
@return the completed array | ||
""" | ||
|
||
yield u'To an artificial mind, all reality is virtual. How do they know that the real world isn\'t just another simulation? How do you?' | ||
|
||
|
||
@rpc() | ||
def server_exception(ctx): | ||
raise Exception("Server side exception example.") | ||
|
||
@rpc() | ||
def server_fault(ctx): | ||
raise Fault("Server", "Server side fault example.") | ||
|
||
@rpc() | ||
def client_fault(ctx): | ||
raise Fault("Client", "Client side fault example") | ||
|
||
|
||
|
||
app = Application([StanSoapService], 'instana.tests.app.ask_question', | ||
in_protocol=Soap11(validator='lxml'), out_protocol=Soap11()) | ||
|
||
# Use Instana middleware so we can test context passing and Soap server traces. | ||
wsgi_app = iWSGIMiddleware(WsgiApplication(app)) | ||
soapserver = make_server('127.0.0.1', 4132, wsgi_app) | ||
|
||
logging.basicConfig(level=logging.WARN) | ||
logging.getLogger('suds').setLevel(logging.WARN) | ||
logging.getLogger('suds.resolver').setLevel(logging.WARN) | ||
logging.getLogger('spyne.protocol.xml').setLevel(logging.WARN) | ||
logging.getLogger('spyne.model.complex').setLevel(logging.WARN) | ||
|
||
if __name__ == '__main__': | ||
soapserver.serve_forever() |
Oops, something went wrong.