Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `sqlcommenter`: prepend SQL comment to beginning of query instead of appending to end
([#3583](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3583))
- Bump `pylint` to `4.0.5`
([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244))
- `opentelemetry-instrumentation-sqlite3`: Add uninstrument, error status, suppress, and no-op tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Ensure same sem conv attributes are on the log and span. Fix an issue where the
- Implement the new semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.
A single event (`gen_ai.client.inference.operation.details`) is used to capture Chat History. This is opt-in,
an environment variable OTEL_SEMCONV_STABILITY_OPT_IN needs to be set to `gen_ai_latest_experimental` to see them ([#3386](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3386))
- Support CompletionHook for upload to cloud storage.
- Support CompletionHook for upload to cloud storage.

## Version 0.3b0 (2025-07-08)

Expand All @@ -53,4 +53,4 @@ span attribute `gen_ai.response.finish_reasons` is empty ([#3417](https://github
([#3298](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3298))

Create an initial version of Open Telemetry instrumentation for github.com/googleapis/python-genai.
([#3256](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3256))
([#3256](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3256))
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,31 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from opentelemetry import context
from opentelemetry.instrumentation.utils import _url_quote


def _add_sql_comment(sql, **meta) -> str:
def _add_sql_comment(sql, comment_position="end", **meta) -> str:
"""
Appends comments to the sql statement and returns it
Adds comments to the sql statement and returns it.
By default, the comment is appended to the end of the query.
Set comment_position="start" to prepend the comment instead.
"""
meta.update(**_add_framework_tags())
comment = _generate_sql_comment(**meta)
sql = sql.rstrip()
if sql.endswith(";"):
sql = sql[:-1] + comment + ";"
if not comment:
return sql
sql = sql.strip()
if comment_position == "start":
if sql.endswith(";"):
sql = comment + " " + sql[:-1] + ";"
else:
sql = comment + " " + sql
else:
sql = sql + comment
if sql.endswith(";"):
sql = sql[:-1] + comment + ";"
else:
sql = sql + comment
return sql


Expand All @@ -36,10 +45,8 @@ def _generate_sql_comment(**meta) -> str:
**meta kwargs.
"""
key_value_delimiter = ","

if not meta: # No entries added.
return ""

# Sort the keywords to ensure that caching works and that testing is
# deterministic. It eases visual inspection as well.
return (
Expand All @@ -57,7 +64,6 @@ def _add_framework_tags() -> dict:
"""
Returns orm related tags if any set by the context
"""

sqlcommenter_framework_values = (
context.get_value("SQLCOMMENTER_ORM_TAGS_AND_VALUES")
if context.get_value("SQLCOMMENTER_ORM_TAGS_AND_VALUES")
Expand Down
Loading