Http tracing middleware for chocs library.
Project description
Chocs-Trace
Http tracing middleware for chocs library.
Installation
Poetry:
poetry add chocs-middleware.trace
Pip:
pip install chocs-middleware.trace
Usage
Support tracing in your responses
from chocs_middleware.trace import TraceMiddleware
from chocs import Application, HttpRequest, HttpResponse
# id_prefix will ensure generated tracing headers to contain your prefix
app = Application(TraceMiddleware(id_prefix="service-name-"))
@app.get("/hello")
def say_hello(req: HttpRequest) -> HttpResponse:
return HttpResponse("Hello!") # tracing middleware will automatically attach x-request-id, x-correlation-id, x-causation-id headers to your response
Tracing requests
from chocs_middleware.trace import TraceMiddleware, HttpStrategy
from chocs import Application, HttpRequest, HttpResponse
import requests
# http_strategy will try to detect requests library and use it to add tracing headers in all your requests
# if it fails to detect requests library it will fallback to urllib3
app = Application(TraceMiddleware(http_strategy=HttpStrategy.AUTO))
@app.get("/hello")
def say_hello(req: HttpRequest) -> HttpResponse:
requests.get("http://example.com/test") # middleware will automatically attach x-correlation-id, x-causation-id and x-request-id headers to your request
return HttpResponse("Hello!")
Using logger
Formatting message
Available properties
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
Close
Hashes for chocs_middleware.trace-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | da1fd7443631c21ec244e40e7721750add943d5b35e1ef43689c7bbd45bf109d |
|
MD5 | 58d745c5a1576a92ebc1b7920edb7927 |
|
BLAKE2b-256 | 6df0e7cfe26cc437e69ad06b349e157929ce2c14676dee1e64310c1e8b2453b7 |