Karma Trace Logging SDK
ktools-python/ktrace/README.mdktrace is the Python tracing and operational logging layer for the ktools
ecosystem.
It follows the same high-level model as the C++ implementation:
- library-facing
TraceLoggersources with named channels - executable-facing
Loggerruntime state for selector enablement and output kcliintegration throughlogger.makeInlineParser(...)- developer/operator output rather than end-user UI text
Documentation
Build SDK
Build from the ktools-python/ workspace root with the shared build tool:
python3 ../kbuild/kbuild.py --batch ktrace --build-latest
If kbuild is already on your PATH, the equivalent command is:
kbuild --batch ktrace --build-latest
SDK output:
build/latest/sdk/python/ktracebuild/latest/sdk/lib/cmake/KtraceSDK
Build And Test Demos
python3 -m unittest discover -s tests
python3 -m unittest discover -s demo/tests
Demo entrypoints from this repo root:
python3 demo/bootstrap/main.py --trace '.*'
python3 demo/exe/core/main.py --trace '*.*'
python3 demo/exe/omega/main.py --trace '*.{net,io}'
Trace CLI examples:
python3 demo/exe/core/main.py --trace '.*'
python3 demo/exe/omega/main.py --trace '*.*'
python3 demo/exe/omega/main.py --trace '*.{net,io}'
python3 demo/exe/omega/main.py --trace-namespaces
python3 demo/exe/omega/main.py --trace-channels
python3 demo/exe/omega/main.py --trace-colors
API Model
TraceLogger is the namespace-bearing source object:
import ktrace
trace = ktrace.TraceLogger("alpha")
trace.addChannel("net", ktrace.Color("DeepSkyBlue1"))
trace.addChannel("cache", ktrace.Color("Gold3"))
SDK-style Python modules will usually expose one shared trace source through a module-level helper:
_TRACE_LOGGER: ktrace.TraceLogger | None = None
def get_trace_logger() -> ktrace.TraceLogger:
global _TRACE_LOGGER
if _TRACE_LOGGER is not None:
return _TRACE_LOGGER
trace = ktrace.TraceLogger("alpha")
trace.addChannel("net", ktrace.Color("DeepSkyBlue1"))
_TRACE_LOGGER = trace
return _TRACE_LOGGER
Logger owns the runtime registry, selector state, and formatting:
logger = ktrace.Logger()
logger.addTraceLogger(trace)
logger.enableChannels("alpha.*")
Behavior Highlights
- trace output is channel-gated and disabled by default
info(),warn(), anderror()are always visible once the trace source is attached to aLogger- selector matching supports local selectors, namespace-qualified selectors,
wildcard segments inside qualified selectors such as
*.*, and brace sets such as*.{net,io} - bare
*is rejected; use a qualified selector such as.*or*.* - unmatched selectors produce warning output instead of raising
- conflicting explicit channel-color merges are rejected when trace sources are attached to one
Logger - invalid runtime channel queries return
Falserather than raising makeInlineParser()exposes--trace,--trace-examples,--trace-namespaces,--trace-channels,--trace-colors,--trace-files,--trace-functions, and--trace-timestamps
Demo Layout
demo/bootstrap/minimal logger and inline-parser smoke testdemo/sdk/{alpha,beta,gamma}reusable demo trace sourcesdemo/exe/core/local executable tracing plus imported alpha tracingdemo/exe/omega/combined local, alpha, beta, and gamma tracing
The demos are covered by subprocess-based CLI tests under demo/tests/.
Coding Agents
If you are using a coding agent, read the workspace-level agent instructions first and then follow the local repo layout.