Skip to main content
instrumentServer returns an ObservabilityInstance with helpers for the three OTel signals you’ll most often need: spans, histograms, and counters.

Custom spans

Use startActiveSpan for any operation you want timed and traced. The session id is added automatically.
Always call span.end() inside the callback. The helper does not auto-end.

Async spans

Nested under a tool span

If you call startActiveSpan from inside a tool handler, the new span becomes a child of the auto-generated tools/call <toolName> span — you’ll see the nesting in your trace UI.

Histograms

Use a histogram for distributions you care about — durations, sizes, scores.
getHistogram returns a recorder function — keep it around (don’t recreate per call) to avoid allocating a new instrument on every record.

Counters

For monotonically increasing counts:

Process attributes through your data processors

If you’ve configured dataProcessors, every attribute set passes through them before it reaches the exporter. Useful for redacting:
You can also call telemetry.processTelemetryAttributes(data) directly if you need to apply your processors to a value outside the standard span/metric path.

Pattern: time a critical path

Pattern: outcome counter

Next

Automatic metrics

What’s already recorded for free.

Data processors

Mutate or redact attributes site-wide.