OpenTelemetry support in Claude Code is currently in beta and details are subject to change.
Prerequisites
- Obtain your
LANGWATCH_API_KEYfrom the LangWatch dashboard - Claude Code installed on your system
- Access to configure environment variables or managed settings
Quick Start
Configure Claude Code to send traces to LangWatch using environment variables:Administrator Configuration
Administrators can configure OpenTelemetry settings for all users through the managed settings file. This allows for centralized control of telemetry settings across an organization. The managed settings file is located at:- macOS:
/Library/Application Support/ClaudeCode/managed-settings.json - Linux and WSL:
/etc/claude-code/managed-settings.json - Windows:
C:\ProgramData\ClaudeCode\managed-settings.json
Managed settings can be distributed via MDM (Mobile Device Management) or other device management solutions. Environment variables defined in the managed settings file have high precedence and cannot be overridden by users.
LangWatch-Specific Configuration
Endpoint Configuration
LangWatch provides OpenTelemetry endpoints for traces:Protocol Selection
LangWatch supports multiple OTLP protocols. For Claude Code integration, we recommend:Authentication
Set your LangWatch API key for authentication:Available Trace Data
Claude Code exports comprehensive trace data that integrates seamlessly with LangWatch’s observability platform.Standard Attributes
All traces share these standard attributes:| Attribute | Description | Controlled By |
|---|---|---|
session.id | Unique session identifier | OTEL_METRICS_INCLUDE_SESSION_ID (default: true) |
app.version | Current Claude Code version | OTEL_METRICS_INCLUDE_VERSION (default: false) |
organization.id | Organization UUID (when authenticated) | Always included when available |
user.account_uuid | Account UUID (when authenticated) | OTEL_METRICS_INCLUDE_ACCOUNT_UUID (default: true) |
terminal.type | Terminal type (e.g., iTerm.app, vscode, cursor, tmux) | Always included when detected |
Key Trace Information
Claude Code traces include:- Session tracking: CLI session lifecycle and duration
- Code generation: Lines of code added/removed, file operations
- Tool usage: Edit, MultiEdit, Write, and NotebookEdit tool decisions
- API interactions: Claude API requests, responses, and performance
- User interactions: Prompt submissions and tool acceptances/rejections
Configuration Examples
Basic LangWatch Integration
Advanced Configuration with Custom Attributes
Debug Configuration
Multi-Team Organization Support
Organizations with multiple teams can add custom attributes to distinguish between different groups:- Filter traces by team or department
- Track usage per cost center
- Create team-specific dashboards
- Set up alerts for specific teams
Dynamic Headers for Enterprise
For enterprise environments that require dynamic authentication, you can configure a script to generate headers dynamically:Settings Configuration
Add to your.claude/settings.json:
Script Requirements
The script must output valid JSON with string key-value pairs representing HTTP headers:Verification and Testing
1. Verify Configuration
After setting up your configuration, verify that Claude Code is sending data to LangWatch:2. Test Data Flow
- Start Claude Code with your configuration
- Make some interactions (ask questions, edit code, use tools)
- Check LangWatch dashboard for incoming traces
- Verify data appears in the dashboard
Troubleshooting
No data appearing in LangWatch
No data appearing in LangWatch
- Verify
CLAUDE_CODE_ENABLE_TELEMETRY=1is set - Check that the endpoint URL is correct:
https://app.langwatch.ai/api/otel - Ensure your API key is valid and has proper permissions
- Check network connectivity to the LangWatch endpoint
- Verify the OTLP protocol is supported (http/json or grpc)
Authentication errors
Authentication errors
- Verify the Authorization header format:
Bearer YOUR_API_KEY - Ensure the API key is valid and not expired
- Check that the API key has the necessary permissions for trace ingestion
- Verify the header is properly formatted in the environment variable
Performance issues
Performance issues
- Consider using batch span processors for high-volume applications
- Implement sampling to reduce the number of traces sent
- Use async span processors to avoid blocking your application
- Adjust export intervals based on your monitoring needs
Configuration not taking effect
Configuration not taking effect
- Restart Claude Code after changing environment variables
- Check for conflicting settings in managed settings files
- Verify environment variable precedence (managed settings override user settings)
- Use
claude --helpto verify configuration is loaded
Best Practices
1. Start with Console Exporter for Debugging
2. Implement Proper Error Handling
Monitor for export failures and implement retry logic if needed. LangWatch provides reliable endpoints, but network issues can occur.3. Use Resource Attributes for Organization
Usage Insights
With LangWatch integration, you can gain insights into Claude Code usage:Productivity Tracking
- Monitor code generation patterns
- Track tool usage and acceptance rates
- Analyze session duration and frequency
User Behavior Analysis
- Understand how teams use Claude Code
- Identify popular features and workflows
- Monitor adoption across different teams
Next Steps
- Set up your configuration using the examples above
- Verify data flow to LangWatch
- Explore the LangWatch dashboard to view your Claude Code traces
- Create custom dashboards for your team’s specific needs
- Set up alerts for unusual usage patterns
Security and Privacy
- Telemetry is opt-in and requires explicit configuration
- Sensitive information like API keys or file contents are never included in traces
- User prompt content is redacted by default - only prompt length is recorded
All data sent to LangWatch is encrypted in transit and stored securely. Review LangWatch’s privacy policy and security practices for more details.