Commit cf44d1b
authored
chore: add PostHog telemetry tracing for LLM assistant operations (baserow#4299)
* Add PostHog telemetry tracing for LLM assistant operations
This commit adds comprehensive PostHog telemetry integration to track
and analyze LLM assistant operations including:
- uDSPy module execution (ChainOfThought, ReAct, Predict)
- LLM API calls with automatic generation tracking
- Tool invocations
- Performance metrics (latency, token usage)
- Error tracking with exception messages
The telemetry system:
- Captures hierarchical span relationships for nested operations
- Patches OpenAI client for automatic generation event tracking
- Handles errors gracefully without breaking assistant execution
- Respects POSTHOG_ENABLED setting
- Adds workspace and user context to all events
Run the telemetry test suite:
```bash
just pytest -k test_telemetry
```
All 8 tests should pass, covering:
- Trace context manager (success and exception paths)
- Module execution tracing (ChainOfThought, ReAct, Predict)
- LM callback enrichment
- Tool execution tracing
- Exception handling (module and tool failures)
- Telemetry disabled state
To test manually:
1. Ensure POSTHOG_ENABLED=True in settings
2. Set up PostHog project credentials
3. Use the assistant and verify events appear in PostHog
4. Check for $ai_trace, $ai_span, and $ai_generation events
5. Verify span hierarchy and context propagation
* Fix issue when POSTHOG_PROJECT_API_KEY is not set
* Fix tests; capture all spans; add trace input and output
* Bump udspy version1 parent 39e7722 commit cf44d1b
File tree
9 files changed
+635
-58
lines changed- backend
- requirements
- src/baserow
- config/settings
- core
- tests/baserow/core
- enterprise/backend
- src/baserow_enterprise/assistant
- tests/baserow_enterprise_tests/assistant
9 files changed
+635
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
314 | | - | |
315 | | - | |
316 | 315 | | |
317 | 316 | | |
318 | 317 | | |
| |||
454 | 453 | | |
455 | 454 | | |
456 | 455 | | |
457 | | - | |
| 456 | + | |
458 | 457 | | |
459 | 458 | | |
460 | 459 | | |
| |||
665 | 664 | | |
666 | 665 | | |
667 | 666 | | |
| 667 | + | |
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
682 | | - | |
| 682 | + | |
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
1243 | 1242 | | |
1244 | 1243 | | |
1245 | 1244 | | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
| 1245 | + | |
| 1246 | + | |
1253 | 1247 | | |
1254 | 1248 | | |
1255 | 1249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
| |||
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | | - | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
Lines changed: 32 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
193 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
209 | 230 | | |
210 | 231 | | |
211 | 232 | | |
| |||
360 | 381 | | |
361 | 382 | | |
362 | 383 | | |
363 | | - | |
| 384 | + | |
364 | 385 | | |
365 | 386 | | |
366 | 387 | | |
| |||
449 | 470 | | |
450 | 471 | | |
451 | 472 | | |
452 | | - | |
| 473 | + | |
453 | 474 | | |
454 | 475 | | |
455 | 476 | | |
| |||
472 | 493 | | |
473 | 494 | | |
474 | 495 | | |
475 | | - | |
476 | 496 | | |
477 | 497 | | |
478 | 498 | | |
| |||
510 | 530 | | |
511 | 531 | | |
512 | 532 | | |
513 | | - | |
| 533 | + | |
514 | 534 | | |
515 | 535 | | |
516 | 536 | | |
| |||
586 | 606 | | |
587 | 607 | | |
588 | 608 | | |
| 609 | + | |
589 | 610 | | |
590 | 611 | | |
591 | 612 | | |
592 | | - | |
593 | | - | |
| 613 | + | |
| 614 | + | |
594 | 615 | | |
595 | 616 | | |
596 | 617 | | |
| |||
0 commit comments