Zipkin tracing for nameko framework
Project description
emplocity-nameko-zipkin
Zipkin tracing for nameko framework
Install
pip install emplocity-nameko-zipkin
Usage
Services
from nameko_zipkin import Zipkin
from nameko.rpc import rpc
class Service:
name = 'service'
zipkin = Zipkin() # Dependency provider injects py_zipkin.zipkin.zipkin_span object
@rpc
def method(self):
assert self.zipkin.service_name == Service.name
assert self.zipkin.span_name == Service.method.__name__
Standalone rpc
from py_zipkin import zipkin
from nameko_zipkin import monkey_patch
from nameko_zipkin.transport import HttpHandler
from nameko.standalone.rpc import ClusterRpcProxy
handler = HttpHandler('http://localhost:9411/api/v1/spans').handle
monkey_patch(handler)
with zipkin.zipkin_server_span('RootService',
'RootMethod',
sample_rate=100.,
transport_handler=handler):
with ClusterRpcProxy({'AMQP_URI': "pyamqp://guest:guest@localhost"}) as proxy:
proxy.service.method()
How it works
- monkey_patch patches MethodProxy class to initialize a client span, it's called in dependency provider setup method
- On service method call a server span is created
- Trace parameters (trace_id, parent_span_id, etc.) are passed through context data and are accessible in py_zipkin.thread_local.get_zipkin_attrs
- If there are no parameters, request isn't traced
- Child service calls are also supported
- Trace results are reported through handler classes in nameko_zipkin.transport
Configuration
ZIPKIN section must be added to nameko service config.yaml
ZIPKIN:
HANDLER: HttpHandler
HANDLER_PARAMS:
url: http://localhost:9411/api/v1/spans
Test it out locally
We've provided an example docker-compose based stack that includes a nameko
service and a Zipkin instance. To try it out, run docker-compose up
in the
root directory of the project. This will bring up three services: RabbitMQ
(required by nameko), Zipkin, and an example Python service with both RPC
and HTTP endpoints.
Navigate to http://localhost:8000 to visit the example service, and if you then visit Zipkin dashboard (typically at http://localhost:9411), you should see some traces there!
Planned changes
- Kafka transport support
- Custom handlers support in config.yaml ('my_module.MyHandler')
Project details
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
File details
Details for the file emplo-nameko-zipkin-0.1.8.tar.gz
.
File metadata
- Download URL: emplo-nameko-zipkin-0.1.8.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d335397c590702b25a5594abf08593822b232f5543ba1a93a3af6b406501bac5 |
|
MD5 | f5242a13ace3ac79b6f4591fd9f79149 |
|
BLAKE2b-256 | 175928a117639f96a7d0a2ab6b12933e5a5c0beb7e80235f23c6c9b193fb27a7 |
File details
Details for the file emplo_nameko_zipkin-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: emplo_nameko_zipkin-0.1.8-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f26c0bf34cbcebf50301020c766a7ed3a262ab77b6577e8f5fd6752fbd855da |
|
MD5 | e497289f2fceffc54b83999abfed42ba |
|
BLAKE2b-256 | 4a0029efcdfbdb5b51590a2a745046b0f471b6ccaa3117ec95c31afacdda386a |