Skip to content

Commit

Permalink
Added possibility not to forward _make_packet errors (#187)
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Gavro <[email protected]>
Co-authored-by: Inada Naoki <[email protected]>
  • Loading branch information
vgavro and methane authored Feb 29, 2024
1 parent 54ce654 commit f3bc435
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fluent/sender.py
Original file line number Diff line number Diff line change
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

0 comments on commit f3bc435

Please sign in to comment.