Skip to content

fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579

Closed
guipace wants to merge 2 commits into
DataDog:mainfrom
going-dev:fix/gorm-respect-remove-integration-service-names
Closed

fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579
guipace wants to merge 2 commits into
DataDog:mainfrom
going-dev:fix/gorm-respect-remove-integration-service-names

Conversation

@guipace

@guipace guipace commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Summary

The contrib/gorm.io/gorm.v1 package hardcodes "gorm.db" as the service name in newConfigWithDefaults(), which means DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true has no effect. Gorm spans always appear as a separate gorm.db service in Datadog APM instead of being rolled under the global DD_SERVICE.

By comparison, contrib/jackc/pgx.v5 correctly uses instr.ServiceName() and respects this env var.

Changes

  1. instrumentation/packages.go: Added naming map to PackageGormIOGormV1 (matching the PackageJackcPGXV5 pattern)
  2. contrib/gorm.io/gorm.v1/option.go: Replaced cfg.serviceName = "gorm.db" with cfg.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 to DD_SERVICE (fixed)

Fixes #4578

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
@guipace
guipace requested review from a team as code owners March 20, 2026 20:38
useDDServiceV0: false,
buildServiceNameV0: staticName("gorm.db"),
},
},

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, just saw this. Glad we're able to get a fix in place.

@rarguelloF

Copy link
Copy Markdown
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!

@rarguelloF rarguelloF closed this Mar 31, 2026
@guipace
guipace deleted the fix/gorm-respect-remove-integration-service-names branch March 31, 2026 12:52
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]>
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.

gorm.io/gorm.v1 contrib does not respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED

2 participants