Context
General request context collection. Collects data points like thread ID, process ID, and so on, for common middleware usage.
API
# all params come with defaults
context(
namespace="service",
scope="all",
env="local",
sha="dev",
version="0.01",
context_fn=get_context,
getpid=os.getpid,
gettid=thread.get_ident,
)
Context:
v
- Logical product versionsha
- Physical source tree version (e.g. Git SHA)env
- Development environmentpid
- Process ID of current process running requesttid
- Thread ID of current thread running requestuid
- User ID for the current requestscope
- Scope, i.e. module namens
- Namespace, i.e. product namerid
- Request ID for correlationrid_p
- Parent request ID for correlation,
Usage
from formation.middleware import context
@client
class Google(object):
base_uri = "https://google.com"
middleware=[
context(
namespace="acme"
scope="billing"
)
]
...
Accessing context from your middleware:
from formation import _CONTEXT
def my_mware(mime_type):
def my_mware_middleware(ctx, call):
c = ctx.get(_CONTEXT)
print(c)
return call(ctx)
return my_mware_middleware