Observability¶
Tracing lifecycle, span helpers, exporters, and redaction. See the observability reference for configuration and the span/attribute schema.
apab.observability.tracing ¶
Tracer lifecycle and span helpers with a soft OpenTelemetry dependency.
is_enabled ¶
is_enabled()
Whether tracing is currently active.
Source code in src/apab/observability/tracing.py
39 40 41 | |
init_observability ¶
init_observability(spec, run_ctx=None, extra_processors=None)
Set up the APAB tracer provider from spec.
Returns True when tracing is active. Safe to call when the
opentelemetry packages are absent: logs a warning and stays
disabled. The APAB_OBSERVABILITY=1 env var forces enabled.
extra_processors is a hook for tests to inject an in-memory
span processor.
Source code in src/apab/observability/tracing.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
shutdown_observability ¶
shutdown_observability()
Flush exporters and disable tracing.
Source code in src/apab/observability/tracing.py
98 99 100 101 102 103 104 105 106 107 108 109 | |
init_remote_parent_from_env ¶
init_remote_parent_from_env()
Adopt a W3C TRACEPARENT from the environment, if present.
A spawned MCP server process has no in-process parent span; a caller
(e.g. a Strands client) can hand one across the process boundary via
the standard traceparent header value in the TRACEPARENT env
var. Root spans opened after this call parent onto it, so both sides
of the stdio transport share one trace. Returns True when a remote
parent was adopted.
Source code in src/apab/observability/tracing.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
span ¶
span(name, **attributes)
Open a child span, or yield a no-op span when tracing is off.
Attribute values of None are skipped.
Source code in src/apab/observability/tracing.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
current_trace_ids ¶
current_trace_ids()
Return (trace_id, span_id) of the current span as hex strings.
Source code in src/apab/observability/tracing.py
162 163 164 165 166 167 168 169 170 171 | |
set_span_error ¶
set_span_error(s, exception)
Record exception on span s and mark its status as error.
Source code in src/apab/observability/tracing.py
174 175 176 177 178 179 180 181 182 | |
apab.observability.export ¶
Span exporters and processor construction.
Only imported once OpenTelemetry is known to be installed
(from :func:apab.observability.tracing.init_observability).
JsonlSpanExporter ¶
Bases: SpanExporter
Write one JSON object per span to a .jsonl file.
Kept dependency-light so trace.jsonl in the run bundle can be read without any OpenTelemetry tooling.
Source code in src/apab/observability/export.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
build_processors ¶
build_processors(spec, run_ctx)
Build span processors for the configured exporters.
Spans are low-volume here (one per turn/tool call), so simple processors are used throughout: they export synchronously, which keeps trace.jsonl complete even on a crash.
Source code in src/apab/observability/export.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
apab.observability.redaction ¶
Redaction of captured tool arguments and results for span attributes.
Mirrors the RedactionMode semantics used by the tool-dispatch audit log:
none captures values, metadata_only captures shape only,
strict captures nothing beyond a content hash.
args_hash ¶
args_hash(arguments)
Deterministic 16-char hash of a tool-call argument dict.
Source code in src/apab/observability/redaction.py
17 18 19 20 | |
capture_args ¶
capture_args(arguments, mode)
Return span attributes describing arguments under mode.
Always includes args_hash so identical calls can be correlated
across runs without exposing values.
Source code in src/apab/observability/redaction.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
capture_text ¶
capture_text(text, mode, max_len=200)
Return text truncated per mode, or None if it must be dropped.
Source code in src/apab/observability/redaction.py
41 42 43 44 45 46 47 48 49 50 51 52 53 | |