Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.
This repository was archived by the owner on May 29, 2026. It is now read-only.

Feature request: spec support for using bound parameters as attribute values #245

Open

Description

@mitchsw

Would it be feasible to support attribute values being specified via a query's parameter bindings?

Idea

I'd like to support prepared statements like the following (and stay within the sqlcommeter spec):

LOG:  execute my-demo-stmt: SELECT * FROM FOO WHERE ID = $1 /*application='app-1', traceparent=$2*/
DETAIL:  parameters: $1 = 1234, $2 = '00-5bd66ef5095369c7b0d1f8f4bd33716a-c532cb4098ac3dd2-01'

This would necessitate an extension to sqlcommeter spec. Something like:

FIELD      ::=  <SERIALIZED_KEY>=<VALUE>
VALUE      ::=  <SERIALIZED_VALUE> | <PARAM_NUM>
PARAM_NUM  ::=  $[0-9]+

Motivation

My objective is to enable the performance benefits of prepared statements, whilst still being able to use a unique per-query traceparent.

In Postgres, it is technically possible to prepare and execute a statement like the example above. (The $2 parameter is simply unused by the query planner, but still appears in the statement log.) I am exploring adding this support to DataDog/dd-trace-go's SqlCommeter.

Would this feature in the spec be generally useful?

Activity

  1. StevenACoffman commented on Sep 28, 2025

    @StevenACoffman

    Yes! This feature would be quite useful for many applications!

    AFAICT, Sqlcommenter currently acts as a post-processor that adds some comments to queries that later can be identified by the server to tag queries with extra metadata.

    At least for PostgreSQL, when using prepared statements, the SQL text isn't sent to the server -- only the prepared statement name.

    However (at least for PostgreSQL), I believe that it is possible to bind variables in comments like:

    select 1 /*tracespan=$1*/

    such that it can still be prepared, and a trace context can then be added at query execution time.

    My specific use case is for the preferred Go PostgreSQL driver, pgx/v5, which exclusively uses prepared statements to achieve much better performance, but renders the current SQLCommenter utterly unusable.

    Please see jackc/pgx#1423

  2. StevenACoffman commented on Sep 28, 2025

    @StevenACoffman

    @sjs994 @lonewolf3739 Is there any planned work to extend or amend the SQL Commenter spec using bound parameters in Prepared Statements, given the conversation in open-telemetry/semantic-conventions#2162
    and in #284 ?

  3. StevenACoffman commented on Sep 29, 2025

    @StevenACoffman

    @Thiyagu55 Do you have any thoughts on this?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions