Skip to main content

Overview

@core-ai/opentelemetry provides middleware that creates OpenTelemetry spans for every model operation. Spans include model metadata, token usage, finish reasons, and optionally the full message content. Traces export to any OpenTelemetry-compatible backend such as Jaeger, Grafana Tempo, or Datadog.

Installation

@opentelemetry/api is a peer dependency. You also need an OpenTelemetry SDK configured in your application (e.g., @opentelemetry/sdk-node or @opentelemetry/sdk-trace-base) to collect and export spans.

Usage

Chat models

All four chat operations (generate, stream, generateObject, streamObject) are traced. For streaming operations, the span stays open until the stream completes and captures the final usage and finish reason.

Embedding models

Image models

Options

All three factory functions accept an optional OtelMiddlewareOptions object:

recordContent

When true, input messages, tool definitions, and output content are recorded as span attributes. This includes complete base64 image and audio payloads, which may be sensitive and can create large span attributes. Defaults to false. Leave it disabled for calls or recordings unless your tracing backend is approved to receive that content.

tracerName

The OpenTelemetry tracer name. Defaults to 'core-ai'.

Span attributes

Spans follow OpenTelemetry GenAI semantic conventions and include: When recordContent is enabled, input messages and output content are recorded as additional attributes. Errors are recorded with error.type and the span status is set to ERROR.