Skip to navigation

Send a first trace

Instrument your agent to export OpenTelemetry traces to Runtype, run it once in development, and confirm that Runtype accepts and reads the trace. When the first-trace check reports healthy, your repository is ready for analysis and simulation.

Before you begin

You need the following:

  • A connected repository with RUNTYPE_INGEST_KEY, RUNTYPE_OTLP_URL, and RUNTYPE_ENVIRONMENT in .env or your chosen env file. If you haven’t connected the repository, follow Connect a repository.
  • A local command, script, or test that runs your agent end to end.

Get the setup for your framework

The runtype-connect CLI and the Runtype Connect Model Context Protocol (MCP) server provide setups for AI SDK, LangGraph, OpenAI Agents SDK, Pydantic AI, Mastra, OpenAI Agents SDK (TypeScript), eve, Flue, and OpenTelemetry GenAI (for an agent loop you wrote yourself). When your project already sends traces somewhere, such as Logfire with Pydantic AI or Flue’s own OpenTelemetry instrumentation, the setup adds Runtype beside that telemetry. Get the setup in one of the following ways:

  • From init: If init opened your coding agent, your coding agent already has the setup prompt for the detected framework. Otherwise, paste the prompt that init printed into your coding agent. That prompt includes the install command, env loading, and instrumentation code.

  • From your coding agent: Ask your coding agent to call the get_setup tool with your framework. Without a framework, get_setup returns only the list of supported framework names.

  • From the CLI: Run get-setup with --framework to print the same setup:

    Get a framework setup
    npx @runtypelabs/connect get-setup --framework "FRAMEWORK_NAME"

    Replace FRAMEWORK_NAME with AI SDK, LangGraph, OpenAI Agents SDK, Pydantic AI, Mastra, OpenAI Agents SDK (TypeScript), eve, Flue, or OpenTelemetry GenAI.

To set up Flue by hand, see Instrument a Flue agent. To set up Mastra by hand, see Send traces from a supported framework. For other supported frameworks (Cloudflare Agents, OpenClaw, Hermes, or Pi) or a manual exporter with a telemetry API key, see Instrument a supported framework.

Instrument your agent

Each Connect setup configures the following on every run:

  • Agent name: Set in gen_ai.agent.name. Runtype creates an agent in the product for each distinct name it receives (up to 50 agents per product), so give each agent a stable name.
  • Environment: Set in the deployment.environment.name resource attribute and read from RUNTYPE_ENVIRONMENT (default development). Runtype counts production and prod (case-insensitive) as production, and any other value as development.
  • Conversation ID and end-user ID: Set in gen_ai.conversation.id and user.id.
  • Conversation content: User and assistant messages, the system prompt, and tool definitions, inputs, and outputs. Analysis and simulation require this content. If your app already redacts content, your coding agent asks before changing it. Decide what content to send to Runtype. For more information, see Control what content is sent.

Each setup loads RUNTYPE_INGEST_KEY, RUNTYPE_OTLP_URL, and RUNTYPE_ENVIRONMENT from .env. It exports spans over the OpenTelemetry Protocol (OTLP) to RUNTYPE_OTLP_URL with the ingest key as the bearer token. If init wrote those variables to another file (such as .env.local), load that file instead.

Import the instrumentation file first in your entry point, before the agent runs. If your project already configures OpenTelemetry, add the Runtype exporter and deployment.environment.name to that provider instead of starting a second one. Leave your existing exporters unchanged.

Give the Runtype exporter its own URL and headers instead of OTEL_EXPORTER_OTLP_HEADERS. Every OTLP exporter reads that variable, so using it can send credentials to the wrong collector. If your app redacts content before export, Runtype receives the redacted content.

A batch span processor holds spans for about 5 seconds. Flush before a short-lived script exits, or its spans don’t leave the process. In a serverless handler, flush at the end of each request because the runtime freezes the handler instead of exiting it.

