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

Feature/ticket194 #201

Merged
merged 24 commits into from
May 13, 2021
Merged

Feature/ticket194 #201

merged 24 commits into from
May 13, 2021

Conversation

rcbjBlueMars
Copy link
Contributor

Description

Testing

  • Updated test suite to test autoinstrumentation CLI with flask and mysql
  • Standard test suite runs successfully.

Documentation

  • Regenerated pydoc documentation.

@rcbjBlueMars rcbjBlueMars requested a review from jcchavezs May 10, 2021 02:00

modules_array = MODULES.split(',')

if len(modules_array) == 1 and modules_array[0] == '':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is modules_array[0] == '' needed? Not sure how split works in python.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If an empty string is given, the result is an array with one element that is a blank string. To make it more intuitive, I changed the logic to check for a blank string before calling split.

$ cat test.py
str1 = "This is a test"
str_array = str1.split(' ')
print(str(str_array))
str2 = "Thisisatest"
str_array2 = str2.split(' ')
print(str(str_array2))
str3 = ""
str_array3 = str3.split(' ')
print(str(str_array3))

$ python test.py
['This', 'is', 'a', 'test']
['Thisisatest']
['']


def is_registered(self, module: str) -> bool:
'''Is an instrumentation module already registered?'''
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is pretty straighforward to check if the key exists and then return the value instead of throwing an exception. In general I would only expect an exception thrown for things I can't control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be straightforward, but python throws a KeyError exception if an invalid key is provided and the keys are based on external input. You can see this behavior below.

So, to avoid this disrupting the flow of logic, a try-except clause that returns False on any exception is used.

$ cat test.py
tester = {
'test1':'test1',
'test2':'test2',
'test3':'test3'
}

print(str(tester['test1']))
print(str(tester['test4']))

$ python test.py
test1
Traceback (most recent call last):
File "test.py", line 8, in
print(str(tester['test4']))
KeyError: 'test4'

@rcbjBlueMars
Copy link
Contributor Author

@jcchavezs ,

All issues have been addressed or explained.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@jcchavezs jcchavezs merged commit aac1649 into main May 13, 2021
@jcchavezs jcchavezs deleted the feature/ticket194 branch May 13, 2021 08:13
- Use the autoinstrumentation CLI
```
HT_INSTRUMENTED_MODULES=flask,mysql
hypertrace-instrument python app.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

If instrumenting a flask app, would hypertrace-instrument flask run be the more common use case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

double tapping this comment. We should provide examples on how to launch with and without the autoinstrumentation (hypertrace-instrument)

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should document starting up with hypertrace-instrument flask run to avoid confusing people accustomed to launching flask apps using the flask cli

agent.registerFlaskApp(app) # instrument a flask application
agent.registerMySQL() # instrument the MySQL client
agent.register_flask_app(app) # instrument a flask application
agent.register_mysql() # instrument the MySQL client
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch!

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