Compare commits

..

2 commits

2 changed files with 7 additions and 5 deletions

View file

@ -26,7 +26,7 @@ type dbCtxVal struct {
attrs []attribute.KeyValue
}
type tracedPgxHooks struct {
type tracedSQLHooks struct {
dbType string
t *Telemetry
@ -36,7 +36,7 @@ type tracedPgxHooks struct {
mDuration metric.Float64Histogram
}
func (h *tracedPgxHooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
func (h *tracedSQLHooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
cleanedQuery := strings.ReplaceAll(query, "\n", " ")
cleanedQuery = strings.ReplaceAll(cleanedQuery, "\t", " ")
cleanedQuery = strings.ReplaceAll(cleanedQuery, " ", " ")
@ -78,7 +78,7 @@ func (h *tracedPgxHooks) Before(ctx context.Context, query string, args ...inter
}), nil
}
func (h *tracedPgxHooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
func (h *tracedSQLHooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
if s := SpanFromContext(ctx); s != nil {
s.End()
}
@ -106,7 +106,7 @@ func (t *Telemetry) TraceSQL(driver driver.Driver, dbType string, printQueries b
log.Fatal().Err(err).Msg("failed to create request duration histogram")
}
return sqlhooks.Wrap(driver, &tracedPgxHooks{
return sqlhooks.Wrap(driver, &tracedSQLHooks{
dbType: dbType,
printQueries: printQueries,

View file

@ -82,7 +82,9 @@ func WithOtelTracer(tracer trace.Tracer) ConfigureSpanStartFunc {
}
}
func RunTraced[T any](t *Telemetry, op string, fn func(context.Context, ...any) T) func(context.Context, string, ...any) T {
type TracedFunc[T any] func(context.Context, string, ...any) T
func RunTraced[T any](t *Telemetry, op string, fn func(context.Context, ...any) T) TracedFunc[T] {
return func(ctx context.Context, name string, args ...any) T {
span := t.StartSpan(ctx, op, name)
defer span.End()