Your coding agent can apply this setup for you. Choose your framework in the following tabs to see what it adds. For Mastra, OpenAI Agents SDK (TypeScript), eve, and Flue, run init or call get_setup with that framework name:

Install the packages with your project’s package manager. Pick the @ai-sdk/otel release whose patch number matches your installed ai package, such as @ai-sdk/otel@1.0.181 with ai@7.0.181. A mismatched pair fails to type-check:

Install
npm i @ai-sdk/otel @opentelemetry/sdk-node @opentelemetry/sdk-trace @opentelemetry/exporter-trace-otlp-proto @opentelemetry/resources dotenv

If you use pnpm, the install can exit with ERR_PNPM_IGNORED_BUILDS for protobufjs. The packages install and work without that build script.

Create instrumentation.ts to register the exporter and telemetry integration:

instrumentation.ts
import 'dotenv/config'
import { OpenTelemetry } from '@ai-sdk/otel'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
import {
defaultResource,
resourceFromAttributes,
} from '@opentelemetry/resources'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace'
import { registerTelemetry } from 'ai'
const spanProcessor = new BatchSpanProcessor({
exporter: new OTLPTraceExporter({
url: process.env.RUNTYPE_OTLP_URL,
headers: {
authorization: `Bearer ${process.env.RUNTYPE_INGEST_KEY}`,
},
}),
})
export const sdk = new NodeSDK({
resource: defaultResource().merge(
resourceFromAttributes({
'deployment.environment.name':
process.env.RUNTYPE_ENVIRONMENT ?? 'development',
})
),
spanProcessors: [spanProcessor],
})
sdk.start()
export function flushTelemetry(): Promise<void> {
return spanProcessor.forceFlush()
}
registerTelemetry(
new OpenTelemetry({
agentSpanName: 'functionId',
enrichSpan: ({ runtimeContext }) => ({
...(typeof runtimeContext?.conversationId === 'string'
? { 'gen_ai.conversation.id': runtimeContext.conversationId }
: {}),
...(typeof runtimeContext?.userId === 'string'
? { 'user.id': runtimeContext.userId }
: {}),
}),
})
)
process.once('beforeExit', () => void sdk.shutdown().catch(console.error))

Import instrumentation.ts as the first import of your entry point:

Entry point
import './instrumentation'

Name each agent with functionId and pass the conversation ID and end-user ID at each generateText and streamText call. Each functionId becomes one agent in Runtype:

Call site
const result = await generateText({
model,
prompt,
runtimeContext: { conversationId, userId },
telemetry: {
functionId: 'support-agent',
includeRuntimeContext: { conversationId: true, userId: true },
},
})

In a serverless handler, await flushTelemetry() at the end of each request. It sends finished spans and keeps the exporter open for the next request.

If you use ToolLoopAgent, pass runtimeContext and telemetry to new ToolLoopAgent({ ... }), because generate() and stream() take neither option. Build the agent per conversation when those IDs change per conversation.

On AI SDK 5 or 6, leave @ai-sdk/otel out of the install command and remove the @ai-sdk/otel and registerTelemetry code from instrumentation.ts. Turn telemetry on at each call site instead:

Call site on AI SDK 5 or 6
const result = await generateText({
model,
prompt,
experimental_telemetry: {
isEnabled: true,
functionId: 'support-agent',
metadata: { sessionId: conversationId, userId },
},
})

Run the agent and check the first trace

Nothing reaches Runtype until your agent runs. To send a first trace and verify it, follow these steps:

  1. Run your agent once locally, end to end, with RUNTYPE_ENVIRONMENT=development. Use your project’s normal run command, script, or test. If the run fails, fix that error before checking the trace.

  2. Run the check command from the repository root (or ask your coding agent to call the check_first_trace tool):

    Check the first run
    npx @runtypelabs/connect check

    The check command finds your product from the ingest key in .env. Pass --product to check another product.

  3. Wait for the check to return. By default, it waits up to 30 seconds for a run to arrive. Pass --wait with a number of seconds from 0 to 50 to change that.

