Skip to content

feat(sqlcommenter): add comment_position option to control SQL comment placement#4628

Open
RiyaChaturvedi37 wants to merge 3 commits into
open-telemetry:mainfrom
RiyaChaturvedi37:fix/sqlcommenter-clean
Open

feat(sqlcommenter): add comment_position option to control SQL comment placement#4628
RiyaChaturvedi37 wants to merge 3 commits into
open-telemetry:mainfrom
RiyaChaturvedi37:fix/sqlcommenter-clean

Conversation

@RiyaChaturvedi37

Copy link
Copy Markdown
Contributor

Problem
The SQL comment was always 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).
Solution
Added a comment_position parameter to _add_sql_comment() that defaults to "end" (preserving existing behavior per OTel spec). Set comment_position="start" to prepend the comment instead.
Usage
python_add_sql_comment(sql, comment_position="start", **meta)
Notes

Default behavior unchanged
Part of a series of PRs adding comment_position support across instrumentation libraries
Replaces #4490

Part of #3583



def _add_sql_comment(sql, **meta) -> str:
def _add_sql_comment(sql, comment_position="end", **meta) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pardon my delayed review @RiyaChaturvedi37 and thank you for resuming this!

I had this comment on the other PR: Instead of a string, what if we had it as a case-insensitive boolean string check for false/true and the config was called comment_prepend=false? Since I don't think we'll support a "middle".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tammy-baylis-swi tammy-baylis-swi moved this to Reviewed PRs that need fixes in Python PR digest Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

2 participants