By NHI Mgmt Group Editorial TeamBased on Braintrust: “How to trace LLM applications in TypeScript (2026)” (July 2, 2026)

TL;DR: TypeScript LLM apps often span Node, serverless, and edge runtimes, which makes tracing harder unless teams capture model calls, tool invocations, retrieval steps, latency, tokens, and errors in one typed span tree, according to Braintrust. The operational gap is not visibility alone, but whether traces can be turned into reusable evaluation data before runtime limits erase them.


At a glance

What this is: TypeScript LLM tracing needs a typed span tree that follows each model call, tool step, retrieval action, and error across runtime boundaries.

Why it matters: IAM and AI security teams should care because agent observability only becomes governable when trace data is complete enough to support debugging, evaluation, and release control.


Context

A trace is the operational record of what an LLM application actually did during a request. In TypeScript, that record is fragile because the app may run across Node, serverless, and edge runtimes, and each one affects whether spans are captured, nested, and flushed before the work disappears.

For agentic AI programmes, the governance problem is not just logging. It is whether model calls, tool usage, retrieval steps, and request metadata can be preserved as evidence that supports quality control, incident review, and release checks across the full execution path.


Key questions

Q: What breaks when LLM traces do not preserve the full request path?

A: Teams lose the ability to isolate whether a failure came from retrieval, the model call, a tool invocation, or the runtime itself. That turns debugging into guesswork and makes it difficult to turn a production incident into a reusable evaluation case. Complete traces are what make agent behaviour reviewable and repeatable.

Q: Why do serverless and edge runtimes make LLM observability harder?

A: These runtimes may stop as soon as the response returns, so buffered spans can be dropped before they are written. That means tracing succeeds only if the system flushes work before shutdown or uses a background primitive such as waitUntil. Runtime behaviour therefore becomes part of the control design, not just the deployment detail.

Q: How do production traces become useful for release testing?

A: The value comes from preserving real failures as dataset records, then running future prompt, model, or application changes against those examples. That turns observability into a release gate because the same bad case can be replayed, scored, and compared before it reaches users again.

Q: Should teams rely on telemetry alone for LLM governance?

A: No. Telemetry records what happened, but governance also needs storage, queryability, filtering, and a path into evaluation datasets. Without that backend layer, traces are hard to investigate consistently and cannot easily support repeatable quality checks or change control.


Technical breakdown

Typed span trees for LLM observability

A useful LLM trace is more than a request log. It is a typed span tree that records each model call, retrieval step, tool invocation, input, output, latency, token count, cost, and error in a parent-child structure. That structure matters because agent workflows are multi-step systems, not single API calls. When the trace preserves hierarchy, teams can see which sub-step failed, which tool call changed the outcome, and where time was spent. In TypeScript, strong typing adds another control point because metadata and payload fields can be validated at compile time instead of failing silently in production.

Practical implication: Instrument every request path so the trace captures step-level evidence, not just the final response.

Auto-instrumentation, manual spans, and Vercel AI SDK telemetry

TypeScript tracing usually starts with SDK-level auto-instrumentation, which patches supported libraries at startup so model calls are captured without wrapping every client manually. Manual spans still matter when teams need explicit control over which calls are traced or when a library is not supported. The Vercel AI SDK can also emit OpenTelemetry spans for model and tool execution, which makes telemetry portable across tracing backends. The important distinction is that telemetry records activity, while a tracing backend stores, queries, and turns it into reusable evidence. Without that backend layer, spans are hard to govern at scale.

Practical implication: Use the simplest instrumentation path that still preserves tool, model, and metadata fidelity across your stack.

Serverless flushing and trace loss in edge runtimes

Edge and serverless environments create a delivery problem that long-lived Node services do not. A runtime may shut down as soon as the response is sent, so buffered spans can disappear unless the SDK flushes them before exit or uses a background-work primitive such as waitUntil. Streaming responses are still traceable, but the tracing system must ensure the full span is written even when output is incremental. This is a runtime-control issue as much as an observability issue, because incomplete traces undermine both debugging and later evaluation work.

Practical implication: Verify that your runtime flushes spans reliably before shutdown, especially in serverless and edge deployments.


Threat narrative

Attacker objective: The operational objective is to make agent failures invisible long enough that teams cannot reproduce, diagnose, or govern them cleanly.

  1. Initial capture begins when an agent request is traced without structured spans, so the application records only the end result and not the steps that produced it.
  2. Escalation occurs when tool calls, retrieval steps, and model calls are not nested together, making it impossible to isolate the failing or slow stage.
  3. Impact is the loss of reproducible evidence, which prevents teams from turning production failures into evaluation datasets or release checks.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Trace completeness is now a governance control, not a developer convenience. When LLM systems span multiple runtimes, the organisation needs a trustworthy record of each step if it wants to debug, evaluate, and approve changes with confidence. Missing spans create blind spots that are functionally similar to missing audit evidence in identity and access workflows. Practitioner implication: treat trace integrity as part of release governance, especially for agentic AI systems that make tool decisions at runtime.

Typed metadata creates the bridge between observability and accountability. Plain logs tell you that something happened, but typed request metadata tells you whose request, which workflow, and which context produced the behaviour. That makes traces useful for filtering, incident reconstruction, and dataset creation. The same logic applies across AI governance and identity governance: if context is not captured at issuance time, it is hard to certify later. Practitioner implication: standardise the metadata fields that every traced agent request must carry.

