Implementation:0xSteph Pentest ai Tracing
| Knowledge Sources | |
|---|---|
| Domains | Tracing, OpenTelemetry, Observability |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for OpenTelemetry tracing spans with no-op degradation when the OTel SDK is not installed, provided by the pentest-ai engine.
Description
The tracing module provides span context managers that the orchestrator, agents, and LLM client wrap around their work. Spans flow to any OTLP-compatible backend (Phoenix, Jaeger, Tempo, Datadog, Honeycomb). When the OTel SDK is not installed (the default), this module degrades to a no-op so the rest of the engine works unchanged. Configuration via env vars: PENTEST_AI_TRACING (on/off), OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME.
Usage
Import the tracer instance when you need to wrap operations in spans. The span context manager always returns a Span-like object with set_attr and set_status methods, regardless of whether tracing is on.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: engine/tracing.py
- Lines: 1-229
Signature
tracer: Tracer # shared instance
class Tracer:
@contextmanager
def span(self, name: str, **attrs: Any) -> Span: ...
class Span:
def set_attr(self, key: str, value: Any) -> None: ...
def set_status(self, status: str) -> None: ...
Import
from engine.tracing import tracer
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | Span name (e.g. "agent.decide", "tool.exec") |
| **attrs | kwargs | No | Span attributes |
| PENTEST_AI_TRACING | str (env) | No | "on" to enable |
Outputs
| Name | Type | Description |
|---|---|---|
| Span | context manager | Span-like object with set_attr/set_status |
Usage Examples
Trace Operations
from engine.tracing import tracer
with tracer.span("agent.decide", agent="recon", engagement_id=eid):
decision = await agent.next_step()
with tracer.span("tool.exec", tool="nmap", target="10.0.0.1") as s:
result = await tool.execute(target, args)
s.set_attr("exit_code", result.get("returncode", -1))
s.set_status("OK" if result.get("returncode") == 0 else "ERROR")