Skip to content

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

@guipace

Description

@guipace

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:

  1. instrumentation/packages.go: PackageGormIOGormV1 has no naming map, unlike PackageJackcPGXV5 which defines one.
  2. 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

  1. Add a naming map to PackageGormIOGormV1 in instrumentation/packages.go (matching the pgx pattern)
  2. 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

Metadata

Metadata

Assignees

Labels

bugunintended behavior that has to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions