Skip to content

Commit 0cb4dd5

Browse files
committed
chore: Remove TraceDatabase
1 parent 47a2e39 commit 0cb4dd5

File tree

4 files changed

+7
-70
lines changed

4 files changed

+7
-70
lines changed

pkg/instrumentation/database.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

pkg/instrumentation/database_test.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

pkg/interceptors/database.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"gorm.io/gorm"
99

1010
sdkcontext "github.com/scribd/go-sdk/pkg/context/database"
11-
sdkinstrumentation "github.com/scribd/go-sdk/pkg/instrumentation"
1211
)
1312

1413
// DatabaseUnaryServerInterceptor returns a unary server interceptor that adds gorm.DB to the context.
@@ -19,8 +18,8 @@ func DatabaseUnaryServerInterceptor(db *gorm.DB) grpc.UnaryServerInterceptor {
1918
info *grpc.UnaryServerInfo,
2019
handler grpc.UnaryHandler,
2120
) (interface{}, error) {
22-
newDb := sdkinstrumentation.TraceDatabase(ctx, db)
23-
newCtx := sdkcontext.ToContext(ctx, newDb)
21+
instrumentedDB := db.WithContext(ctx)
22+
newCtx := sdkcontext.ToContext(ctx, instrumentedDB)
2423

2524
return handler(newCtx, req)
2625
}
@@ -34,8 +33,9 @@ func DatabaseStreamServerInterceptor(db *gorm.DB) grpc.StreamServerInterceptor {
3433
info *grpc.StreamServerInfo,
3534
handler grpc.StreamHandler,
3635
) error {
37-
newDb := sdkinstrumentation.TraceDatabase(stream.Context(), db)
38-
newCtx := sdkcontext.ToContext(stream.Context(), newDb)
36+
instrumentedDB := db.WithContext(stream.Context())
37+
newCtx := sdkcontext.ToContext(stream.Context(), instrumentedDB)
38+
3939
wrapped := grpcmiddleware.WrapServerStream(stream)
4040
wrapped.WrappedContext = newCtx
4141

pkg/middleware/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"net/http"
55

66
sdkdatabasecontext "github.com/scribd/go-sdk/pkg/context/database"
7-
sdkinstrumentation "github.com/scribd/go-sdk/pkg/instrumentation"
87

98
"gorm.io/gorm"
109
)
@@ -27,7 +26,8 @@ func NewDatabaseMiddleware(d *gorm.DB) DatabaseMiddleware {
2726
// connection pool to the request context.
2827
func (dm DatabaseMiddleware) Handler(next http.Handler) http.Handler {
2928
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30-
db := sdkinstrumentation.TraceDatabase(r.Context(), dm.Database)
29+
db := dm.Database.WithContext(r.Context())
30+
3131
ctx := sdkdatabasecontext.ToContext(r.Context(), db)
3232
next.ServeHTTP(w, r.WithContext(ctx))
3333
})

0 commit comments

Comments
 (0)