feat(dbapi): add comment_position option to control SQL comment placement#4561
Conversation
|
This is the first PR in a series adding comment_position support to sqlcommenter instrumentation libraries, as discussed with @tammy-baylis-swi in #4490. Starting with DB-API as the base library to confirm the approach before proceeding to Django, Flask, SQLAlchemy, psycopg2, psycopg, mysql, mysqlclient, and PyMySQL. |
c098c79 to
d504f0a
Compare
|
Fixed all the suggestions @herin049 — used Literal["start", "end"] type with a CommentPositionT alias, simplified the semicolon handling logic in sqlcommenter_utils.py, and cleaned up the changelog. Ready for re-review! |
236d8e0 to
f360254
Compare
… conflict resolution
9d63a69 to
f88ddcc
Compare
2cf3dac to
8020903
Compare
|
Thanks for the PR! Just a heads-up: we no longer update Please add the appropriate changelog fragment for this change instead of editing |
|
The misc/typecheck failure is in util/opentelemetry-util-genai/src/opentelemetry/util/genai/completion_hook.py which was last modified by upstream commits (#4533, #4506) unrelated to my PR. All lint and test checks for my changes are passing. @herin049 @emdneto could you confirm this is a pre-existing issue? |
Problem
The SQL comment was always appended to the end of the query, which caused truncation issues in database query logs for long queries.
Solution
Added a comment_position parameter to trace_integration, wrap_connect, instrument_connection, and DatabaseApiIntegration that defaults to "end" (preserving existing behavior per OTel spec). Set comment_position="start" to prepend the comment instead.
Usage
pythonwrap_connect(
name,
mysql.connector,
"connect",
"mysql",
enable_commenter=True,
comment_position="start",
)
Default behavior unchanged
Part of a series of PRs adding comment_position support across DB-API, Django, Flask, SQLAlchemy, psycopg2, psycopg, mysql, mysqlclient, PyMySQL
Follows approach confirmed in #4490
Part of #3583