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

Added possibility not to forward _make_packet errors #187

Merged
merged 4 commits into from Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions fluent/sender.py
Expand Up @@ -52,6 +52,8 @@ def __init__(
buffer_overflow_handler=None,
nanosecond_precision=False,
msgpack_kwargs=None,
*,
forward_packet_error=True,
**kwargs,
):
"""
Expand All @@ -65,6 +67,7 @@ def __init__(
self.verbose = verbose
self.buffer_overflow_handler = buffer_overflow_handler
self.nanosecond_precision = nanosecond_precision
self.forward_packet_error = forward_packet_error
self.msgpack_kwargs = {} if msgpack_kwargs is None else msgpack_kwargs

self.socket = None
Expand All @@ -81,11 +84,11 @@ def emit(self, label, data):
return self.emit_with_time(label, cur_time, data)

def emit_with_time(self, label, timestamp, data):
if self.nanosecond_precision and isinstance(timestamp, float):
timestamp = EventTime(timestamp)
try:
bytes_ = self._make_packet(label, timestamp, data)
except Exception as e:
if not self.forward_packet_error:
raise
self.last_error = e
bytes_ = self._make_packet(
label,
Expand Down Expand Up @@ -129,6 +132,8 @@ def _make_packet(self, label, timestamp, data):
tag = ".".join((self.tag, label)) if self.tag else label
else:
tag = self.tag
if self.nanosecond_precision and isinstance(timestamp, float):
timestamp = EventTime(timestamp)
packet = (tag, timestamp, data)
if self.verbose:
print(packet)
Expand Down