Skip to content

Commit 291847a

Browse files
[mq] [skip ddci] working branch - merge 7469c18 on top of main at 56e391d
{"baseBranch":"main","baseCommit":"56e391d86a430b72572115bb7a1e5ed13699fe35","createdAt":"2026-04-08T08:59:21.404808Z","headSha":"7469c18fee3b600d47cb8da8a5653252851062f7","id":"e50b0f07-99f2-4d5a-a8e1-5e23f558a11c","nextMergeabilityCheckAt":"2026-04-08T10:39:02.993358Z","priority":"200","pullRequestNumber":"4618","queuedAt":"2026-04-08T09:39:07.483053Z","status":"STATUS_QUEUED"}
2 parents 237e567 + 7469c18 commit 291847a

6 files changed

Lines changed: 91 additions & 6 deletions

File tree

contrib/gorm.io/gorm.v1/option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (fn OptionFn) apply(cfg *config) {
3636

3737
func newConfigWithDefaults() *config {
3838
cfg := new(config)
39-
cfg.serviceName = "gorm.db"
39+
cfg.serviceName = instr.ServiceName(instrumentation.ComponentDefault, nil)
4040
cfg.serviceSource = string(instrumentation.PackageGormIOGormV1)
4141
cfg.analyticsRate = instr.AnalyticsRate(false)
4242
cfg.errCheck = func(error) bool { return true }

instrumentation/internal/namingschematest/go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v1/v2 v2.6.0-dev.1
1515
github.com/DataDog/dd-trace-go/contrib/confluentinc/confluent-kafka-go/kafka.v2/v2 v2.6.0-dev.1
1616
github.com/DataDog/dd-trace-go/contrib/confluentinc/confluent-kafka-go/kafka/v2 v2.6.0-dev.1
17-
github.com/DataDog/dd-trace-go/contrib/database/sql/v2 v2.7.0-dev.1
17+
github.com/DataDog/dd-trace-go/contrib/database/sql/v2 v2.9.0-dev
1818
github.com/DataDog/dd-trace-go/contrib/dimfeld/httptreemux.v5/v2 v2.6.0-dev.1
1919
github.com/DataDog/dd-trace-go/contrib/elastic/go-elasticsearch.v6/v2 v2.6.0-dev.1
2020
github.com/DataDog/dd-trace-go/contrib/emicklei/go-restful.v3/v2 v2.6.0-dev.1
@@ -32,6 +32,7 @@ require (
3232
github.com/DataDog/dd-trace-go/contrib/gomodule/redigo/v2 v2.6.0-dev.1
3333
github.com/DataDog/dd-trace-go/contrib/google.golang.org/grpc/v2 v2.6.0-dev.1
3434
github.com/DataDog/dd-trace-go/contrib/gorilla/mux/v2 v2.6.0-dev.1
35+
github.com/DataDog/dd-trace-go/contrib/gorm.io/gorm.v1/v2 v2.6.0-dev.1
3536
github.com/DataDog/dd-trace-go/contrib/graph-gophers/graphql-go/v2 v2.6.0-dev.1
3637
github.com/DataDog/dd-trace-go/contrib/graphql-go/graphql/v2 v2.6.0-dev.1
3738
github.com/DataDog/dd-trace-go/contrib/hashicorp/consul/v2 v2.6.0-dev.1
@@ -103,6 +104,8 @@ require (
103104
google.golang.org/api v0.258.0
104105
google.golang.org/grpc v1.79.3
105106
gopkg.in/olivere/elastic.v5 v5.0.84
107+
gorm.io/driver/postgres v1.5.5
108+
gorm.io/gorm v1.25.12
106109
)
107110

108111
require (
@@ -239,6 +242,7 @@ require (
239242
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
240243
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
241244
github.com/jinzhu/inflection v1.0.0 // indirect
245+
github.com/jinzhu/now v1.1.5 // indirect
242246
github.com/jmespath/go-jmespath v0.4.0 // indirect
243247
github.com/josharian/intern v1.0.0 // indirect
244248
github.com/json-iterator/go v1.1.12 // indirect
@@ -462,3 +466,5 @@ replace github.com/DataDog/dd-trace-go/contrib/redis/rueidis/v2 => ../../../cont
462466
replace github.com/DataDog/dd-trace-go/contrib/valkey-io/valkey-go/v2 => ../../../contrib/valkey-io/valkey-go
463467

464468
replace github.com/DataDog/dd-trace-go/contrib/valyala/fasthttp/v2 => ../../../contrib/valyala/fasthttp
469+
470+
replace github.com/DataDog/dd-trace-go/contrib/gorm.io/gorm.v1/v2 => ../../../contrib/gorm.io/gorm.v1

instrumentation/internal/namingschematest/go.sum

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2024 Datadog, Inc.
5+
6+
package namingschematest
7+
8+
import (
9+
"context"
10+
"testing"
11+
12+
"github.com/stretchr/testify/assert"
13+
"github.com/stretchr/testify/require"
14+
"gorm.io/driver/postgres"
15+
"gorm.io/gorm"
16+
17+
gormtrace "github.com/DataDog/dd-trace-go/contrib/gorm.io/gorm.v1/v2"
18+
"github.com/DataDog/dd-trace-go/instrumentation/internal/namingschematest/v2/harness"
19+
20+
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"
21+
"github.com/DataDog/dd-trace-go/v2/instrumentation"
22+
)
23+
24+
var gormTest = harness.TestCase{
25+
Name: instrumentation.PackageGormIOGormV1,
26+
GenSpans: func(t *testing.T, serviceOverride string) []*mocktracer.Span {
27+
var opts []gormtrace.Option
28+
if serviceOverride != "" {
29+
opts = append(opts, gormtrace.WithService(serviceOverride))
30+
}
31+
mt := mocktracer.Start()
32+
defer mt.Stop()
33+
34+
db, err := gormtrace.Open(
35+
postgres.Open("postgres://postgres:[email protected]:5432/postgres?sslmode=disable"),
36+
&gorm.Config{},
37+
opts...,
38+
)
39+
require.NoError(t, err)
40+
41+
sqlDB, err := db.DB()
42+
require.NoError(t, err)
43+
defer sqlDB.Close()
44+
45+
db.WithContext(context.Background()).Exec("SELECT 1")
46+
47+
return mt.FinishedSpans()
48+
},
49+
WantServiceNameV0: harness.ServiceNameAssertions{
50+
Defaults: []string{"gorm.db"},
51+
DDService: []string{"gorm.db"},
52+
ServiceOverride: []string{harness.TestServiceOverride},
53+
},
54+
WantServiceSource: harness.ServiceSourceAssertions{
55+
Defaults: []string{string(instrumentation.PackageGormIOGormV1)},
56+
ServiceOverride: []string{instrumentation.ServiceSourceWithServiceOption},
57+
},
58+
AssertOpV0: func(t *testing.T, spans []*mocktracer.Span) {
59+
require.Len(t, spans, 1)
60+
assert.Equal(t, "gorm.raw_query", spans[0].OperationName())
61+
},
62+
AssertOpV1: func(t *testing.T, spans []*mocktracer.Span) {
63+
require.Len(t, spans, 1)
64+
assert.Equal(t, "gorm.raw_query", spans[0].OperationName())
65+
},
66+
}

instrumentation/internal/namingschematest/main_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ func TestNamingSchema(t *testing.T) {
7878
gorillaMux,
7979
pgxTest,
8080
bunTest,
81-
// gormTest and dnsTest are excluded: these integrations hardcode their service names
82-
// ("gorm.db" and "dns") and don't use instr.ServiceName(), so they don't conform to the
83-
// naming schema contract (DD_SERVICE, remove_integration_service_names, v1 schema).
84-
// ServiceNameWithSource is still implemented in their source code.
81+
gormTest,
8582
rueidisTest,
8683
valkeyTest,
8784
fasthttpTest,

instrumentation/packages.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ var packages = map[Package]PackageInfo{
795795
},
796796
PackageGormIOGormV1: {
797797
TracedPackage: "gorm.io/gorm",
798+
naming: map[Component]componentNames{
799+
ComponentDefault: {
800+
useDDServiceV0: false,
801+
buildServiceNameV0: staticName("gorm.db"),
802+
},
803+
},
798804
},
799805
PackageGorillaMux: {
800806
TracedPackage: "github.com/gorilla/mux",

0 commit comments

Comments
 (0)