feat: [#726] database auto instrumentation [8]#1477
Draft
krishankumar01 wants to merge 6 commits into
Draft
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1477 +/- ##
==========================================
+ Coverage 69.36% 69.37% +0.01%
==========================================
Files 374 378 +4
Lines 29666 29876 +210
==========================================
+ Hits 20578 20727 +149
- Misses 8140 8179 +39
- Partials 948 970 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry database instrumentation to Goravel, covering GORM operations, query-builder calls, and connection-pool metrics, with a config toggle to enable/disable the feature.
Changes:
- Introduces a new
telemetry/instrumentation/databasepackage (spans, operation-duration histogram, pool stats metrics, and wrappers for DB builders). - Wires database instrumentation into GORM connection setup and DB query builder execution paths behind
telemetry.instrumentation.database.enabled. - Adjusts
Tx.Selectto execute parameterized SQL (placeholders) while still logging the explained SQL, and adds tests around the behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| telemetry/setup/stubs.go | Adds default config stub for database instrumentation enablement. |
| telemetry/instrumentation/database/database.go | Core DB span + duration metric helpers and semantic attributes. |
| telemetry/instrumentation/database/database_test.go | Unit tests for DB system mapping, operation parsing, and recordable-error filtering. |
| telemetry/instrumentation/database/pool.go | Registers observable metrics from sql.DBStats for connection pool telemetry. |
| telemetry/instrumentation/database/pool_test.go | Validates pool metric registration and emitted metric names/attributes. |
| telemetry/instrumentation/database/gorm.go | GORM plugin to create spans for ORM operations and optionally register pool metrics once. |
| telemetry/instrumentation/database/gorm_test.go | Ensures GORM spans are created, named, and do not include interpolated bound values. |
| telemetry/instrumentation/database/builder.go | Wraps query-builder interfaces to create spans/metrics for sqlx operations. |
| telemetry/instrumentation/database/builder_test.go | Tests traced builder wrappers for spans and error status behavior. |
| telemetry/instrumentation/database/helpers_test.go | Shared test telemetry setup (recording exporter + facade mocking). |
| database/driver/gorm.go | Enables GORM plugin registration (with pool metrics) when database instrumentation is enabled. |
| database/db/db.go | Enables builder wrapping + fixes Tx.Select to execute parameterized SQL while logging explained SQL. |
| database/db/db_test.go | Tests that Tx.Select passes placeholder SQL through to builder methods. |
Comment on lines
+24
to
+27
| func RegisterPoolMetrics(db *sql.DB, driverName, poolName string) error { | ||
| if telemetry.Facade == nil { | ||
| return nil | ||
| } |
Comment on lines
+83
to
+87
| for _, ignored := range []error{gorm.ErrRecordNotFound, sql.ErrNoRows, driver.ErrSkip, io.EOF} { | ||
| if errors.Is(err, ignored) { | ||
| return false | ||
| } | ||
| } |
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.
📑 Description
RelatedTo goravel/goravel#726
✅ Checks