fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579
Open
guipace wants to merge 2 commits intoDataDog:mainfrom
Open
fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579guipace wants to merge 2 commits intoDataDog:mainfrom
guipace wants to merge 2 commits intoDataDog:mainfrom
Conversation
The gorm.io/gorm.v1 contrib package hardcodes "gorm.db" as the service name, ignoring DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED. This causes gorm.db to appear as a separate service in Datadog APM even when the env var is set to true. Fix by: 1. Adding a naming schema to PackageGormIOGormV1 in packages.go (matching the pattern used by PackageJackcPGXV5) 2. Using instr.ServiceName() instead of the hardcoded string in option.go (matching contrib/jackc/pgx.v5/option.go) Fixes DataDog#4578
rarguelloF
requested changes
Mar 24, 2026
| useDDServiceV0: false, | ||
| buildServiceNameV0: staticName("gorm.db"), | ||
| }, | ||
| }, |
Contributor
There was a problem hiding this comment.
Thanks for the fix! Could we add a test that reproduces the original bug to prevent regressions?
There is a specific test suite for the service names and these configurations in instrumentation/internal/namingschematest. You can add a new testcase in gorm_test.go and add it to the test suite in main_test.go.
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
The
contrib/gorm.io/gorm.v1package hardcodes"gorm.db"as the service name innewConfigWithDefaults(), which meansDD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=truehas no effect. Gorm spans always appear as a separategorm.dbservice in Datadog APM instead of being rolled under the globalDD_SERVICE.By comparison,
contrib/jackc/pgx.v5correctly usesinstr.ServiceName()and respects this env var.Changes
instrumentation/packages.go: Addednamingmap toPackageGormIOGormV1(matching thePackageJackcPGXV5pattern)contrib/gorm.io/gorm.v1/option.go: Replacedcfg.serviceName = "gorm.db"withcfg.serviceName = instr.ServiceName(instrumentation.ComponentDefault, nil)Behavior
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=false(default): service name remains"gorm.db"(no change)DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true: service name falls back toDD_SERVICE(fixed)Fixes #4578