Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a mechanism to record db.response.status_code #377

Open
aereal opened this issue Oct 15, 2024 · 1 comment
Open

add a mechanism to record db.response.status_code #377

aereal opened this issue Oct 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@aereal
Copy link

aereal commented Oct 15, 2024

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:

attrs = append(attrs, cfg.AttributesGetter(ctx, method, query, args)...)

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 aereal added the enhancement New feature or request label Oct 15, 2024
@XSAM
Copy link
Owner

XSAM commented Oct 21, 2024

@aereal Thanks for raising this issue!

This is a good suggestion. I am considering creating an option to get attributes at the end of the operation for both traces and metrics. Something like type AttributeGetterOnEnd func(string signal, err error) []attribute.KeyValue. signal could be metric or trace. What do you think?

Please also notice that the db.response.status_code attribute is an experimental attribute. This attribute might be changed in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants