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

cassandra-driver Instrumentation #1280

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

cassandra-driver Instrumentation #1280

wants to merge 14 commits into from

Conversation

TimPansino
Copy link
Contributor

Overview

  • Add instrumentation for cassandra-driver library.

@TimPansino TimPansino requested a review from a team as a code owner January 3, 2025 23:43
Copy link

github-actions bot commented Jan 3, 2025

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON bandit 2 0 5.15s
✅ PYTHON black 6 0 0 2.02s
✅ PYTHON flake8 6 0 1.01s
✅ PYTHON isort 6 0 0 0.36s
✅ PYTHON pylint 6 0 7.52s
✅ YAML prettier 1 0 0 1.05s
✅ YAML v8r 1 0 2.3s
✅ YAML yamllint 1 0 0.55s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@codecov-commenter
Copy link

codecov-commenter commented Jan 4, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 14 lines in your changes missing coverage. Please review.

Project coverage is 81.25%. Comparing base (454709e) to head (ea6f81e).

Files with missing lines Patch % Lines
newrelic/hooks/datastore_cassandradriver.py 70.21% 9 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1280      +/-   ##
==========================================
- Coverage   81.28%   81.25%   -0.03%     
==========================================
  Files         201      202       +1     
  Lines       22174    22223      +49     
  Branches     3519     3526       +7     
==========================================
+ Hits        18024    18058      +34     
- Misses       2982     2993      +11     
- Partials     1168     1172       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TimPansino TimPansino changed the title cassandra-driver Instrumentation [WIP] cassandra-driver Instrumentation Jan 4, 2025
@TimPansino TimPansino changed the title [WIP] cassandra-driver Instrumentation cassandra-driver Instrumentation Jan 17, 2025
@mergify mergify bot removed the tests-failing label Jan 21, 2025
Copy link
Contributor

@hmstepanek hmstepanek left a comment

Choose a reason for hiding this comment

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

Just a couple minor things - otherwise looks good! Marking it as pre-approved cause I don't think any of them are merge stoppers.

# the result. We can therefore just instrument execute_async() and achieve full sync/async coverage.
# If this changes in the future we'll need an additional wrapper, but care should be taken not to double wrap.
wrap_function_wrapper(module, "Session.execute_async", wrap_Session_execute_async)
wrap_function_wrapper(module, "Session.execute", wrap_Session_execute_async) # TODO check this
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove this wrapper then given the above comment about only needing to wrap execute_async?

# Exit early there's no transaction, or if we're under an existing DatabaseTrace
return wrapped(*args, **kwargs)

bound_args = bind_args(wrapped, args, kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

So glad we made this-I use it all the time now!

sql = bound_args.get("query", None)
if not isinstance(sql, str):
statement = getattr(sql, "prepared_statement", sql) # Unbind BoundStatement
sql = statement.query_string # Unpack query from SimpleStatement and PreparedStatement
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use a getattr here in case this attribute doesn't exist?


database_name = getattr(instance, "keyspace", None)

# hosts = instance.cluster.metadata.all_hosts()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# hosts = instance.cluster.metadata.all_hosts()

database_name = getattr(instance, "keyspace", None)

# hosts = instance.cluster.metadata.all_hosts()
# breakpoint()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# breakpoint()

):
return wrapped(*args, **kwargs)

return wrapped(*args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this reachable?

# Cassandra isn't DBAPI2 compliant, but we need the DatabaseTrace to function properly. We can set parameters
# for CQL parsing and the product name here, and leave the explain plan functionality unused.
global DBAPI2_MODULE
DBAPI2_MODULE = module
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little unorthodox but seems like it will work fine.

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.

3 participants