Skip to content

fix(sqlcommenter): prepend comment to beginning of query#4490

Open
RiyaChaturvedi37 wants to merge 12 commits intoopen-telemetry:mainfrom
RiyaChaturvedi37:fix/sqlcommenter-prepend-comment
Open

fix(sqlcommenter): prepend comment to beginning of query#4490
RiyaChaturvedi37 wants to merge 12 commits intoopen-telemetry:mainfrom
RiyaChaturvedi37:fix/sqlcommenter-prepend-comment

Conversation

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor

Problem

The SQL comment was appended to the end of the query, which caused
truncation issues in database query logs for long queries (e.g.
queries produced by Django in AWS RDS logs).

Fix

Changed the comment position from end to beginning of the query.

Before:

SELECT * FROM users /*key='value'*/;

After:

/*key='value'*/ SELECT * FROM users;

Testing

The existing tests have been updated to reflect the new comment
position at the beginning of queries.

Fixes #3583

Previously the SQL comment was appended to the end of the query,
which caused truncation issues in database query logs for long queries.
This change moves the comment to the beginning of the query.

Fixes open-telemetry#3583

Signed-off-by: RiyaChaturvedi37 <chaturvediriya37@gmail.com>
Signed-off-by: RiyaChaturvedi37 <chaturvediriya37@gmail.com>
Signed-off-by: RiyaChaturvedi37 <chaturvediriya37@gmail.com>
@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

After implementing this change, I noticed it affects many existing tests and could be a breaking change for users who parse SQL logs expecting comment at the end. Should I proceed with updating all tests, or would maintainers prefer a different approach such as a configuration option to control comment position?

@RiyaChaturvedi37 RiyaChaturvedi37 marked this pull request as draft April 26, 2026 15:59
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few concerns:

  1. Breaking change — moving the comment from end to start changes behaviour for any downstream system that expects sqlcommenter comments at the end of queries. The sqlcommenter spec defines comments at the end. This needs discussion on the issue (#3583) before we change the default behaviour — maybe an option to control position rather than switching it outright.

  2. Semicolon test looks wrong — the expected output for the semicolon case is " /*...*/ Select 1" (no semicolon), but the input was "Select 1;". The semicolon is being dropped.

  3. Leading space — the prepended output starts with a space before the comment: " /*...*/ SELECT 1".

  4. Line endings — same as #4482, the diff shows the entire file rewritten due to CRLF line endings. Please configure your editor/git to use Unix line endings (git config core.autocrlf input).

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Apr 27, 2026
Signed-off-by: RiyaChaturvedi37 <chaturvediriya37@gmail.com>
@RiyaChaturvedi37 RiyaChaturvedi37 marked this pull request as ready for review April 30, 2026 13:57
@github-actions github-actions Bot added the gen-ai Related to generative AI label May 1, 2026
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Hi @RiyaChaturvedi37 , thanks for working on this. I realized in my above comments that supporting the original requested feature is going to involve changes to several instrumentation libraries and not just this util:

  • DB-API
  • Django
  • Flask
  • SQLAlchemy
  • psycopg2
  • psycopg
  • mysql
  • mysqlclient
  • PyMySQL

Are you interested and available for submitting several PRs for this?

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Hi @tammy-baylis-swi, yes I'm interested and available! I'd be happy to submit PRs for each of these instrumentation libraries. Should I start with one library first for review, then proceed to the others once the approach is confirmed? Or would you prefer I submit them all at once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gen-ai Related to generative AI

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

sqlcommenter: put the comment at the beginning of the query

4 participants