|
| 1 | +# KaibanJS OpenTelemetry Examples |
| 2 | + |
| 3 | +This document provides a comprehensive overview of the OpenTelemetry examples available in the KaibanJS package. |
| 4 | + |
| 5 | +## 🚀 Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Install dependencies |
| 9 | +npm install |
| 10 | + |
| 11 | +# Set up environment variables |
| 12 | +export OPENAI_API_KEY="your-openai-key" |
| 13 | + |
| 14 | +# Run console example (no external dependencies) |
| 15 | +npm run example:console |
| 16 | + |
| 17 | +# Run Langfuse example |
| 18 | +export LANGFUSE_PUBLIC_KEY="your-public-key" |
| 19 | +export LANGFUSE_SECRET_KEY="your-secret-key" |
| 20 | +npm run example:langfuse |
| 21 | +``` |
| 22 | + |
| 23 | +## 📋 Available Examples |
| 24 | + |
| 25 | +### 1. Console Export (`console-example.ts`) |
| 26 | + |
| 27 | +**Perfect for development and debugging** |
| 28 | + |
| 29 | +- ✅ No external dependencies |
| 30 | +- ✅ Immediate console output |
| 31 | +- ✅ Development debugging |
| 32 | +- ✅ Multiple team complexity levels |
| 33 | + |
| 34 | +**Usage:** |
| 35 | + |
| 36 | +```bash |
| 37 | +npm run example:console |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. Langfuse Export (`langfuse-example.ts`) |
| 41 | + |
| 42 | +**LLM observability and trace visualization** |
| 43 | + |
| 44 | +- ✅ OTLP export to Langfuse |
| 45 | +- ✅ LLM observability |
| 46 | +- ✅ Trace visualization |
| 47 | +- ✅ Performance monitoring |
| 48 | + |
| 49 | +**Setup:** |
| 50 | + |
| 51 | +```bash |
| 52 | +export LANGFUSE_PUBLIC_KEY="your-public-key" |
| 53 | +export LANGFUSE_SECRET_KEY="your-secret-key" |
| 54 | +npm run example:langfuse |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. SigNoz Export (`signoz-example.ts`) |
| 58 | + |
| 59 | +**Distributed tracing and service monitoring** |
| 60 | + |
| 61 | +- ✅ OTLP export to SigNoz |
| 62 | +- ✅ Distributed tracing |
| 63 | +- ✅ Service map visualization |
| 64 | +- ✅ Performance metrics |
| 65 | + |
| 66 | +**Setup:** |
| 67 | + |
| 68 | +```bash |
| 69 | +export SIGNOZ_ACCESS_TOKEN="your-access-token" |
| 70 | +npm run example:signoz |
| 71 | +``` |
| 72 | + |
| 73 | +### 4. Phoenix Export (`phoenix-example.ts`) |
| 74 | + |
| 75 | +**LLM observability and debugging** |
| 76 | + |
| 77 | +- ✅ OTLP export to Phoenix |
| 78 | +- ✅ LLM observability |
| 79 | +- ✅ Trace visualization |
| 80 | +- ✅ Error tracking |
| 81 | + |
| 82 | +**Setup:** |
| 83 | + |
| 84 | +```bash |
| 85 | +export PHOENIX_API_KEY="your-api-key" |
| 86 | +export PHOENIX_ENDPOINT="https://your-phoenix-instance.com/otel" |
| 87 | +npm run example:phoenix |
| 88 | +``` |
| 89 | + |
| 90 | +### 5. Braintrust Export (`braintrust-example.ts`) |
| 91 | + |
| 92 | +**LLM observability and cost tracking** |
| 93 | + |
| 94 | +- ✅ OTLP export to Braintrust |
| 95 | +- ✅ LLM observability |
| 96 | +- ✅ Cost tracking |
| 97 | +- ✅ Performance optimization |
| 98 | + |
| 99 | +**Setup:** |
| 100 | + |
| 101 | +```bash |
| 102 | +export BRAINTRUST_API_KEY="your-api-key" |
| 103 | +export BRAINTRUST_ENDPOINT="https://www.braintrust.dev/api/v1/otel" |
| 104 | +npm run example:braintrust |
| 105 | +``` |
| 106 | + |
| 107 | +## 🏗️ Shared Teams |
| 108 | + |
| 109 | +All examples use shared teams that range from simple to complex: |
| 110 | + |
| 111 | +### Simple Teams |
| 112 | + |
| 113 | +- **`simple-data`** - Single agent, single task |
| 114 | +- **`content-creation`** - Two agents working in sequence |
| 115 | + |
| 116 | +### Intermediate Teams |
| 117 | + |
| 118 | +- **`resume-creation`** - Multi-agent resume creation |
| 119 | +- **`sports-news`** - Research and content creation |
| 120 | + |
| 121 | +### Complex Teams |
| 122 | + |
| 123 | +- **`trip-planning`** - Multi-phase trip planning |
| 124 | +- **`product-spec`** - Product specification workflow |
| 125 | + |
| 126 | +## 🎯 Usage Examples |
| 127 | + |
| 128 | +### Run Specific Team |
| 129 | + |
| 130 | +```bash |
| 131 | +# Set team name |
| 132 | +export TEAM_NAME="trip-planning" |
| 133 | +npm run example:langfuse |
| 134 | +``` |
| 135 | + |
| 136 | +### Run Multiple Examples |
| 137 | + |
| 138 | +```bash |
| 139 | +# Run multiple teams |
| 140 | +export RUN_TYPE="multiple" |
| 141 | +npm run example:langfuse |
| 142 | +``` |
| 143 | + |
| 144 | +### Run Complex Examples |
| 145 | + |
| 146 | +```bash |
| 147 | +# Run complex teams only |
| 148 | +export RUN_TYPE="complex" |
| 149 | +npm run example:langfuse |
| 150 | +``` |
| 151 | + |
| 152 | +## 🔧 Configuration |
| 153 | + |
| 154 | +### Environment Variables |
| 155 | + |
| 156 | +#### Required for all examples: |
| 157 | + |
| 158 | +- `OPENAI_API_KEY` - OpenAI API key for LLM calls |
| 159 | + |
| 160 | +#### Langfuse: |
| 161 | + |
| 162 | +- `LANGFUSE_PUBLIC_KEY` - Langfuse public key |
| 163 | +- `LANGFUSE_SECRET_KEY` - Langfuse secret key |
| 164 | + |
| 165 | +#### SigNoz: |
| 166 | + |
| 167 | +- `SIGNOZ_ACCESS_TOKEN` - SigNoz access token |
| 168 | + |
| 169 | +#### Phoenix: |
| 170 | + |
| 171 | +- `PHOENIX_API_KEY` - Phoenix API key |
| 172 | +- `PHOENIX_ENDPOINT` - Phoenix OTLP endpoint (optional) |
| 173 | + |
| 174 | +#### Braintrust: |
| 175 | + |
| 176 | +- `BRAINTRUST_API_KEY` - Braintrust API key |
| 177 | +- `BRAINTRUST_ENDPOINT` - Braintrust OTLP endpoint (optional) |
| 178 | + |
| 179 | +### Custom Configuration |
| 180 | + |
| 181 | +```typescript |
| 182 | +import { createOpenTelemetryIntegration } from '@kaibanjs/opentelemetry'; |
| 183 | + |
| 184 | +const config = { |
| 185 | + enabled: true, |
| 186 | + sampling: { |
| 187 | + rate: 1.0, |
| 188 | + strategy: 'always', |
| 189 | + }, |
| 190 | + attributes: { |
| 191 | + includeSensitiveData: false, |
| 192 | + customAttributes: { |
| 193 | + 'service.name': 'my-kaiban-service', |
| 194 | + 'service.version': '1.0.0', |
| 195 | + }, |
| 196 | + }, |
| 197 | + exporters: { |
| 198 | + console: true, |
| 199 | + otlp: { |
| 200 | + endpoint: 'https://your-service.com', |
| 201 | + headers: { |
| 202 | + Authorization: 'Bearer your-token', |
| 203 | + }, |
| 204 | + serviceName: 'my-service', |
| 205 | + }, |
| 206 | + }, |
| 207 | +}; |
| 208 | + |
| 209 | +const integration = createOpenTelemetryIntegration(config); |
| 210 | +``` |
| 211 | + |
| 212 | +## 📊 Semantic Conventions |
| 213 | + |
| 214 | +All examples use KaibanJS semantic conventions: |
| 215 | + |
| 216 | +### LLM Request Attributes (`kaiban.llm.request.*`) |
| 217 | + |
| 218 | +- `kaiban.llm.request.messages` - Input messages |
| 219 | +- `kaiban.llm.request.model` - Model name |
| 220 | +- `kaiban.llm.request.provider` - Provider (openai, anthropic, etc.) |
| 221 | +- `kaiban.llm.request.iteration` - Iteration number |
| 222 | +- `kaiban.llm.request.start_time` - Start time |
| 223 | +- `kaiban.llm.request.status` - Request status |
| 224 | + |
| 225 | +### LLM Usage Attributes (`kaiban.llm.usage.*`) |
| 226 | + |
| 227 | +- `kaiban.llm.usage.input_tokens` - Input tokens |
| 228 | +- `kaiban.llm.usage.output_tokens` - Output tokens |
| 229 | +- `kaiban.llm.usage.total_tokens` - Total tokens |
| 230 | +- `kaiban.llm.usage.cost` - Cost in USD |
| 231 | + |
| 232 | +### LLM Response Attributes (`kaiban.llm.response.*`) |
| 233 | + |
| 234 | +- `kaiban.llm.response.messages` - Output messages |
| 235 | +- `kaiban.llm.response.duration` - Response duration |
| 236 | +- `kaiban.llm.response.status` - Response status |
| 237 | + |
| 238 | +### Span Types |
| 239 | + |
| 240 | +- `kaiban.agent.thinking` - Agent thinking spans |
| 241 | +- `task.execute` - Task execution spans |
| 242 | + |
| 243 | +## 🐛 Troubleshooting |
| 244 | + |
| 245 | +### Common Issues |
| 246 | + |
| 247 | +1. **Missing Environment Variables** |
| 248 | + |
| 249 | + ``` |
| 250 | + Error: Missing required environment variables: OPENAI_API_KEY |
| 251 | + ``` |
| 252 | + |
| 253 | + **Solution:** Set the required environment variables |
| 254 | + |
| 255 | +2. **OTLP Export Failures** |
| 256 | + |
| 257 | + ``` |
| 258 | + Error: OTLP export failed |
| 259 | + ``` |
| 260 | + |
| 261 | + **Solution:** Check your API keys and endpoints |
| 262 | + |
| 263 | +3. **Team Not Found** |
| 264 | + ``` |
| 265 | + Error: Team 'invalid-team' not found |
| 266 | + ``` |
| 267 | + **Solution:** Use a valid team name from the available teams |
| 268 | + |
| 269 | +### Debug Mode |
| 270 | + |
| 271 | +Enable debug mode for detailed logging: |
| 272 | + |
| 273 | +```bash |
| 274 | +export DEBUG=true |
| 275 | +npm run example:langfuse |
| 276 | +``` |
| 277 | + |
| 278 | +## 📚 Additional Resources |
| 279 | + |
| 280 | +- [OpenTelemetry Documentation](https://opentelemetry.io/docs/) |
| 281 | +- [Langfuse Documentation](https://langfuse.com/docs) |
| 282 | +- [SigNoz Documentation](https://signoz.io/docs) |
| 283 | +- [Phoenix Documentation](https://phoenix.arize.com/docs) |
| 284 | +- [Braintrust Documentation](https://www.braintrust.dev/docs) |
| 285 | + |
| 286 | +## 🤝 Contributing |
| 287 | + |
| 288 | +To add a new example: |
| 289 | + |
| 290 | +1. Create a new file: `new-service-example.ts` |
| 291 | +2. Follow the existing pattern |
| 292 | +3. Add configuration and validation |
| 293 | +4. Export from `index.ts` |
| 294 | +5. Update this README |
| 295 | + |
| 296 | +## 📄 License |
| 297 | + |
| 298 | +MIT License - see LICENSE file for details. |
0 commit comments