feat(tracing): add memory read-path spans - #1252
Conversation
Add framework-neutral Runtime tracing backed by ServerTracing. Trace memory search, reranking, experience recall, and context preparation. Cover span hierarchy, privacy, cancellation, and tracing failure isolation. Closes oceanbase#1241
| attributes={ | ||
| **attributes, | ||
| "powercontext.operation.name": name, | ||
| "powercontext.operation.unit": "stage", |
There was a problem hiding this comment.
This adds a fifth value for powercontext.operation.unit, but the docs that define the vocabulary aren't updated: the unit table in docs/{en,zh}/rfcs/0046_observability_foundations.md
and the span table in docs/{en,zh}/docs/how-to/trace-with-phoenix.md
.
There was a problem hiding this comment.
Get, it was an oversight on my part, and I will add it later.
|
Just a thought, not a blocker: _context() (which awaits self._provider.get() and opens a DB session) and the wait on _lock(scope_id) both happen before the first stage span opens, so they don't show up in the trace. Since the goal here is locating latency in the read path, and test_same_scope_read_only_searches_do_not_serialize_reranking suggests lock contention is already on your radar, those might be interesting to cover eventually. |
|
Those are my thoughts so far; let's wait for @PsiACE's review before settling on the specifics. |
PsiACE
left a comment
There was a problem hiding this comment.
Please focus the tests on exported tracing behavior and real regressions: drop the dynamic policy_id, fake _RecordingTracing, and synthetic SystemExit cases, and cover the actual vector-search span tree plus the readiness probe's no-root-span behavior.
@Ethan-Xingyue I noticed a detail here: the default Given that context retrieval and lock waiting are runtime concerns spanning multiple stages—whereas the scope of this PR is limited to the memory read phase—I intend to keep the PR focused. We can add |
- Rename the context stage from context.prepare to context.build. - Keep reranker policy_id as a regular attribute. - Prevent readiness embedding probes from exporting inference spans. - Preserve operational tracing under ALWAYS_ON sampling and injected models. - Replace synthetic tracing tests with real exported vector-search coverage. - Document the stage vocabulary and read-path spans in English and Chinese.
|
@Ethan-Xingyue @PsiACE When adding ready regression coverage, I encountered an additional special case that I felt was worth mentioning. The previous suppression mechanism relied on attaching an unsampled synthetic parent model during ready testing. This worked for the default I fixed this by providing a separate, uninstrumented ready copy of the injected
Regression tests now use The entire test suite passed 484 tests, skipped 7 tests, and both |
…tracing # Conflicts: # src/powercontext/builtin/runtime/application.py
| inference_token = self._inference_suppressed.set(True) | ||
| context_token: Token[Context] | None = None | ||
| try: | ||
| parent = trace.NonRecordingSpan( | ||
| trace.SpanContext( | ||
| trace_id=_ID_GENERATOR.generate_trace_id(), | ||
| span_id=_ID_GENERATOR.generate_span_id(), | ||
| is_remote=False, | ||
| trace_flags=trace.TraceFlags(0), | ||
| ) | ||
| ) | ||
| context_token = otel_context.attach(set_span_in_context(parent)) |
There was a problem hiding this comment.
Readiness should stay outside tracing, but attaching a synthetic parent makes tracing setup part of the readiness path and can abort server startup. Please make it best-effort.
Which issue or RFC does this PR close?
Closes #1241
Rationale for this change
Memory read requests currently expose only top-level application spans, making it difficult to determine whether latency comes from retrieval, embeddings, reranking, Experience recall, or context assembly.
This change adds stage-level tracing while keeping OpenTelemetry owned by the Server layer. The Runtime remains framework-neutral, and tracing failures do not affect search behavior.
What changes are included in this PR?
RuntimeSpanandRuntimeTracingprotocols.BuiltinRuntime.ServerTracing.stage()using OpenTelemetryINTERNALspans.success,failure, andcancelledoutcomes while preserving original exceptions.memory.searchmemory.rerankexperience.searchcontext.preparepolicy_id.Validated span trees:
Are there any user-facing changes?
Operators with tracing enabled will see the additional internal spans and bounded attributes.
Search results and error behavior remain unchanged. This PR does not change public APIs, OpenAPI, CLI behavior, database schemas, persisted formats, or dependencies.
How was this change tested?
The tests also cover missing Memory, unconfigured Experience recall, empty results, reranker fallback, embedding and agent span nesting, sensitive-data exclusion, cancellation, and tracing failure isolation.
AI usage statement
OpenAI Codex (GPT-5.6-Sol) was used to help analyze the issue, assist with making changes, write tests.