newrelic / go-agent

New Relic Go Agent
Apache License 2.0
762 stars 294 forks source link

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

Open siketyan opened 9 months ago

siketyan commented 9 months ago

Summary

User attributes in segments does not support types other than primitive types. https://github.com/newrelic/go-agent/blob/0100f62956fc305066a0cffe8ac77d901e8e07da/v3/newrelic/attributes_from_internal.go#L357-L374

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