Skip to content

Commit 692cdf2

Browse files
authored
Merge pull request #2910 from alectimison-maker/feat/trace-otlp-session-association
feat(trace-export): add session-aware OTLP export compatibility
2 parents 8e74d58 + 25a1147 commit 692cdf2

4 files changed

Lines changed: 506 additions & 9 deletions

File tree

docs/export-and-workflow-formats.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,17 @@ npm run trace:otlp -- webbrain-trace-example.json \
103103
--output webbrain-trace-example.otlp.json
104104
```
105105

106+
For a legacy single-run input, the output retains the existing root span with
107+
model-call and tool child spans. A session bundle uses one trace per persisted
108+
session, one span per run, same-session `parentRunId` parent links, and span
109+
events for turn/step activity. Cross-session parents are represented as span
110+
links rather than parent spans.
111+
106112
The output is an
107113
[OTLP/HTTP JSON](https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding)
108-
`ExportTraceServiceRequest`. It contains one `invoke_agent WebBrain` root span,
109-
child model-call and `execute_tool` spans, and lightweight lifecycle events.
114+
`ExportTraceServiceRequest`. Legacy input contains one `invoke_agent WebBrain`
115+
root span, child model-call and `execute_tool` spans, and lightweight lifecycle
116+
events; session bundles contain one `invoke_agent` span per run.
110117
The mappings follow the current
111118
[OpenTelemetry GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-agent-spans.md),
112119
which are still marked development and may change.
@@ -134,6 +141,10 @@ npm run trace:otlp -- webbrain-trace-example.json \
134141
--include-content
135142
```
136143

144+
See [`trace-format-compatibility.md`](trace-format-compatibility.md) for the
145+
relationship between the storage version, run format version, and export
146+
schema, plus the reader obligations for unknown events and legacy records.
147+
137148
This is a post-run conversion, not live OpenTelemetry instrumentation. Child
138149
span start times are reconstructed from the recorder's completion timestamp and
139150
reported latency, so they should be used for diagnostics rather than

docs/trace-format-compatibility.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Trace format compatibility
2+
3+
WebBrain trace data has three independent version layers:
4+
5+
- `DB_VERSION` describes IndexedDB object-store structure and changes only when
6+
stores or indexes change.
7+
- `traceFormatVersion` describes the meaning of a persisted run and its event
8+
log. New optional fields and new event kinds are additive and remain at the
9+
current version. Bump this value only when an existing meaning changes, a
10+
field becomes required, or `seq`/`ts` semantics change.
11+
- `schema` describes the JSON export envelope. `webbrain-trace/1` remains the
12+
envelope for additive run and event changes. A new schema is reserved for a
13+
container-shape or semantic break.
14+
15+
## Reader obligations
16+
17+
Treat a missing or malformed `traceFormatVersion` as the legacy baseline. Keep
18+
missing optional fields harmless. Reject a numeric `traceFormatVersion` newer
19+
than the latest version the reader supports instead of interpreting `seq` and
20+
`ts` with older semantics. Readers must not fail an entire export because one
21+
event kind is unknown:
22+
23+
- the Traces UI shows a labeled placeholder with the raw event view;
24+
- machine-readable exporters preserve an unknown event as a generic record with
25+
its event kind;
26+
- the Markdown summary may omit unknown event details, but reports the count.
27+
28+
Raw JSON re-export keeps the original fields. Compatibility handling does not
29+
perform destructive migration and does not change the default privacy policy.
30+
31+
## Session bundles
32+
33+
The existing single-run `webbrain-trace/1` shape remains valid. A session bundle
34+
may carry a `session` identity and a `runs` array containing `{ run, events }`
35+
entries. Session-aware consumers use persisted `conversationId`, `parentRunId`,
36+
and `parentSessionId` values; they do not infer lineage from in-memory state.

0 commit comments

Comments
 (0)