Skip to content

fix(gorm): respect DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED#4579

Open
guipace wants to merge 2 commits intoDataDog:mainfrom
going-dev:fix/gorm-respect-remove-integration-service-names
Open

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

Conversation

@guipace
Copy link
Copy Markdown

@guipace guipace commented Mar 20, 2026

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.

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