The check looks at the newest development run of each agent (up to five). In the dashboard, your product shows Connected agents and a run appears. Connect an agent reports “A run arrived”.

Read the check status

The check returns one of the five statuses in the following table:

StatusMeaningWhat to do
healthyA run arrived and every required check passed.Proceed to describing your agents.
degradedA run arrived and nothing failed, but a check warned that the traces are below the fidelity Runtype needs, for example content the app declares withheld.Nothing needs fixing. The check says what is missing and what it costs, and a coding agent relays that from fixPrompt. Then proceed. See Control what content is sent.
needs_attentionA run arrived with a failed check, or Runtype refused an export.Apply each item in fixPrompt, then run the agent and check again.
processingA run arrived and Runtype is still processing it.Wait a moment and run the check again.
no_tracesNothing arrived.Confirm that the agent ran end to end, verify RUNTYPE_OTLP_URL, and confirm that spans flush on exit.

The check command exits with code 0 for healthy, 1 for needs_attention, 5 for degraded, and 6 for processing or no_traces. Pass --json to print the raw check result.

Read the eight per-agent checks

The check evaluates eight checks for each examined agent, as shown in the following table:

CheckRequiredPasses when the run carries
attributionYesTraces that reach this product and name an agent
contentYesReadable user and assistant messages that aren’t replaced by redaction markers
system_promptYesA system prompt in gen_ai.system_instructions or a system message in gen_ai.input.messages
tool_definitionsYesTool definitions offered to the model
tool_ioYesBoth inputs and outputs on execute_tool spans
conversation_idYesA conversation ID
environmentYesA deployment environment
end_user_idNoAn end-user ID

A check reports unknown when the run can’t show the answer. For example, tool_definitions and tool_io report unknown when a run calls no tools. Neither an unknown check nor a failed end_user_id check turns the status into needs_attention. A required check reports warn when the run works but is below the fidelity Runtype needs: content warns with withheld_by_app when the app declares its content withheld. A warn check makes the status degraded, not needs_attention. See Control what content is sent.

Fix issues that the check reports

When status is needs_attention, fixPrompt returns the exact changes needed, ready to paste into your coding agent. The check classifies each failure so you change the right side:

  • Exporter content capture and redaction: When content, system_prompt, tool_definitions, or tool_io fails because the exporter omitted or redacted content, fixPrompt tells you what to enable in your instrumentation. For OpenTelemetry GenAI instrumentations, set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true and turn off redaction for development runs.
  • Runtype logging policy and redaction: When the agent’s logging policy is off or personally identifiable information (PII) redaction is on in Runtype, fixPrompt states that the exporter needs no change. Update the agent’s settings in Runtype instead.
  • Missing attributes: When conversation_id, environment, system_prompt, tool_definitions, or tool_io fails, fixPrompt names the exact span or resource attribute to add.
  • No agent name: If no span carries gen_ai.agent.name, attribution fails. Set it on the invocation span, or set service.name on the resource.
  • Refused exports: When Runtype refuses an export, the check lists recent refusals with a fix for each. For the full list of ingest errors and fixes, see Troubleshooting.

To verify a fix without matching older runs, follow these steps:

  1. Note the current time in ISO 8601 format (for example, 2026-06-15T14:30:00Z).

  2. Run your agent once in development again.

  3. Run check with --since (or call check_first_trace with since) so Runtype ignores runs received before your fix:

    Re-check after a fix
    npx @runtypelabs/connect check --since TIMESTAMP

    Replace TIMESTAMP with the ISO 8601 time that you noted before running the agent.

Running your test suite afterwards can send incomplete traces. If you do, run the check again.

When tracing works locally, deploy with RUNTYPE_ENVIRONMENT=production and the same RUNTYPE_INGEST_KEY and RUNTYPE_OTLP_URL variables.

Next steps