Instrument
Add observability to your AI agents with automatic and manual instrumentation.
The Instrument section covers everything you need to add observability to your AI agents.
Overview
Risicare provides multiple ways to instrument your code:
- Auto-Instrumentation - Zero-code tracing of LLM providers
- SDK Decorators - Rich context with
@agent,@trace_*decorators - Framework Integrations - Native support for LangGraph, CrewAI, AutoGen
Choose Your Approach
SDK Reference
Core SDK configuration and decorators
LLM Providers
OpenAI, Anthropic, Cohere, and more
Frameworks
LangGraph, CrewAI, AutoGen integrations
Progressive Integration
Start simple and add depth as needed. The code below is Python. Tier 0 is Python only. In JavaScript, call init() and one patch call for each provider (see JavaScript SDK):
Tier 0: One Import
Add import risicare to your entrypoint and set RISICARE_API_KEY and
RISICARE_TRACING=true for automatic instrumentation of the LLM calls of supported providers. The environment variables are read
when the SDK is imported — a process that never imports risicare emits no spans.
export RISICARE_API_KEY=rsk-your-api-key
export RISICARE_TRACING=trueimport risicare # the one line you add
# ... your agent code, unchanged ...Tier 1: Explicit Init
Call risicare.init() for configuration control.
import risicare
risicare.init(environment="production")Tier 2: Agent Identity
Use @agent() to identify agent functions.
from risicare import agent
@agent(name="planner", role="orchestrator")
def plan(objective):
passTier 3: Sessions
Group traces with @session or session_context().
from risicare import session_context
with session_context(session_id=user_session):
agent.run(query)Tier 4: Phases
Track decision phases with @trace_think, @trace_decide, @trace_act.
from risicare import trace_think, trace_decide, trace_act
@trace_think
def analyze(): pass
@trace_decide
def choose(): pass
@trace_act
def execute(): passTier 5: Multi-Agent
Track messages with @trace_message, @trace_delegate.
from risicare import trace_message, trace_delegate
@trace_message
def send_to_reviewer(msg): pass
@trace_delegate
def assign_subtask(task): passWhat Gets Captured
| Data | Auto | With Decorators |
|---|---|---|
| LLM calls (provider, model, parameters) | ✓ | ✓ |
| Prompt and completion text | On by default | On by default |
| Token counts & costs | ✓ | ✓ |
| Latency & timing | ✓ | ✓ |
| Agent identity | - | ✓ |
| Session grouping | - | ✓ |
| Decision phases | - | ✓ |
| Inter-agent messages | - | ✓ |
| Custom attributes | - | ✓ |
Prompt and completion text is recorded only when two switches allow it: trace_content
in the SDK (on by default since Python 0.7.0 and npm 0.10.0), and the project setting
"Capture Content, this project" in Settings > General (on by default). The arguments of
tool calls are content too. To keep the text in your process, set trace_content=False
(npm: traceContent: false) or RISICARE_TRACE_CONTENT=false. The project switch acts at the
gateway, after the text has left your process. When it is off, the gateway replaces prompt,
completion and tool content with <risicare:content-omitted> before it stores the span, and
it also masks the exception message and the status message. The change takes effect within
two minutes. It does not remove content that is already stored. In the JavaScript SDK,
patchOpenAI and patchAnthropic record the text; a streamed call records the prompt only.
The other JavaScript providers record no text.
Some data of a tool call is not content: the number of calls, their names and the finish or
stop reason. The SDK sends them with trace_content on or off, and no option turns them off.
With trace_content off, the SDK also withholds the text of an error. It replaces the
span status message, the exception messages and their copies in the stack traces,
error.message, exception.message and error.stack with <risicare:content-omitted>
before they leave your process. The exception type, error.code, the status and the frame
lines of a stack stay. The
option error_text (npm: errorText, or RISICARE_ERROR_TEXT) sets this apart: "auto"
(the default) follows trace_content, True sends the error text also with content capture
off, and False withholds it also with content capture on. If a provider's error message
repeats part of a prompt, that text is in those fields when you send them. To filter them in
Python, use mask: it receives statusMessage, exceptions.{i}.message,
exceptions.{i}.stacktrace and error.message.