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, andRUNTYPE_ENVIRONMENTin.envor 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: Ifinitopened your coding agent, your coding agent already has the setup prompt for the detected framework. Otherwise, paste the prompt thatinitprinted 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_setuptool with your framework. Without a framework,get_setupreturns only the list of supported framework names. -
From the CLI: Run
get-setupwith--frameworkto print the same setup:Get a framework setupReplace
FRAMEWORK_NAMEwithAI SDK,LangGraph,OpenAI Agents SDK,Pydantic AI,Mastra,OpenAI Agents SDK (TypeScript),eve,Flue, orOpenTelemetry 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.nameresource attribute and read fromRUNTYPE_ENVIRONMENT(defaultdevelopment). Runtype countsproductionandprod(case-insensitive) as production, and any other value as development. - Conversation ID and end-user ID: Set in
gen_ai.conversation.idanduser.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:
AI SDK
LangGraph
OpenAI Agents SDK
Pydantic AI
OpenTelemetry GenAI
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:
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:
Import instrumentation.ts as the first import of your entry point:
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:
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:
Install the OpenInference and OpenTelemetry packages with your project’s
Python package tool (uv add or poetry add work in place of
pip install):
Create instrumentation.py to export spans and put the agent name,
conversation ID, and end-user ID on every span:
Import instrumentation at the top of your entry point before the agent
runs:
LangGraph spans carry no agent name, so pass one stable name per graph to
agent_run and wrap each invocation in it:
Install the OpenInference and OpenTelemetry packages with your project’s Python package tool:
Create instrumentation.py to export spans and put the agent name,
conversation ID, and end-user ID on every span:
Import instrumentation at the top of your entry point before the agent
runs:
Each Agent name becomes one agent in Runtype, and an Agent it hands off
to becomes another, so give every Agent a stable name. Pass the starting
Agent name as agent_name in agent_run. Without it, Runtype files
handoff agents under the first agent:
Install the OpenTelemetry packages with your project’s Python package tool:
Create instrumentation.py to export spans and record the agent name,
conversation ID, end-user ID, and conversation content:
Import instrumentation at the top of your entry point before the agent
runs:
Give every Agent a stable name, pass conversation_id to the run, and
wrap the run in agent_run:
Install the OpenTelemetry packages for your language. For Node.js, install the TypeScript SDK packages:
For Python, install the Python SDK packages:
Configure the tracer provider, resource, and OTLP exporter as shown in the
AI SDK tab (without @ai-sdk/otel and registerTelemetry) or in the
Python tabs (without a framework instrumentor). Then emit the three spans
listed in the following table from your agent loop:
Nest the chat and execute_tool spans under the run’s invoke_agent
span. A loop that calls the model several times in one run emits several
chat spans.
Call the get_setup tool with framework set to "OpenTelemetry GenAI"
for a complete example loop. For hand-written span details and non-OTLP
options, see
Instrument a custom agent loop.
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:
-
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. -
Run the
checkcommand from the repository root (or ask your coding agent to call thecheck_first_tracetool):Check the first runThe
checkcommand finds your product from the ingest key in.env. Pass--productto check another product. -
Wait for the check to return. By default, it waits up to 30 seconds for a run to arrive. Pass
--waitwith a number of seconds from0to50to 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:
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:
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, ortool_iofails because the exporter omitted or redacted content,fixPrompttells you what to enable in your instrumentation. For OpenTelemetry GenAI instrumentations, setOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=trueand 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,
fixPromptstates that the exporter needs no change. Update the agent’s settings in Runtype instead. - Missing attributes: When
conversation_id,environment,system_prompt,tool_definitions, ortool_iofails,fixPromptnames the exact span or resource attribute to add. - No agent name: If no span carries
gen_ai.agent.name,attributionfails. Set it on the invocation span, or setservice.nameon 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:
-
Note the current time in ISO 8601 format (for example,
2026-06-15T14:30:00Z). -
Run your agent once in development again.
-
Run
checkwith--since(or callcheck_first_tracewithsince) so Runtype ignores runs received before your fix:Re-check after a fixReplace
TIMESTAMPwith 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
- Describe your agents: send Runtype a map of your agents and their business context.
- Connect your coding agent: add the Runtype Connect MCP server to another coding agent or use the CLI directly.
- Read traces and runs: inspect ingested runs and span content from your coding agent or CLI.
- Trace attributes: look up every OpenTelemetry attribute that Runtype reads.