MCPcopy Create free account
hub / github.com/TanStack/ai / createLocalCaptureTracer

Function createLocalCaptureTracer

testing/e2e/src/routes/api.otel-usage.ts:29–103  ·  view source on GitHub ↗

* Single-request in-memory tracer. Unlike the per-testId capture in * `api.middleware-test.ts`, everything here happens inside one POST, so spans * collect into a local array returned directly in the response body.

()

Source from the content-addressed store, hash-verified

27 * collect into a local array returned directly in the response body.
28 */
29function createLocalCaptureTracer(): {
30 tracer: Tracer
31 spans: Array<CapturedSpan>
32} {
33 const spans: Array<CapturedSpan> = []
34 let spanSeq = 0
35 const tracer: Tracer = {
36 startSpan(name, options = {}, _ctx?: Context): Span {
37 const id = `span-${spanSeq++}`
38 const attributes: Record<string, AttributeValue> = {}
39 for (const [k, v] of Object.entries(options.attributes ?? {})) {
40 if (v !== undefined) attributes[k] = v as AttributeValue
41 }
42 const captured: CapturedSpan = {
43 name,
44 kind: options.kind,
45 attributes,
46 ended: false,
47 }
48 spans.push(captured)
49 const span: Span = {
50 spanContext(): SpanContext {
51 return { traceId: 'otel-usage-trace', spanId: id, traceFlags: 1 }
52 },
53 setAttribute(key, value) {
54 captured.attributes[key] = value as AttributeValue
55 return span
56 },
57 setAttributes(next) {
58 for (const [k, v] of Object.entries(next)) {
59 captured.attributes[k] = v as AttributeValue
60 }
61 return span
62 },
63 addEvent() {
64 return span
65 },
66 addLink() {
67 return span
68 },
69 addLinks() {
70 return span
71 },
72 setStatus() {
73 return span
74 },
75 updateName(next) {
76 captured.name = next
77 return span
78 },
79 end() {
80 captured.ended = true
81 },
82 isRecording() {
83 return !captured.ended
84 },
85 recordException() {},
86 }

Callers 1

api.otel-usage.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected