Skip to content

Wrong named query support #614

@rafiwicht

Description

@rafiwicht

Hi everyone

Description

First of thanks for the nice package. I have an issue when using the package with sqlx and PostgreSQL. When I use otelsql, sqlx detect the wrong driver type and named queries use ? instead of $1. It also doesn't help to use Rebind.

This doesn't work:

driverName, err := otelsql.Register("pgx",
  otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL),
  otelsql.WithSpanOptions(otelsql.SpanOptions{
    Ping:           true,
    DisableErrSkip: true,
  }),
)
if err != nil {
  return nil, err
}

return sqlx.Open(driverName, config.DBURL), nil

This workaround works:

driverName, err := otelsql.Register("pgx",
  otelsql.WithAttributes(semconv.DBSystemNamePostgreSQL),
  otelsql.WithSpanOptions(otelsql.SpanOptions{
    Ping:           true,
    DisableErrSkip: true,
  }),
)
if err != nil {
  return nil, err
}

db, err := sql.Open(driverName, config.DBURL)
if err != nil {
  return nil, err
}

return sqlx.NewDb(db, "pgx"), nil

Environment

  • OS: Linux
  • Architecture: x86_64
  • Go Version: 1.25.6
  • otelsql version: v0.42.0

Steps To Reproduce

  1. Use the example from above

Expected behavior

It should work without the workaround.

Let me know what you think. I haven't really looked deeply in your code. If it's a small fix, I canm open an PR.

Best

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions