File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1512,7 +1512,7 @@ export async function getDetailedTrace(
15121512 * ID that `parent_span_id` references on child spans. We copy it to `span_id`
15131513 * so the rest of the codebase can use a single, predictable field name.
15141514 */
1515- function normalizeTraceSpan ( span : TraceSpan ) : TraceSpan {
1515+ export function normalizeTraceSpan ( span : TraceSpan ) : TraceSpan {
15161516 const normalized = { ...span } ;
15171517 if ( ! normalized . span_id && normalized . event_id ) {
15181518 normalized . span_id = normalized . event_id ;
Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "bun:test" ;
2+ import { normalizeTraceSpan } from "../../src/lib/api-client.js" ;
3+
4+ describe ( "normalizeTraceSpan" , ( ) => {
5+ test ( "copies event_id to span_id when span_id is missing" , ( ) => {
6+ const span = { event_id : "abc123" , start_timestamp : 0 } as Parameters <
7+ typeof normalizeTraceSpan
8+ > [ 0 ] ;
9+ const result = normalizeTraceSpan ( span ) ;
10+ expect ( result . span_id ) . toBe ( "abc123" ) ;
11+ } ) ;
12+
13+ test ( "preserves existing span_id" , ( ) => {
14+ const result = normalizeTraceSpan ( {
15+ span_id : "existing" ,
16+ event_id : "other" ,
17+ start_timestamp : 0 ,
18+ } ) ;
19+ expect ( result . span_id ) . toBe ( "existing" ) ;
20+ } ) ;
21+
22+ test ( "recurses into children" , ( ) => {
23+ const result = normalizeTraceSpan ( {
24+ span_id : "parent" ,
25+ start_timestamp : 0 ,
26+ children : [ { event_id : "child1" , start_timestamp : 1 } as any ] ,
27+ } ) ;
28+ expect ( result . children ?. [ 0 ] ?. span_id ) . toBe ( "child1" ) ;
29+ } ) ;
30+ } ) ;
You can’t perform that action at this time.
0 commit comments