otelsql icon indicating copy to clipboard operation
otelsql copied to clipboard

add a mechanism to record db.response.status_code

Open aereal opened this issue 4 months ago • 1 comments

Problem Statement

The latest semantic conventions has introduced db.response.status_code attribute that is the status code returned by the database.

Usually it represents an error code, but may also represent partial success, warning, or differentiate between various types of successful outcomes.

The latest otelsql provides AttributesGetter but it is called only when creating a span:

https://github.com/XSAM/otelsql/blob/c3358219f8a42e28ee40f90115722c560a9d434a/utils.go#L101

The recordSpanError internal function just calls RecordError and has no mechanism to extract some information from err.

So the library users can't extract the information from the error returned by the driver.

Proposed Solution

Add a new option like type ErrorEventAttributesGetter func(err error) []attribute.KeyValue and recordSpanError uses ErrorEventAttributesGetter's return values.

The users can pass the function that extracts the status information from the driver's concrete error type such as mysql.MySQLError.Number.

Alternatives

Add a new argument err error to AttributeGetter.

It is unreasonable because it breaks backward compatibilities.

Prior Art

No prior arts found.

Additional Context

aereal avatar Oct 15 '24 09:10 aereal