Skip to content

Commit

Permalink
Merge pull request #20 from backtrace-labs/feature/client-parameters
Browse files Browse the repository at this point in the history
Define client parameters
  • Loading branch information
konraddysput authored Sep 18, 2024
2 parents 5a72ee8 + adc65b4 commit 48409f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
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

0 comments on commit 48409f1

Please sign in to comment.