Skip to content

Commit f3bc435

Browse files
vgavromethane
andauthored
Added possibility not to forward _make_packet errors (#187)
Signed-off-by: Victor Gavro <[email protected]> Co-authored-by: Inada Naoki <[email protected]>
1 parent 54ce654 commit f3bc435

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fluent/sender.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def __init__(
5252
buffer_overflow_handler=None,
5353
nanosecond_precision=False,
5454
msgpack_kwargs=None,
55+
*,
56+
forward_packet_error=True,
5557
**kwargs,
5658
):
5759
"""
@@ -65,6 +67,7 @@ def __init__(
6567
self.verbose = verbose
6668
self.buffer_overflow_handler = buffer_overflow_handler
6769
self.nanosecond_precision = nanosecond_precision
70+
self.forward_packet_error = forward_packet_error
6871
self.msgpack_kwargs = {} if msgpack_kwargs is None else msgpack_kwargs
6972

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

8386
def emit_with_time(self, label, timestamp, data):
84-
if self.nanosecond_precision and isinstance(timestamp, float):
85-
timestamp = EventTime(timestamp)
8687
try:
8788
bytes_ = self._make_packet(label, timestamp, data)
8889
except Exception as e:
90+
if not self.forward_packet_error:
91+
raise
8992
self.last_error = e
9093
bytes_ = self._make_packet(
9194
label,
@@ -129,6 +132,8 @@ def _make_packet(self, label, timestamp, data):
129132
tag = ".".join((self.tag, label)) if self.tag else label
130133
else:
131134
tag = self.tag
135+
if self.nanosecond_precision and isinstance(timestamp, float):
136+
timestamp = EventTime(timestamp)
132137
packet = (tag, timestamp, data)
133138
if self.verbose:
134139
print(packet)

0 commit comments

Comments
 (0)