fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579
Closed
guipace wants to merge 2 commits into
Closed
fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579guipace wants to merge 2 commits into
guipace wants to merge 2 commits into
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.
Contributor
Author
There was a problem hiding this comment.
Sorry, just saw this. Glad we're able to get a fix in place.
9 tasks
Contributor
|
I added the missing test in #4618 (I didn't have permissions to push to your fork), so we will continue there. Thanks for your contribution! |
gh-worker-dd-mergequeue-cf854d Bot
pushed a commit
that referenced
this pull request
Apr 8, 2026
…4618) <!-- * New contributors are highly encouraged to read our [CONTRIBUTING](/CONTRIBUTING.md) documentation. * Commit and PR titles should be prefixed with the general area of the pull request's change. --> ### What does this PR do? <!-- * A brief description of the change being made with this pull request. * If the description here cannot be expressed in a succinct form, consider opening multiple pull requests instead of a single one. --> (continuation of #4579) 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 #4578 ### Motivation <!-- * What inspired you to submit this pull request? * Link any related GitHub issues or PRs here. * If this resolves a GitHub issue, include "Fixes #XXXX" to link the issue and auto-close it on merge. --> ### Reviewer's Checklist <!-- * Authors can use this list as a reference to ensure that there are no problems during the review but the signing off is to be done by the reviewer(s). --> - [ ] Changed code has unit tests for its functionality at or near 100% coverage. - [ ] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag. - [ ] There is a benchmark for any new code, or changes to existing code. - [ ] If this interacts with the agent in a new way, a system test has been added. - [ ] New code is free of linting errors. You can check this by running `make lint` locally. - [ ] New code doesn't break existing tests. You can check this by running `make test` locally. - [ ] Add an appropriate team label so this PR gets put in the right place for the release notes. - [ ] All generated files are up to date. You can check this by running `make generate` locally. - [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running `make fix-modules` locally. Unsure? Have a question? Request a review! Co-authored-by: hannahkm <[email protected]> Co-authored-by: guipace <[email protected]>
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