Skip to content

Comments

feat(go/adbc): add context.Context support for uniform OpenTelemetry instrumentation#4009

Open
zeroshade wants to merge 7 commits intoapache:mainfrom
zeroshade:go-contexts
Open

feat(go/adbc): add context.Context support for uniform OpenTelemetry instrumentation#4009
zeroshade wants to merge 7 commits intoapache:mainfrom
zeroshade:go-contexts

Conversation

@zeroshade
Copy link
Member

Summary

Implements context.Context support for all Go ADBC methods to enable uniform OpenTelemetry instrumentation, cancellation, and deadline propagation (addresses #2772).

  • Add DatabaseContext, ConnectionContext, and StatementContext interfaces that mirror existing interfaces but require context.Context for all methods
  • Add extension Context interfaces: PostInitOptionsContext, GetSetOptionsContext, ConnectionGetStatisticsContext, StatementExecuteSchemaContext
  • Implement adapter functions (AsDatabaseContext, AsConnectionContext, AsStatementContext) to wrap non-context implementations for backward compatibility
  • Add IngestStreamContext helper for context-aware bulk ingestion
  • Comprehensive test suite (9 tests, all passing)

Changes

New Interfaces (go/adbc/adbc.go):

  • DatabaseContext - Database with context support for all operations
  • ConnectionContext - Connection with context support for all operations
  • StatementContext - Statement with context support for all operations
  • Extension interfaces with context support

Adapter Implementation (go/adbc/context_adapters.go):

  • Three adapter types that wrap non-context implementations
  • Proper nil handling and double-wrap prevention
  • Context pass-through for methods that already accept context
  • Clear documentation about context limitations for legacy methods

Tests (go/adbc/context_adapters_test.go):

  • Comprehensive test coverage for all adapters
  • Tests for error handling, nil handling, and context pass-through
  • All tests passing with race detector

Documentation & Examples:

  • Updated package documentation explaining Context interfaces
  • Added IngestStreamContext helper function
  • Example code demonstrating adapter usage

Migration Path

For Applications:

// Wrap existing Database to add context support
db := driver.NewDatabase(opts)
dbCtx := adbc.AsDatabaseContext(db)

ctx := context.Background()
conn, err := dbCtx.Open(ctx)

For Driver Implementers:

  • Existing drivers work unchanged via adapters
  • New drivers should implement Context interfaces directly
  • Gradual migration supported - no breaking changes

Test Plan

  • All adapter tests passing (9/9)
  • Race detector: PASS
  • Backward compatibility verified (existing tests unchanged)
  • Documentation examples compile

Notes

This is the first step toward uniform OpenTelemetry support. Future work includes:

  • Updating individual drivers to implement Context interfaces natively
  • Adding context-aware tests to validation suite
  • Enhanced tracing instrumentation using context propagation

- Add DatabaseContext, ConnectionContext, StatementContext interfaces
- Add extension Context interfaces (PostInitOptions, GetSetOptions, etc.)
- Add context_adapters.go with DatabaseContext adapter implementation
- Add context_adapters_test.go with tests for DatabaseContext adapter
- Update .gitignore to exclude docs/plans

Relates to apache#2772
Implement adapter to wrap existing Connection and Statement implementations
as ConnectionContext and StatementContext for backward compatibility.

Relates to apache#2772
Ensure adapters handle nil inputs correctly and return nil when
given nil inputs. Tests verify that AsDatabaseContext, AsConnectionContext,
and AsStatementContext all handle nil correctly.

Note: Tests for avoiding double-wrapping are not applicable because
Database/DatabaseContext, Connection/ConnectionContext, and
Statement/StatementContext have conflicting method signatures (Close()
vs Close(ctx)), making it impossible for a type to implement both
interfaces simultaneously.

Relates to apache#2772
- Update package docs to explain Context interfaces
- Add IngestStreamContext helper for context-aware ingestion
- Add example code demonstrating Context usage

Relates to apache#2772
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants