Skip to content

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

Closed

Description

@aereal

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

Activity

  1. added
    enhancement
    on Oct 15, 2024
  2. XSAM commented on Oct 21, 2024

    @XSAM
    Owner

    @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.

  3. cristiangreco commented on Jul 13, 2025

    @cristiangreco

    Hi @XSAM ! 👋 Now that db.response.status_code is stable, are you considering going ahead with your proposed changes?

  4. added this to the v0.42.0 milestone on Dec 16, 2025
  5. modified the milestones: v0.42.0, v0.43.0 on Mar 31, 2026
  6. modified the milestones: v0.43.0, v0.44.0 on Jul 12, 2026
  7. added a commit that references this issue on Sep 5, 2026
    97ff1d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions