Skip to content

Store user-defined data in Rows, Stmt and Tx objects #10

@fho

Description

@fho

Hello,

I'm implementing an interceptor with sqlmw that records traces for database
operations (instrumentedsql->sqlmw->tracing with sqlmw :-)).

When a Rows, Stmt or Tx object is created I create a parent tracing span.
Operations on the Rows, Stmt and Tx structs should be created as child spans. When
the Rows, Stmt, Tx operations is finished (Close(), Commit(), Rollback(),
etc), the parent span is also finished.

To be able to create a child span, the parent span must be available in the
methods of the Rows, Stmt and Tx objects.
One way to to achieve this would be to wrap the Rows, Stmt and Tx objects
again in my interceptor implementation and store the additional information in
the struct.

I would like to avoid having to wrap those structs again in my interceptor.
Wrapping it also requires to implement the fallback logic for the
Stmt.QueryContext() and Stmt.ExecContext() methods to their non context aware
variants again. This means maintaining another copy of
namedValueToValue.

It would be great if sqlmw would support the usecase to store user-defined
data when creating Rows, Stmt and Tx structs and access it in their methods instead.
sqlmw is doing something similiar already. When for example QueryContext() is
called, it stores the cx in the wrappedRows objects and passes it as
parameters to methods like RowsNext() as argument, which do not have a ctx
argument in the stdlib implementation.

What do you think about the idea?
Does somebody have an suggestion for how to implement it?
(I'll extend this issue or create a PR, when I have an idea.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions