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

Define client parameters #20

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions backtracepython/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@


class globs:
endpoint = None
next_except_hook = None
debug_backtrace = False
worker = None
attachments = []
handler = None

Expand All @@ -40,7 +37,8 @@ def create_and_send_report(ex_type, ex_value, ex_traceback):
report = BacktraceReport()
report.set_exception(ex_type, ex_value, ex_traceback)
report.set_attribute("error.type", "Unhandled exception")
globs.handler.process(report.get_data(), globs.attachments)
if globs.handler:
globs.handler.process(report.get_data(), globs.attachments)


def bt_except_hook(ex_type, ex_value, ex_traceback):
Expand All @@ -65,27 +63,38 @@ def bt_except_hook(ex_type, ex_value, ex_traceback):
globs.next_except_hook(ex_type, ex_value, ex_traceback)


def initialize(**kwargs):
globs.endpoint = construct_submission_url(
kwargs["endpoint"], kwargs.get("token", None)
)
globs.debug_backtrace = kwargs.get("debug_backtrace", False)
globs.attachments = kwargs.get("attachments", [])
attribute_manager.add(kwargs.get("attributes", {}))
def initialize(
endpoint,
token=None,
debug_backtrace=False,
attachments=[],
attributes={},
timeout=4,
ignore_ssl_certificate=False,
tab_width=8,
context_line_count=200,
collect_source_code=True,
disable_global_handler=False,
):
globs.endpoint = construct_submission_url(endpoint, token)
globs.debug_backtrace = debug_backtrace
globs.attachments = attachments
attribute_manager.add(attributes)

globs.handler = ReportQueue(
BacktraceRequestHandler(
globs.endpoint,
kwargs.get("timeout", 4),
kwargs.get("ignore_ssl_certificate", False),
timeout,
ignore_ssl_certificate,
globs.debug_backtrace,
),
SourceCodeHandler(
kwargs.get("tab_width", 8), kwargs.get("context_line_count", 200)
(
SourceCodeHandler(tab_width, context_line_count)
if collect_source_code
else None
),
)

disable_global_handler = kwargs.get("disable_global_handler", False)
if not disable_global_handler:
globs.next_except_hook = sys.excepthook
sys.excepthook = bt_except_hook
Expand Down
5 changes: 3 additions & 2 deletions backtracepython/report_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ReportQueue:
def __init__(self, request_handler, source_code_handler):
def __init__(self, request_handler, source_code_handler=None):
self.request_handler = request_handler
self.source_code_handler = source_code_handler

Expand Down Expand Up @@ -37,7 +37,8 @@ def add(self, report, attachments):
# Immediately process the report and skip the queue process
# Use this method to handle importa data before application exit
def process(self, report, attachments):
self.source_code_handler.collect(report)
if self.source_code_handler is not None:
self.source_code_handler.collect(report)
self.request_handler.send(report, attachments)

def __del__(self):
Expand Down
Loading