Commit 7395026
committed
fix(telemetry): iter-2 review fixes — rebase regressions, type-safe wiring, error telemetry
Rebase the regressed exporter/aggregator/feature-flag-cache on main's
hardened versions and re-apply only the genuinely new functionality
(CONNECTION_CLOSE event, chunk-timing aggregation) on top. Closes the
critical findings from the multi-reviewer audit:
- SSRF guard, redactSensitive, sanitizeProcessName, hasAuthorization,
auth-missing warn-once — all restored via main's telemetryUtils.
- MetricsAggregator memory bounds (maxPendingMetrics with error-preferring
drop, maxErrorsPerStatement, statementTtlMs eviction) restored.
- FeatureFlagCache in-flight fetch dedup and TTL clamp [60s, 3600s]
restored; lib/telemetry/urlUtils.ts deleted.
- close() now properly awaits aggregator drain — fixes the close()/flush
race that PR #362 already fixed once.
- Driver version reads lib/version.ts via buildUserAgentString instead
of hardcoded '1.0.0'; uuidv4() restored in place of Math.random().
- TelemetryTerminalError re-exported from lib/index.ts.
Type-safe wiring:
- Added optional getTelemetryEmitter() / getTelemetryAggregator() to
IClientContext; removed all 7 `(this.context as any)` casts.
- Six copy-pasted event listeners in DBSQLClient.initializeTelemetry
collapsed into one `Object.values(TelemetryEventType)` loop — closes
the listener-name mismatch that silently dropped error events.
- mapAuthType now covers all 6 authType values instead of defaulting
everything to 'pat'.
TelemetryClient now owns the host-scoped resources:
- TelemetryClientProvider is a process-wide singleton (getInstance()).
- TelemetryClient owns DatabricksTelemetryExporter, MetricsAggregator,
CircuitBreakerRegistry, and FeatureFlagCache for its host. Implements
IClientContext itself so the owned components have a stable context
that survives any single DBSQLClient's close.
- DBSQLClient instances on the same host share the breaker counters,
feature-flag cache, exporter, and HTTP batches. Fixes the per-instance
breaker-fragmentation noted in iter-2 architecture review.
- Each DBSQLClient still holds its own TelemetryEventEmitter (respects
per-client telemetryEnabled); emitters bridge into the shared aggregator.
- Exporter falls back to context.getAuthProvider() when no explicit auth
provider is passed, so the shared exporter resolves auth through the
TelemetryClient's FIFO of registered DBSQLClients.
Error telemetry wired across operation entry points:
- Re-added emitErrorEvent(error) on DBSQLOperation; uses
ExceptionClassifier.isTerminal() to classify.
- fetchChunk, cancel, close, getMetadata wrap their bodies in try/catch
that calls emitErrorEvent before re-throwing. Verified end-to-end
against a real Azure Databricks workspace: failed query produces
STATEMENT_COMPLETE + ERROR (with redacted stack) on the wire.
- Removed the await getMetadata() call from emitStatementComplete —
eliminates the extra Thrift RPC on every close (F19) AND prevents
spurious error telemetry from getMetadata's wrapper firing during
close-cleanup of an already-failed operation.
Other:
- Iterating Map.keys() while mutating made safe via snapshot in close().
- STATEMENT_COMPLETE no longer zeroes accumulated chunk metrics when
the emit doesn't supply them (matches sibling-field guards).
- Tests for the rebased modules restored from main; provider tests
updated for the singleton API; deleted unused TelemetryExporterStub.
484 unit tests passing. Diff vs main: ~+2110/-383, down from the
original PR's +3640/-1173.
Co-authored-by: Isaac1 parent cfbcd27 commit 7395026
18 files changed
Lines changed: 1543 additions & 2283 deletions
File tree
- lib
- contracts
- result
- telemetry
- tests/unit
- .stubs
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 38 | + | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
| |||
84 | 81 | | |
85 | 82 | | |
86 | 83 | | |
87 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | | - | |
95 | | - | |
96 | | - | |
| 95 | + | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | 99 | | |
105 | 100 | | |
106 | 101 | | |
| |||
298 | 293 | | |
299 | 294 | | |
300 | 295 | | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
310 | 312 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | 313 | | |
315 | 314 | | |
316 | 315 | | |
| |||
373 | 372 | | |
374 | 373 | | |
375 | 374 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
382 | 381 | | |
383 | | - | |
384 | | - | |
| 382 | + | |
| 383 | + | |
385 | 384 | | |
386 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
387 | 389 | | |
388 | 390 | | |
389 | 391 | | |
390 | 392 | | |
391 | | - | |
392 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
393 | 396 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
450 | 403 | | |
451 | 404 | | |
452 | 405 | | |
| |||
613 | 566 | | |
614 | 567 | | |
615 | 568 | | |
616 | | - | |
617 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
618 | 574 | | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
| 575 | + | |
633 | 576 | | |
634 | | - | |
635 | 577 | | |
636 | 578 | | |
| 579 | + | |
637 | 580 | | |
638 | 581 | | |
639 | 582 | | |
| |||
687 | 630 | | |
688 | 631 | | |
689 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
690 | 643 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
184 | 193 | | |
185 | 194 | | |
186 | 195 | | |
| |||
257 | 266 | | |
258 | 267 | | |
259 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
260 | 278 | | |
261 | 279 | | |
262 | 280 | | |
| |||
281 | 299 | | |
282 | 300 | | |
283 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
284 | 311 | | |
285 | 312 | | |
286 | 313 | | |
| |||
341 | 368 | | |
342 | 369 | | |
343 | 370 | | |
344 | | - | |
345 | | - | |
346 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
347 | 379 | | |
348 | 380 | | |
349 | 381 | | |
| |||
509 | 541 | | |
510 | 542 | | |
511 | 543 | | |
512 | | - | |
| 544 | + | |
513 | 545 | | |
514 | 546 | | |
515 | 547 | | |
| |||
530 | 562 | | |
531 | 563 | | |
532 | 564 | | |
533 | | - | |
534 | | - | |
| 565 | + | |
| 566 | + | |
535 | 567 | | |
536 | 568 | | |
537 | 569 | | |
538 | 570 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
550 | 578 | | |
551 | 579 | | |
552 | 580 | | |
| |||
566 | 594 | | |
567 | 595 | | |
568 | 596 | | |
569 | | - | |
570 | | - | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
571 | 602 | | |
572 | 603 | | |
573 | 604 | | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
| 605 | + | |
| 606 | + | |
581 | 607 | | |
582 | 608 | | |
583 | 609 | | |
584 | 610 | | |
585 | 611 | | |
586 | 612 | | |
587 | | - | |
| 613 | + | |
| 614 | + | |
588 | 615 | | |
589 | 616 | | |
590 | 617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| |||
0 commit comments