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

Refactor collect and send algorithm #19

Merged
merged 7 commits into from
Sep 17, 2024
Merged

Conversation

konraddysput
Copy link
Contributor

No description provided.

@konraddysput konraddysput self-assigned this Sep 13, 2024
@konraddysput konraddysput marked this pull request as draft September 13, 2024 15:52
globs.tab_width = kwargs.get("tab_width", 8)
globs.context_line_count = kwargs.get("context_line_count", 200)

globs.attachments = kwargs.get("attachments", [])
attribute_manager.add(kwargs.get("attributes", {}))
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of using kwargs, why not define the arguments directly with default values?

e.g.

def initialize(attributes={}, token=None, timeout=4)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will handle it in a different pull request to reduce the scope of this change

"sourceCode": add_source_code(
source_file, source_code_dict, source_path_dict, line
),
"library": source_file,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would be better to use filename here only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The source code integration (with the source code service and source code injection in the client side) won't work

def send(self):
if len(self.log_lines) != 0 and "Log" not in self.report["annotations"]:
self.report["annotations"]["Log"] = self.log_lines
from backtracepython.client import send_worker_report
from backtracepython.client import send
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use global imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately, this would require breaking the existing API. Our current interface allows the record to be sent directly via the send method. Since client has to have a reference to report (creating a report on unhandled exception or sending a message), and report has a reference to the client due to the send method, we have a circular reference

self.report_queue.task_done()

def add(self, report, attachments):
self.report_queue.put((report, attachments))
Copy link
Contributor

Choose a reason for hiding this comment

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

you'll want to use put_nowait here probably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's true. Changing it. Thanks

Comment on lines 16 to 18
self.debug_api(
"Submitting a payload to {},\n {}\n".format(self.submission_url, payload)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would be a better idea to format in the debug_api method? This way you won't have to do string formatting if debugging is disabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On my todo list - thanks for pointing out!

if not self.debug:
return

print(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Print to stderr. Also, maybe prefix with some kind of category?

backtracepython/request_handler.py Outdated Show resolved Hide resolved
Comment on lines +23 to +24
if not os.path.exists(attachment):
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

if you do try/catch afterwards, do you need to check this here?

Comment on lines 58 to 59
finally:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to actually return None?

response.status_code, response.text
)
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to actually return None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh cool - I thought I need to return a result from the method directly. Changing.

@konraddysput konraddysput marked this pull request as ready for review September 17, 2024 13:46
@konraddysput konraddysput merged commit 5a72ee8 into master Sep 17, 2024
6 checks passed
@konraddysput konraddysput deleted the improvement/refactor-send branch September 17, 2024 15:44
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