---
title: "Trace a Voice Agent in Node.js with OpenTelemetry"
description: "See where the silence of each turn goes, from the end of the user speech to the first word of the answer: one trace per call, a span per turn and per step, in Jaeger, Langfuse or any OTLP backend."
url: "https://micdrop.dev/blog/opentelemetry-voice-agent-nodejs"
---

# Trace a Node.js voice agent with OpenTelemetry, turn by turn

See where the silence of each turn goes, from the end of the user speech to the first word of the answer: one trace per call, a span per turn and per step, in Jaeger, Langfuse or any OTLP backend.

November 29, 2026

[Godefroy de Compreignac](https://github.com/Godefroy)

Key takeaways

*   The latency a caller feels is the silence between the end of their sentence and the first sound of the answer. It splits into speech to text, the model and the voice, and only a measure per turn tells which one to fix.
*   Micdrop times every turn with nothing to configure, and \`traceCall()\` from \`@micdrop/otel\` turns each call into an OpenTelemetry trace: a span for the call, one per turn, and one per step under it.
*   The answer span follows the GenAI conventions of OpenTelemetry, so Langfuse shows it as a generation with its model and tokens, and Jaeger or Grafana Tempo show the same trace as a waterfall.
*   Transcripts stay out of the traces unless you set \`recordContent\`, and every log line of the call carries the ids of its trace.

A voice agent that answers in 700 ms feels attentive. The same agent at 2 seconds feels broken, and the caller starts talking over it. Between those two numbers sit three providers, your tools and the network, and an average over the day hides which one slowed down. You need the latency of each turn, split into its steps, next to what the model was sent.

This tutorial traces a Node.js voice agent with [OpenTelemetry](https://opentelemetry.io), the open standard most tracing backends read. It uses [Micdrop](/), the open source TypeScript library this site publishes, and its `@micdrop/otel` package. By the end, every call shows up in Jaeger on your machine, then in Langfuse, as a trace you can read at a glance.

## Where the time of a turn goes

A turn of a cascaded voice agent runs three steps in a row. The speech to text finishes the transcript, the model writes the first words of its answer, and the text to speech turns them into the first chunk of voice. The caller hears the sum, plus whatever your code adds in between.

```mermaid
graph LR
  A[User stops speaking] -->|stt| B[Final transcript]
  B -->|llm| C[First token]
  C -->|tts| D[First chunk of voice]
  A -.->|total, the silence the caller hears| D
```

Each step fails in its own way. A speech to text that streams has the transcript ready almost at once, one that works on whole files makes the caller wait for it. A model slows down with a long conversation or a slow tool. A voice provider has a cold connection on the first answer. Seeing the three side by side, per turn, is what tells you where to look.

Micdrop measures them on every turn, with nothing to set up. The [metrics page](/docs/server/metrics) lists every field; the server emits them as a `Metrics` event once the answer has been heard:

```typescript
server.on('Metrics', (turn) => {
  console.log(turn.index, turn.latency.total, {
    stt: turn.latency.stt,
    llm: turn.latency.llm,
    tts: turn.latency.tts,
  })
})
```

An event is enough to print numbers. To compare calls, follow one user across the day or show the model input next to a slow answer, the numbers belong in a tracing backend.

## Set up the project

The server below answers browser calls over a WebSocket, with OpenAI for the three steps. Any other provider Micdrop supports traces the same way.

```bash
mkdir traced-agent && cd traced-agent
npm init -y
npm pkg set type=module
npm install @micdrop/server @micdrop/openai @micdrop/otel ws
npm install @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http
npm install -D tsx typescript @types/node @types/ws
```

`@micdrop/otel` depends on the OpenTelemetry API alone. The SDK and the exporter decide where spans go, and a process without them sends spans nowhere, at no cost.

## Register OpenTelemetry first

The SDK has to be registered before the first call starts. Keep it in its own file, imported first by the server:

`tracing.ts`

```typescript
import { NodeSDK } from '@opentelemetry/sdk-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'

// Reads OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS
export const sdk = new NodeSDK({
  serviceName: 'voice-agent',
  traceExporter: new OTLPTraceExporter(),
})

sdk.start()
```

The exporter reads the standard OpenTelemetry environment variables, so the same file serves Jaeger, Grafana Tempo, Honeycomb, Datadog or Langfuse. Only the variables change.

## Trace every call

The server creates a `MicdropServer` for each WebSocket, then hands it to `traceCall()`:

`server.ts`

```typescript
import { sdk } from './tracing'
import { OpenaiAgent, OpenaiSTT, OpenaiTTS } from '@micdrop/openai'
import { traceCall } from '@micdrop/otel'
import { MicdropServer } from '@micdrop/server'
import { WebSocketServer } from 'ws'

const apiKey = process.env.OPENAI_API_KEY || ''
const wss = new WebSocketServer({ port: 8081 })

wss.on('connection', (socket, request) => {
  const userId = new URL(request.url ?? '/', 'http://x').searchParams.get('user')

  const server = new MicdropServer(socket, {
    firstMessage: 'Hello! What can I do for you?',
    agent: new OpenaiAgent({
      apiKey,
      systemPrompt:
        'You are a helpful assistant. Your answers are spoken, so keep them short.',
    }),
    stt: new OpenaiSTT({ apiKey }),
    tts: new OpenaiTTS({ apiKey, voice: 'alloy' }),
    logger: 'info',
  })

  // One trace per call, a span per turn and per step
  traceCall(server, {
    attributes: { 'user.id': userId ?? 'anonymous' },
  })

  server.on('End', ({ metrics }) => {
    const p95 = metrics.latency.total?.p95
    if (p95 !== undefined && p95 > 1500) {
      server.logger.warn('Slow call', { p95 })
    }
  })
})

// Sends the spans still pending before the process exits
process.on('SIGTERM', async () => {
  await sdk.shutdown()
  process.exit(0)
})

console.log('Voice agent listening on ws://localhost:8081')
```

`traceCall()` returns the call span, open until the call ends, should you want to add attributes as the call goes: the plan of the user, the outcome of the call, an order number found by a tool.

Any Micdrop client connects to it. In a web page:

```typescript
import { Micdrop } from '@micdrop/web'

await Micdrop.start({ url: 'ws://localhost:8081?user=42' })
```

The [getting started guide](/docs/getting-started) builds that page with the microphone, the call state and the transcript.

## Look at the traces in Jaeger

[Jaeger](https://www.jaegertracing.io) runs on your machine with Docker and listens for OTLP on port 4318:

```bash
docker run --rm -p 16686:16686 -p 4318:4318 jaegertracing/jaeger:latest
```

Start the server with its address:

```bash
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 OPENAI_API_KEY=sk-... npx tsx server.ts
```

Hold a short conversation, hang up, then open `http://localhost:16686` and pick the `voice-agent` service. Each call is one trace:

Span

What it covers

Attributes worth reading

`micdrop.call`

The whole call

Providers, turns, interruptions, total usage, latency percentiles

`micdrop.turn`

One turn, from the user speaking to the answer heard

`micdrop.turn.index`, `micdrop.turn.interrupted`, the latency of each step

`micdrop.stt`

The user speaking to the final transcript

`micdrop.latency_ms`, `micdrop.stt.audio_seconds`

`chat <model>`

The request to the model

`gen_ai.request.model`, input and output tokens, a `first_token` event

`micdrop.tts`

The first text given to the voice to its last chunk

`micdrop.latency_ms`, `micdrop.tts.characters`

A slow turn reads at a glance: the span that stretches is the step to fix. When the `chat` span is long before its `first_token` event, the model is slow to start, often from a long context or a large model. When the `micdrop.stt` span outlasts the speech of the user, the speech to text waits for the whole audio, and a streaming one would save that time. With a [speech to speech model](/docs/realtime), a single `micdrop.realtime` span replaces the three steps.

A turn span is written once the turn is over, with the timestamps the server recorded, so its steps sit where they happened even though they reach the exporter together.

## Send the traces to Langfuse

[Langfuse](https://langfuse.com) is built for LLM applications and reads OTLP over HTTP. The answer span follows the [GenAI semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) of OpenTelemetry, so Langfuse shows it as a generation, with its model and its token counts. Point the exporter to it with the keys of your project:

```bash
AUTH=$(printf '%s' "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64)
OTEL_EXPORTER_OTLP_ENDPOINT=https://cloud.langfuse.com/api/public/otel \
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic $AUTH" \
OPENAI_API_KEY=sk-... npx tsx server.ts
```

Use the address of your region, or of your own instance, in place of `cloud.langfuse.com`. The [OpenTelemetry page](/docs/server/opentelemetry) also shows the same setup written in code.

## Record what was said, when you are allowed to

A transcript is personal data, and a tracing backend is seldom cleared to hold it. The traces therefore carry timings, models and token counts, and leave the words out. When you debug an agent with test users, or your backend is cleared for it, turn the content on:

```typescript
traceCall(server, { recordContent: true })
```

Each answer span then holds `gen_ai.input.messages`, the conversation the model read, system prompt included, and `gen_ai.output.messages`, its answer and the tools it called. This is how you check what context reached the model when an answer surprises you. A common setup turns it on from an environment variable, set in staging only.

## Logs that point to their trace

With `logger: 'info'`, the server writes each call turn by turn: the user speech, the transcript, the answer, the tool calls and the latency of each turn. `traceCall()` adds `trace_id`, `span_id` and `trace_flags` to every line of the call, so a log backend links each line to its trace, and a trace to its lines.

```
12:04:33.380 INFO  4f2a9c1e server Turn ended turn=2 trigger=user latencyMs=598 sttMs=57 llmMs=312 ttsMs=229 trace_id=… span_id=…
```

The [logging page](/docs/server/logging) shows how to hand the lines to pino, winston or the request logger of Fastify. From `info` up, the lines carry what the user and the assistant say, so production logs usually stay at `warn`.

## Watch latency during development

A trace arrives once the call is over. While you build, the [devtools panel](/docs/client/devtools) shows each turn in the page as it happens, with a waterfall of the same steps. The server sends it the metrics of each turn with one line:

```typescript
import { forwardMetrics } from '@micdrop/server'

forwardMetrics(server)
```

```typescript
import { Micdrop } from '@micdrop/web'

if (import.meta.env.DEV) {
  const { mountDevtools } = await import('@micdrop/devtools')
  mountDevtools(Micdrop)
}
```

Keep both for development and internal pages: what a call consumes has no place in the client of a public app.

## Alert on the calls that feel slow

The `End` event carries the metrics of the whole call: the count, average, median, p95 and max of each step, the interruptions and the usage. The server above logs a warning when the p95 of a call passes 1.5 seconds, which any log alerting picks up. The same numbers sit on the call span as `micdrop.latency.total.p95_ms` and `micdrop.latency.total.median_ms`, so a backend that alerts on span attributes can watch them without any code.

Interruptions are worth a look too. A call where the user often speaks over the assistant has answers that are too long, or a turn detection that closes turns too early, and `micdrop.call.interruptions` counts them.

## How this compares

Pipecat and LiveKit Agents, the two best known open source voice frameworks, both export OpenTelemetry traces as well: Pipecat from its Python pipeline ([its tracing guide](https://docs.pipecat.ai/server/utilities/opentelemetry)), LiveKit Agents in Python and Node, with the same spans that feed the agent insights of LiveKit Cloud ([its tracing guide](https://docs.livekit.io/deploy/observability/tracing/)), both read on 29 November 2026. The [comparison of Pipecat, LiveKit Agents and Micdrop](/blog/pipecat-vs-livekit-agents) covers the rest of the differences. With Micdrop, the traces come from the Node server you already run, next to the traces of the rest of your backend: pass the context of the HTTP request that opened the call as `context`, and the call nests under it.

## Frequently asked questions

### How do I measure the latency of a voice agent?

Measure the silence between the end of the user speech and the first chunk of the answer voice, on every turn, and split it into speech to text, model and voice. Micdrop does it on each turn with nothing to configure and emits the numbers as a `Metrics` event, and `@micdrop/otel` sends them to any OpenTelemetry backend as spans.

### Which backends can show the traces?

Any backend that reads OTLP: Jaeger, Grafana Tempo, Honeycomb, Datadog, New Relic or Langfuse among others. The exporter reads the standard `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_EXPORTER_OTLP_HEADERS` variables, so a new backend only needs new values for them.

### Does tracing slow the call down?

The server measures every turn anyway, since the metrics cost a few numbers per turn. `traceCall()` reads those metrics once each turn is over and writes its spans then, outside the path of the audio. The exporter sends them in the background, in batches.

### Are the transcripts sent to the tracing backend?

Only with `recordContent: true`. By default the spans hold timings, models, token counts and audio durations, and leave out what the user and the assistant said.

### Does it work with the OpenAI Realtime API or Gemini Live?

Yes. With a speech to speech model, each turn gets a `micdrop.realtime` span in place of the transcription, the answer and the voice, with the tokens the model reports.

## Getting started

The [OpenTelemetry page](/docs/server/opentelemetry) lists every option and span attribute, and the [metrics page](/docs/server/metrics) every field of a turn. To check the agent itself before it reaches users, the [guide to testing a voice agent](/blog/testing-voice-agent-simulated-callers) runs simulated calls in your test suite, latency checks included.

## Keep reading

[

November 29, 2026

## Test a Voice Agent in TypeScript with Simulated Callers

Unit tests for the tools and handoffs of a voice agent, simulated callers played by a model and scored by a judge, and audio tests for turn taking and interruptions, all in node:test, vitest or jest.



](/blog/testing-voice-agent-simulated-callers)

[![Pipecat vs LiveKit Agents vs Micdrop: Which Fits Your Team?](/_astro/thumbnail.DTyYlmZp_jvrHu.webp)

October 28, 2026

## Pipecat vs LiveKit Agents vs Micdrop: Which Fits Your Team?

Pipecat is a Python pipeline with your choice of transport. LiveKit Agents is a WebRTC room in Python and Node. Micdrop is TypeScript in your own server. How to choose, with dated facts.



](/blog/pipecat-vs-livekit-agents)

[![Voice Agent Barge-In: Handle Interruptions](/_astro/thumbnail.B5PI427Q_Z23btMG.webp)

October 31, 2026

## Voice Agent Barge-In: Handle Interruptions

A voice agent needs to detect speech during playback, stop every output path, cancel stale generation and keep only the answer the user heard.



](/blog/voice-agent-interruption-barge-in)
