Skip to content

feat(database): add automatic connection attribute extraction - #9

Merged
karthikeyangs9 merged 1 commit into
mainfrom
feat/database-connection-attributes
Feb 6, 2026
Merged

feat(database): add automatic connection attribute extraction#9
karthikeyangs9 merged 1 commit into
mainfrom
feat/database-connection-attributes

Conversation

@prathamesh-sonpatki

Copy link
Copy Markdown
Member

Summary

Automatically extracts database connection attributes from DSN (Data Source Name) and adds them to OpenTelemetry spans following semantic conventions v1.25.0.

Problem

Database spans were missing crucial connection metadata:

  • server.address (replaces deprecated net.peer.name)
  • server.port
  • db.user
  • db.name

This made it difficult to:

  • Filter spans by specific database hosts/ports
  • Track connections across replicas/shards
  • Troubleshoot connection issues

Solution

Added DSN parsing functions that automatically extract connection attributes.

Changes

integrations/database/database.go

  • Added DSN parsing functions (PostgreSQL, MySQL)
  • Integrated attribute extraction into Open()

tests/integration/database_test.go

  • Added TestDatabase_ConnectionAttributes
  • Validates: server.address, server.port, db.user, db.name, db.system

README.md

  • Documented automatic connection attribute extraction

Testing

✅ All existing tests pass
✅ New integration test validates connection attributes

Benefits

✅ Zero configuration - Works automatically from DSN
✅ OTel compliant - Uses semantic conventions v1.25.0
✅ Better observability - Full connection metadata in every span


🤖 Co-Authored-By: Claude Sonnet 4.5

- Parse DSN to extract server.address, server.port, db.user, db.name
- Support PostgreSQL, MySQL DSN formats
- Use OpenTelemetry semantic conventions v1.25.0 (server.address replaces net.peer.name)
- Add comprehensive integration test for connection attributes
- Update README with connection attributes documentation

This enables better observability by automatically capturing:
- Database host and port information
- User information
- Database name
All attributes follow OTel semantic conventions for consistency.

Benefits:
- Better filtering and querying of database spans
- Connection tracking across replicas/shards
- Improved troubleshooting capabilities
- Zero configuration required - works automatically from DSN

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@karthikeyangs9
karthikeyangs9 merged commit c9808f1 into main Feb 6, 2026
10 checks passed
@prathamesh-sonpatki
prathamesh-sonpatki deleted the feat/database-connection-attributes branch February 6, 2026 10:06
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