Beispiel #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import opentracing.ext.tags as ext
from flask import Flask, redirect
from instana.wsgi import iWSGIMiddleware
from wsgiref.simple_server import make_server
from instana.singletons import tracer

app = Flask(__name__)
app.debug = False
app.use_reloader = False

wsgi_app = iWSGIMiddleware(app.wsgi_app)
flask_server = make_server('127.0.0.1', 5000, wsgi_app)


@app.route("/")
def hello():
    return "<center><h1>🐍 Hello Stan! 🦄</h1></center>"


@app.route("/complex")
def gen_opentracing():
    with tracer.start_active_span('asteroid') as pscope:
        pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
        pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
        pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
        pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
        pscope.span.set_tag(ext.HTTP_METHOD, "GET")
        pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
        pscope.span.log_kv({"foo": "bar"})
Beispiel #2
0
    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")


# 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)
logging.getLogger('spyne.interface._base').setLevel(logging.WARN)
logging.getLogger('spyne.interface.xml').setLevel(logging.WARN)
logging.getLogger('spyne.util.appreg').setLevel(logging.WARN)

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', testenv["soap_port"], wsgi_app)

if __name__ == '__main__':
    soapserver.serve_forever()
Beispiel #3
0
def wrapper(wrapped, instance, args, kwargs):
    rv = wrapped(*args, **kwargs)
    instance.wsgi_app = wsgi.iWSGIMiddleware(instance.wsgi_app)
    return rv
# other things) that you think in terms of resources and state
# transitions, which map to HTTP verbs.


class ThingsResource(object):

    def on_get(self, req, resp):

        with ot.tracer.start_active_span('universe') as escope:
            escope.span.set_tag('http.method', 'GET')
            escope.span.set_tag('http.url', '/things')
            escope.span.set_tag('span.kind', 'entry')
            """Handles GET requests"""
            resp.status = falcon.HTTP_200  # This is the default status
            resp.body = ('\nTwo things awe me most, the starry sky '
                         'above me and the moral law within me.\n'
                         '\n'
                         '    ~ Immanuel Kant\n\n')


# falcon.API instances are callable WSGI apps
app = falcon.API()

# Resources are represented by long-lived class instances
things = ThingsResource()

# things will handle all requests to the '/things' URL path
app.add_route('/things', things)

wsgiapp = iWSGIMiddleware((ThingsResource()))