Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy instrumentor populates span after sqlcomment creation, not before #2937

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Oct 29, 2024

Description

Re-orders database query span population by SQLAlchemy instrumentor so that db.statement span attribute includes any sqlcomments generated.

Fixes #2938

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added unit test. Locally installed this version of opentelemetry-instrumentation-sqlalchemy and upstream dependencies. Instrumented a Flask app that queries MySQL (via mysql-connector driver) with general logs enabled to check sqlcomment (enabled as per doc). Spans were exported to a locally-running otel-collector to inspect attributes including db.statement.

After changes, example span from SQLAlchemy-with-mysql-connector query with updated db.statement:

InstrumentationScope opentelemetry.instrumentation.sqlalchemy 0.49b0.dev
Span #0
    Trace ID       : 3b654158a48190e458f6c4e15e125814
    Parent ID      : ed65cfad7167aecd
    ID             : 69d58000ef348179
    Name           : connect
    Kind           : Client
    Start time     : 2024-10-29 22:09:35.42945621 +0000 UTC
    End time       : 2024-10-29 22:09:35.466973419 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> net.peer.name: Str(mysql-world-db)
     -> net.peer.port: Int(3306)
     -> db.name: Str(world)
     -> db.user: Str(world)
     -> db.system: Str(mysql)
Span #1
    Trace ID       : 3b654158a48190e458f6c4e15e125814
    Parent ID      : ed65cfad7167aecd
    ID             : b62c6e3e794e9f05
    Name           : SELECT world
    Kind           : Client
    Start time     : 2024-10-29 22:09:35.469197169 +0000 UTC
    End time       : 2024-10-29 22:09:35.469996085 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> db.statement: Str(SELECT city.id, city.name, city.district, city.population, city.countrycode
FROM city
WHERE city.id = %(id_1)s /*db_driver='mysqlconnector',db_framework='sqlalchemy%%3A2.0.36',traceparent='00-3b654158a48190e458f6c4e15e125814-b62c6e3e794e9f05-01'*/)
     -> db.system: Str(mysql)
     -> net.peer.name: Str(mysql-world-db)
     -> net.peer.port: Int(3306)
     -> db.name: Str(world)
     -> db.user: Str(world)

which matches sqlcomment in corresponding MySQL general log:

2024-10-29T22:09:35.469520Z	  240 Query	SELECT city.id, city.name, city.district, city.population, city.countrycode
FROM city
WHERE city.id = '1818' /*db_driver='mysqlconnector',db_framework='sqlalchemy%%3A2.0.36',traceparent='00-3b654158a48190e458f6c4e15e125814-b62c6e3e794e9f05-01'*/

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@tammy-baylis-swi tammy-baylis-swi changed the title [WIP] SQLAlchemy instrumentor populates span after sqlcomment creation, not before SQLAlchemy instrumentor populates span after sqlcomment creation, not before Oct 29, 2024
@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review October 29, 2024 22:46
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner October 29, 2024 22:46
@xrmx xrmx closed this Nov 12, 2024
@xrmx xrmx reopened this Nov 12, 2024
@tammy-baylis-swi
Copy link
Contributor Author

tammy-baylis-swi commented Nov 13, 2024

Working on fixing these new failures -- done in 7b78383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include sqlcomment in db.statement span attribute from SQLAlchemy instrumentation
3 participants