diff --git a/tracer.go b/tracer.go index 67b42d5..c7126f5 100644 --- a/tracer.go +++ b/tracer.go @@ -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)), @@ -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 { @@ -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...) @@ -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...) @@ -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 { @@ -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...) @@ -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 {