OpenCode Integration
OpenCode is an open-source AI coding agent. LangGuard integrates with OpenCode via OpenTelemetry to capture agent activity, tool usage, and performance metrics.
Overview
The OpenCode integration enables LangGuard to:
- Capture coding agent traces from OpenCode sessions
- Monitor tool usage — File operations, shell commands, and code edits
- Track LLM interactions — Model calls, token usage, and latency
- Apply governance policies to coding agent activity
Prerequisites
- OpenCode installed and configured
- LangGuard API key (from Settings > API Keys)
- LangGuard admin role
Setup
Step 1: Create an Integration in LangGuard
- Navigate to Integrations in the sidebar
- Click Add Integration
- Select Coding Agents > OpenCode
- Enter a Name (e.g., "OpenCode Agent")
- LangGuard provides your OTLP endpoint and authentication details
- Click Save
Step 2: Configure Environment Variables
Set the OpenTelemetry environment variables to send traces to LangGuard:
# Add to ~/.bashrc or ~/.zshrc
export OTEL_EXPORTER_OTLP_ENDPOINT="https://app.langguard.ai"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/json"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_API_KEY"
export OTEL_SERVICE_NAME="opencode-agent"
Then reload your shell configuration:
source ~/.bashrc # or source ~/.zshrc
Step 3: Verify
- Start an OpenCode session
- Perform some coding tasks
- Check the Trace Explorer in LangGuard for incoming traces
What Gets Captured
Agent Sessions
| Event | Description |
|---|---|
| Session start | When OpenCode is launched |
| Session end | When the session completes |
| Conversation turns | Each interaction with the agent |
Tool Usage
- File reads and writes
- Shell command execution
- Code edits and modifications
- Search operations
Performance Metrics
- Response latency
- Token usage (input/output)
- Tool execution time
- Error rates
Troubleshooting
No Traces Appearing
- Verify environment variables are set correctly
- Restart your terminal after setting variables
- Check network connectivity to the LangGuard endpoint
- Verify your API key is valid
Environment Variables Not Loading
- Ensure you've sourced your shell config (
source ~/.zshrc) - Verify with
echo $OTEL_EXPORTER_OTLP_ENDPOINT
Next Steps
- Integrations Overview — See all available integrations
- Claude Code — Another coding agent integration
- Cursor — IDE-based coding agent integration