Skip to content

fmt.Stringer support for user attributes (especially for SQL query parameters) #834

Open
@siketyan

Description

@siketyan

Summary

User attributes in segments does not support types other than primitive types.

switch v := val.(type) {
case string, bool,
uint8, uint16, uint32, uint64, int8, int16, int32, int64,
uint, int, uintptr:
case float32:
if err := validateFloat(float64(v), key); err != nil {
return nil, err
}
case float64:
if err := validateFloat(v, key); err != nil {
return nil, err
}
default:
return nil, errInvalidAttributeType{
key: key,
val: val,
}
}

I am using the pgx tracer from nrpgx5 package, the querying segment cannot be sent successfully because some of the query parameters are not primitive:

unable to end datastore segment collection=user operation=select product=Postgres reason="attribute '$1' value of type uuid.UUID is invalid"

uuid.UUID are not primitive, but it implements fmt.Stringer interface.
It would be great if we can handle fmt.Stringer for attributes.

Desired Behaviour

Attributes on a segment accept fmt.Stringer implemented types.

Possible Solution

Add a case to the switch statement:

case fmt.Stringer:
    val = val.String()

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions