Description
The contrib/gorm.io/gorm.v1 package hardcodes "gorm.db" as the service name in newConfigWithDefaults() (option.go:39):
cfg.serviceName = "gorm.db"
This means DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true has no effect — spans traced through gorm always appear as a separate gorm.db service in Datadog APM instead of being rolled under the global DD_SERVICE.
By comparison, the contrib/jackc/pgx.v5 package correctly uses:
serviceName: instr.ServiceName(instrumentation.ComponentDefault, nil)
Which respects DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED and falls back to DD_SERVICE when enabled.
Root Cause
Two things are missing:
instrumentation/packages.go: PackageGormIOGormV1 has no naming map, unlike PackageJackcPGXV5 which defines one.
contrib/gorm.io/gorm.v1/option.go: newConfigWithDefaults() hardcodes "gorm.db" instead of calling instr.ServiceName().
Expected Behavior
When DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true, gorm spans should use the global DD_SERVICE name instead of gorm.db, matching the behavior of pgx and database/sql integrations.
Proposed Fix
- Add a
naming map to PackageGormIOGormV1 in instrumentation/packages.go (matching the pgx pattern)
- Replace
cfg.serviceName = "gorm.db" with cfg.serviceName = instr.ServiceName(instrumentation.ComponentDefault, nil) in contrib/gorm.io/gorm.v1/option.go
Environment
- dd-trace-go v2.6.0
- Using Orchestrion auto-instrumentation
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true
DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED=true
Description
The
contrib/gorm.io/gorm.v1package hardcodes"gorm.db"as the service name innewConfigWithDefaults()(option.go:39):This means
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=truehas no effect — spans traced through gorm always appear as a separategorm.dbservice in Datadog APM instead of being rolled under the globalDD_SERVICE.By comparison, the
contrib/jackc/pgx.v5package correctly uses:Which respects
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLEDand falls back toDD_SERVICEwhen enabled.Root Cause
Two things are missing:
instrumentation/packages.go:PackageGormIOGormV1has nonamingmap, unlikePackageJackcPGXV5which defines one.contrib/gorm.io/gorm.v1/option.go:newConfigWithDefaults()hardcodes"gorm.db"instead of callinginstr.ServiceName().Expected Behavior
When
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=true, gorm spans should use the globalDD_SERVICEname instead ofgorm.db, matching the behavior of pgx and database/sql integrations.Proposed Fix
namingmap toPackageGormIOGormV1ininstrumentation/packages.go(matching the pgx pattern)cfg.serviceName = "gorm.db"withcfg.serviceName = instr.ServiceName(instrumentation.ComponentDefault, nil)incontrib/gorm.io/gorm.v1/option.goEnvironment
DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED=trueDD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED=true