Add Go-specific telemetry design document#298
Merged
samikshya-db merged 1 commit intomainfrom Nov 5, 2025
Merged
Conversation
This design document provides a comprehensive telemetry system design adapted specifically for the databricks-sql-go driver following Go best practices and idiomatic patterns. Key Go-specific adaptations: - Replaced C# Activity/ActivitySource with context.Context and interceptors - Used goroutines and channels for async operations - Applied sync.RWMutex and sync.Once for thread-safe singletons - Implemented circuit breaker pattern with Go idioms - Used defer/recover for error handling - Followed Go naming conventions (unexported types, camelCase) - Designed around standard library patterns (http.Client, context) - Included Go-specific testing patterns (unit, integration, benchmarks) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
jadewang-db
approved these changes
Nov 5, 2025
Collaborator
Author
|
Merging this at the moment, verified go best practices. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a comprehensive telemetry design document specifically adapted for the
databricks-sql-godriver. The design was transformed from a C#/.NET ADBC driver design to follow Go best practices and idiomatic patterns.Go-Specific Adaptations
This design document has been completely rewritten to align with Go conventions and the existing codebase patterns:
1. Replaced C#/.NET Concepts with Go Equivalents
Activity/ActivitySourcecontext.Context+ middleware interceptorsActivityListenerasync/awaitConcurrentDictionarymapwithsync.RWMutexIDisposableClose()methods2. Applied Go Naming Conventions
featureFlagCache,clientManager,metricsAggregator(lowercase for internal types)mufor mutex,cfgfor config,ctxfor contexttelemetry)3. Idiomatic Go Code Patterns
Concurrency & Thread Safety
```go
// Singleton with sync.Once
var (
managerOnce sync.Once
managerInstance *clientManager
)
func getClientManager() *clientManager {
managerOnce.Do(func() {
managerInstance = &clientManager{
clients: make(map[string]*clientHolder),
}
})
return managerInstance
}
// Thread-safe operations with RWMutex
func (m *clientManager) getOrCreateClient(host string, ...) *telemetryClient {
m.mu.Lock()
defer m.mu.Unlock()
// ...
}
```
Context Propagation
```go
// Context-based metric collection
func (i *interceptor) beforeExecute(ctx context.Context, statementID string) context.Context {
mc := &metricContext{
statementID: statementID,
startTime: time.Now(),
tags: make(map[string]interface{}),
}
return withMetricContext(ctx, mc)
}
```
Error Handling
```go
// Defer/recover pattern for error swallowing
func recoverAndLog(operation string) {
if r := recover(); r != nil {
// Log at trace level only
}
}
func (i *interceptor) afterExecute(ctx context.Context, err error) {
defer recoverAndLog("afterExecute")
// Telemetry logic
}
```
4. Async Patterns with Goroutines
```go
// Background flush loop
func (agg *metricsAggregator) flushLoop() {
ticker := time.NewTicker(agg.flushInterval)
defer ticker.Stop()
}
// Async export
go func() {
defer recoverAndLog("export")
agg.exporter.export(ctx, metrics)
}()
```
5. Standard Library Integration
6. Driver Integration Points
In `connector.go`
```go
func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
// ... existing code ...
}
```
In `statement.go`
```go
func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
if s.conn.telemetry != nil {
ctx = s.conn.telemetry.beforeExecute(ctx, statementID)
defer func() {
s.conn.telemetry.afterExecute(ctx, err)
}()
}
// ... existing implementation ...
}
```
7. Testing Strategy
```go
func BenchmarkInterceptor_Overhead(b *testing.B) {
// ... setup ...
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx = interceptor.beforeExecute(ctx, "stmt-123")
interceptor.afterExecute(ctx, nil)
}
}
```
Key Design Features
Per-Host Resource Management
Privacy & Security
Reliability
File Structure
```
telemetry/
├── DESIGN.md # This comprehensive design document
├── config.go # Configuration types
├── tags.go # Tag definitions and filtering
├── featureflag.go # Per-host feature flag caching
├── manager.go # Per-host client management
├── circuitbreaker.go # Circuit breaker implementation
├── interceptor.go # Telemetry interceptor
├── aggregator.go # Metrics aggregation
├── exporter.go # Export to Databricks
├── client.go # Telemetry client
├── errors.go # Error classification
└── *_test.go # Test files
```
Alignment with Existing Codebase
This design follows patterns observed in:
Next Steps
This is a design document only. Implementation will be tracked in separate PRs following the implementation checklist in the design.
Related Work
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com