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

Add PyMySQL instrumentor support for sqlcommenting #2942

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

Conversation

tammy-baylis-swi
Copy link
Contributor

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

Description

Updates PyMySQL instrumentor to support sqlcommenting.

Depends on # 2897

Fixes # 2902

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 tests. Used local installations of opentelemetry-instrumentation-dbapi (in ##2897) and upstream dependencies with this updated downstream instrumentor on a Flask app that use PyMySQL to query MySQL with general logs enabled to check sqlcomments.

Example general log entry after this update, which now includes sqlcomment:

2024-10-30T19:33:46.830661Z 25 Query SELECT * FROM city WHERE id = '1818' /*db_driver='pymysql%3A1.4.6',dbapi_level='2.0',dbapi_threadsafety=1,driver_paramstyle='pyformat',mysql_client_version='1.4.6',traceparent='00-f8688332bc5467bfa8fe1a9753d7271a-f7add29c81e79082-01'*/

Example corresponding exported span, whose span ID matches sqlcomment traceparent span ID:

InstrumentationScope opentelemetry.instrumentation.pymysql 0.49b0.dev
Span #0
    Trace ID       : f8688332bc5467bfa8fe1a9753d7271a
    Parent ID      : c125e4709cfe1361
    ID             : f7add29c81e79082
    Name           : SELECT
    Kind           : Client
    Start time     : 2024-10-30 19:33:46.829773588 +0000 UTC
    End time       : 2024-10-30 19:33:46.833294379 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> db.system: Str(mysql)
     -> db.name: Str(world)
     -> db.statement: Str(SELECT * FROM city WHERE id = %s)
     -> db.user: Str(world)
     -> net.peer.name: Str(mysql-world-db)
     -> net.peer.port: Int(3306)

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 marked this pull request as ready for review October 30, 2024 19:35
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner October 30, 2024 19:35
@tammy-baylis-swi
Copy link
Contributor Author

Going to close this and put in a fresh PR later. There's more that I want to add.

@tammy-baylis-swi
Copy link
Contributor Author

Re-opening this PR for review, when others have a moment please 😺

I researched how this instrumentation's support of sqlcommenting would affect prepared statements that PyMySQL driver might generate. The driver implementation seems to not support prepared statements (absence in docs here), so it seems to not be an issue.

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.

1 participant