Skip to content

feat: [#726] database auto instrumentation [8]#1477

Draft
krishankumar01 wants to merge 6 commits into
masterfrom
kkumar-gcc/#726-database-instrumentation
Draft

feat: [#726] database auto instrumentation [8]#1477
krishankumar01 wants to merge 6 commits into
masterfrom
kkumar-gcc/#726-database-instrumentation

Conversation

@krishankumar01

@krishankumar01 krishankumar01 commented Jun 7, 2026

Copy link
Copy Markdown
Member

📑 Description

RelatedTo goravel/goravel#726

✅ Checks

  • Added test cases for my code

@krishankumar01 krishankumar01 requested a review from a team as a code owner June 7, 2026 10:39
Copilot AI review requested due to automatic review settings June 7, 2026 10:39
@krishankumar01 krishankumar01 changed the title Kkumar gcc/#726 database instrumentation feat: [#726] database auto instrumentation Jun 7, 2026
@krishankumar01 krishankumar01 marked this pull request as draft June 7, 2026 10:40
@krishankumar01 krishankumar01 changed the title feat: [#726] database auto instrumentation feat: [#726] database auto instrumentation [8] Jun 7, 2026
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.74439% with 92 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.37%. Comparing base (397b582) to head (55b6477).

Files with missing lines Patch % Lines
telemetry/instrumentation/database/gorm.go 41.66% 16 Missing and 12 partials ⚠️
database/db/db.go 0.00% 21 Missing and 2 partials ⚠️
telemetry/instrumentation/database/builder.go 63.82% 14 Missing and 3 partials ⚠️
database/driver/gorm.go 0.00% 11 Missing ⚠️
telemetry/instrumentation/database/pool.go 71.42% 4 Missing and 4 partials ⚠️
telemetry/setup/stubs.go 0.00% 3 Missing ⚠️
telemetry/instrumentation/database/database.go 96.82% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/database package (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.Select to 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
}
}
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