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

Adding DB API integration + MySQL connector integration #264

Merged
merged 28 commits into from
Jan 5, 2020

Conversation

hectorhdzg
Copy link
Member

Took OpenCensus implementation as starting point for this, there are significant changes now including different fields to store in the Span object and monkey patching process.
https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-mysql

MySQL Connector docs
https://dev.mysql.com/doc/connector-python/en/

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

The approach looks good, but is this wrapping the right library?

ext/opentelemetry-ext-mysql/setup.cfg Outdated Show resolved Hide resolved
ext/opentelemetry-ext-mysql/setup.cfg Outdated Show resolved Hide resolved
raise Exception("Test Exception")


class MockSpan:
Copy link
Member

Choose a reason for hiding this comment

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

are MockSpan and MockTracer needed? I feel like we have a no-op tracer now with the API.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to test the integration code is creating the span correctly, API tracer is no-op so it will not create anything, are you suggesting to use unittest.Mock with a side effect or some other pattern to test here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Using no-op tracer in tests but still using MockSpan to check all attributes are set up correctly

Copy link
Member

Choose a reason for hiding this comment

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

could use a Mock object which takes the Tracer as as a spec: https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock

Copy link
Member

Choose a reason for hiding this comment

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

if the purpose here is to provide a general test utility for tracers, I guess I'd rather see it shared in something like opentelemetry-api. But I'm not sure if sharing test fixtures across projects is an accepted policy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Mocking tracer using mock library now, for Span I prefer to create my own mock class so is easier to test the integration adding correct attributes to the Span

@hectorhdzg
Copy link
Member Author

@c24t I decided to use wrapt library to monkey patch because it was easy to understand and apply it here, I was interested in not altering original code including signatures and types, I gave a try with functools as well, some other integration is using it already in this project, but had some issues patching the cursor methods. I'm open to suggestions and ideas for this

@hectorhdzg
Copy link
Member Author

Added dbapi extension to be shared by all libraries using Python Database API specification
https://www.python.org/dev/peps/pep-0249/

#265 (comment)

@codecov-io
Copy link

codecov-io commented Nov 14, 2019

Codecov Report

Merging #264 into master will not change coverage.
The diff coverage is 89.44%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #264   +/-   ##
=======================================
  Coverage   84.82%   84.82%           
=======================================
  Files          38       38           
  Lines        1839     1839           
  Branches      217      217           
=======================================
  Hits         1560     1560           
  Misses        214      214           
  Partials       65       65
Impacted Files Coverage Δ
...sdk/src/opentelemetry/sdk/trace/export/__init__.py 86.79% <ø> (ø) ⬆️
opentelemetry-api/src/opentelemetry/util/loader.py 81.25% <ø> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/sampling.py 85.1% <ø> (ø) ⬆️
...etry-sdk/src/opentelemetry/sdk/metrics/__init__.py 99.05% <ø> (ø) ⬆️
...try-ext-wsgi/src/opentelemetry/ext/wsgi/version.py 100% <100%> (ø) ⬆️
.../src/opentelemetry/ext/opentracing_shim/version.py 100% <100%> (ø) ⬆️
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 68.18% <100%> (ø) ⬆️
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.9% <100%> (ø) ⬆️
...sts/src/opentelemetry/ext/http_requests/version.py 100% <100%> (ø) ⬆️
...pentelemetry-sdk/src/opentelemetry/sdk/__init__.py 100% <100%> (ø) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83d95e7...26e4983. Read the comment docs.

@hectorhdzg
Copy link
Member Author

@c24t we talked about using wrapt in today OT SIG meeting, everyone agreed it was fine to use this library, is actually heavily used in OpenTracing integrations https://github.com/opentracing-contrib?utf8=%E2%9C%93&q=python&type=&language=
Let me know if you have strong opinions about this and i would appreciate if you can take a look a the PR again, I added a bunch of stuff since your last comment

Copy link
Member

@Oberon00 Oberon00 left a comment

Choose a reason for hiding this comment

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

Two blocking comments:

@hectorhdzg hectorhdzg requested a review from a team December 10, 2019 00:18
@a-feld a-feld removed their request for review December 10, 2019 00:56
hectorhdzg and others added 2 commits December 11, 2019 14:36
other integrations
Updated versions
Added capabilities to specify connection attribute names
@hectorhdzg hectorhdzg changed the title Adding MySQL Connector integration Adding DB API integration + MySQL connector integration Dec 11, 2019
@Oberon00 Oberon00 dismissed their stale review December 12, 2019 09:40

I don't have time to look into this currently.

@hectorhdzg
Copy link
Member Author

@Oberon00 all comments have been resolved now, let me know if you have more feedback, thanks

@hectorhdzg hectorhdzg added the needs reviewers PRs with this label are ready for review and needs people to review to move forward. label Dec 12, 2019
"""Integrate with MySQL Connector/Python library.
https://dev.mysql.com/doc/connector-python/en/
"""
connection_attributes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put this outside the function so it doesn't have to be defined more than once?

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for powering through this.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Overall looks really good! There's a couple small things (like using the global logging module) that I think should be addressed, but by and large the code (and tests) look great.

ext/opentelemetry-ext-dbapi/README.rst Outdated Show resolved Hide resolved
if tracer is None:
raise ValueError("The tracer is not provided.")
self.connection_attributes = connection_attributes
if self.connection_attributes is None:
Copy link
Member

Choose a reason for hiding this comment

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

Just to clarify: is it possible that these connection_attributes don't reflect the actual connection established, since this is wrapping the connect method and different args can be passed there?

should there be some documentation added about what the attribute names should be, in that case? I could imagine people using slightly different names for the attributes which could lead to quite a mismatch in key names.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well the attributes names depends entirely on the dbapi library being used, if we support more popular libraries the less likely people will make mistakes, I agree having more documentation is always good so I added more details

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Great! Thanks for addressing feedback.

@toumorokoshi toumorokoshi merged commit b01f7e8 into open-telemetry:master Jan 5, 2020
@toumorokoshi
Copy link
Member

amazing! Thanks @hectorhdzg!

@hectorhdzg hectorhdzg deleted the newMaster branch March 24, 2020 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reviewers PRs with this label are ready for review and needs people to review to move forward. tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants