Connexion with benefits for microservices
Project description
Connexion with benefits for microservices.
Connexion Plus
If you want to use Connexion for your microservice, you have to add an opentracing or prometheus client on your own. With this library, you instantiate everything before your connexion app starts and this library will take care to put it all together, so you get everything fine.
If you want to know more about the used libraries, please go to the corresponding documentaries.
Dependencies
[Connexion](https://github.com/zalando/connexion)
[opentracing-python-instrumentation](https://github.com/uber-common/opentracing-python-instrumentation)
[Flask-Opentracing](https://github.com/opentracing-contrib/python-flask)
[jaeger-client](https://pypi.org/project/jaeger-client/)
[requests](https://pypi.org/project/requests/)
[prometheus-flask-exporter](https://pypi.org/project/prometheus-flask-exporter/)
Importing
import connexion_plus as conn
OpenTracing / Jaeger-Client
Currently, all opentracing implementation (e.g. jaeger-client) are supported for tracing. If you want to use it, you have to initialize the client before you start your connexion app and give it via the tracer
-parameter to the connexion_plus
Factory, where the magic happens.
The following example uses jaeger-client (pip install jaeger-client
) implementation.
import connexion_plus as conn
from jaeger_client import Config as jConfig
config = jConfig(
config={
'logging': True,
},
)
jaeger_tracer = config.initialize_tracer()
app = connexion.App(__name__)
conn.addServices(app, use_tracer=jaeger_tracer)
Prometheus / Metrics
Currently, it is only the prometheus-flask-exporter supported for connexion, so only for flask connexion. You only have to set the metrics
-parameter to True
import connexion_plus
app = connexion.App(__name__)
conn.addServices(app, use_metric=True)
Example
If you want to use tracer
and metrics
together, see here a complete example. This currently works only with flask (see prometheus)
import connexion_plus
from jaeger_client import Config as jConfig
from jaeger_client.metrics.prometheus import PrometheusMetricsFactory
config = jConfig(
config={
'logging': True,
},
# use this, if you want to track your tracing itself with prometheus
metrics_factory = PrometheusMetricsFactory(namespace=name),
)
jaeger_tracer = config.initialize_tracer()
app = connexion.App(__name__)
conn.addServices(app, use_tracer=jaeger_tracer, use_metric=True)
If you add the line metrics_factory=PrometheusMetricsFactory(namespace='yourAppName')
to your jaeger-client-config, you get the metrics out of jaeger to your flask app.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for connexion_plus-0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20c1e678ed7bc85ea2d7e223e32321ded0e52467143bf3ff7b2229a065289eb9 |
|
MD5 | cf2e861729bd76bcc336793f5646f106 |
|
BLAKE2b-256 | 8311445c38884bcbcb4ec7184d181208d539aeefd5e5d51e72d04df56f17eda8 |