Runtime shutdown is the hidden failure mode in TypeScript tracing. In edge and serverless environments, tracing can fail even when instrumentation is present, because buffered spans may never flush before the function exits. This is a control-plane problem, not a library problem, because the runtime determines whether evidence survives. Practitioner implication: validate trace delivery under the exact deployment model you use, not just in local development.

Evaluation reuse is the real value of production traces. Tracing matters most when a bad agent run becomes a repeatable test case instead of a one-off debugging event. That is the point where observability becomes operational control. For AI security teams, this is the same governance pattern seen in other high-change systems: capture the evidence, promote the failure into a dataset, and make future releases prove they do not repeat it. Practitioner implication: link production tracing to eval workflows before agent logic reaches broad rollout.

Agent observability is converging with identity-grade control expectations. As agents take on tool access and multi-step execution, teams are effectively governing non-human behaviour that leaves an audit trail, consumes permissions, and changes state. That makes the observability stack part of the identity and privilege story, not a separate concern. Practitioner implication: align agent tracing with your broader NHI and access governance model so execution evidence and privilege boundaries stay connected.

From our research library:

What this signals

Typed tracing is becoming the control plane for agent operations. When LLM requests move across Node, serverless, and edge runtimes, the team needs a reliable execution record before it can govern output quality or runtime behaviour. The programme implication is straightforward: if the trace cannot survive the deployment model, the agent cannot be treated as operationally controllable.

Trace-to-eval pipelines are the practical boundary between observability and assurance. Production traces become materially more valuable when they are promoted into reusable datasets that can be re-run against later changes. That shifts AI governance from after-the-fact inspection to repeatable verification, which is the direction AI security programmes should be moving.

Observability gaps in agent systems behave like identity gaps in other control stacks. If the system cannot tie a request to typed metadata, nested actions, and a durable trace, it cannot produce accountability evidence when something goes wrong. Security teams should expect agent tracing to be assessed alongside access, privilege, and audit controls rather than as a standalone engineering feature.


For practitioners

  • Instrument request entry points with typed metadata Capture stable fields such as user ID, org ID, workflow name, and request purpose when the span starts so traces remain searchable and attributable later.
  • Trace tool calls as nested child spans Preserve each model call, retrieval step, and tool invocation as a separate child span so failures and latency can be isolated to the exact stage that caused them.
  • Test span flushing in the deployed runtime Run a real serverless or edge deployment test to confirm spans are delivered before shutdown, then use explicit flush logic where background work is not guaranteed.
  • Promote production failures into eval datasets Save broken tool calls, bad retrievals, and incorrect outputs as dataset records so future prompt or model changes are checked against the same real failure cases.

Key takeaways

  • TypeScript LLM tracing fails when teams capture only outcomes instead of the full hierarchy of model calls, tool actions, retrieval steps, and runtime context.
  • The biggest operational risk is incomplete evidence, especially in serverless and edge deployments where spans can disappear before flush.
  • Production traces become governance assets only when they can be reused as evaluation datasets and release checks.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Agentic AI Top 10 addresses the attack and risk surface, while NIST AI RMF, NIST CSF 2.0 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10ASI02 — Tool MisuseTool spans and agent traces address misuse or loss of visibility in tool-mediated agent runs.
ASI03 — Identity & Privilege AbuseAgent runs consume permissions and need trace evidence tied to identity and privilege boundaries.
Recommendation — Trace tool calls as child spans and review them for misuse before approving agent releases. Bind agent traces to request metadata and privilege context so abuse can be investigated quickly.
NIST AI RMFMANAGE — AI Risk ManagementThe article is about operational controls that make AI behaviour governable in production.
Recommendation — Embed tracing, replay, and evaluation into your AI risk management process before broad deployment.
NIST CSF 2.0DE.CM-01 — Networks, systems and assets are monitored to find anomalies and eventsProduction tracing is a monitoring control that detects failures in LLM and agent execution paths.
Recommendation — Monitor agent execution paths continuously and alert on missing spans or broken step hierarchies.
NIST SP 800-53 Rev 5AU-3 — Content of Audit RecordsTrace spans need enough content to reconstruct request behaviour and support review.
Recommendation — Ensure audit records capture request context, tool calls, and errors needed to reconstruct each agent run.

Key terms

  • Typed Span Tree: A typed span tree is a structured trace that records a request as a parent span with nested child spans for model calls, tools, retrieval, and errors. It gives teams a readable execution map that can be searched, audited, and reused for evaluation.
  • Trace To Eval Workflow: A trace to eval workflow turns production traces into dataset entries that can be replayed against later model or prompt changes. It connects observability to testing so real failures become repeatable checks instead of one-off debugging events.
  • Serverless Flush: Serverless flush is the act of forcing buffered telemetry or traces to be written before a runtime shuts down. It is critical in short-lived environments because otherwise spans can be lost after the response is sent, leaving incomplete evidence for debugging or evaluation.

Deepen your knowledge

NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, workload identity, and agentic AI identity alongside the control thinking that security practitioners need. It helps IAM, security architecture, and AI governance teams align identity control with operational evidence.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 19, 2026.
Updated on October 12, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org