Skip to content

Commit

Permalink
chore: rename function
Browse files Browse the repository at this point in the history
Renaming function to be more transparent in its functionality.
  • Loading branch information
asger-noer authored and costela committed May 17, 2023
1 parent bc49637 commit 8635702
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (t *Tracer) sqlOperationName(stmt string) string {
return strings.ToUpper(parts[0])
}

func appendConnectionAttributes(config *pgx.ConnConfig) []trace.SpanStartOption {
// connectionAttributesFromConfig returns a slice of SpanStartOptions that contain
// attributes from the given connection config.
func connectionAttributesFromConfig(config *pgx.ConnConfig) []trace.SpanStartOption {
if config != nil {
return []trace.SpanStartOption{
trace.WithAttributes(attribute.String(string(semconv.NetPeerNameKey), config.Host)),
Expand All @@ -117,7 +119,7 @@ func (t *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.T
}

if conn != nil {
opts = append(opts, appendConnectionAttributes(conn.Config())...)
opts = append(opts, connectionAttributesFromConfig(conn.Config())...)
}

if t.logSQLStatement {
Expand Down Expand Up @@ -162,7 +164,7 @@ func (t *Tracer) TraceCopyFromStart(ctx context.Context, conn *pgx.Conn, data pg
}

if conn != nil {
opts = append(opts, appendConnectionAttributes(conn.Config())...)
opts = append(opts, connectionAttributesFromConfig(conn.Config())...)
}

ctx, _ = t.tracer.Start(ctx, "copy_from "+data.TableName.Sanitize(), opts...)
Expand Down Expand Up @@ -200,7 +202,7 @@ func (t *Tracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.T
}

if conn != nil {
opts = append(opts, appendConnectionAttributes(conn.Config())...)
opts = append(opts, connectionAttributesFromConfig(conn.Config())...)
}

ctx, _ = t.tracer.Start(ctx, "batch start", opts...)
Expand All @@ -216,7 +218,7 @@ func (t *Tracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.T
}

if conn != nil {
opts = append(opts, appendConnectionAttributes(conn.Config())...)
opts = append(opts, connectionAttributesFromConfig(conn.Config())...)
}

if t.logSQLStatement {
Expand Down Expand Up @@ -260,7 +262,7 @@ func (t *Tracer) TraceConnectStart(ctx context.Context, data pgx.TraceConnectSta
}

if data.ConnConfig != nil {
opts = append(opts, appendConnectionAttributes(data.ConnConfig)...)
opts = append(opts, connectionAttributesFromConfig(data.ConnConfig)...)
}

ctx, _ = t.tracer.Start(ctx, "connect", opts...)
Expand Down Expand Up @@ -290,7 +292,7 @@ func (t *Tracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx
}

if conn != nil {
opts = append(opts, appendConnectionAttributes(conn.Config())...)
opts = append(opts, connectionAttributesFromConfig(conn.Config())...)
}

if t.logSQLStatement {
Expand Down

0 comments on commit 8635702

Please sign in to comment.