Skip to content

Commit

Permalink
sender: allow not to forward make packet error
Browse files Browse the repository at this point in the history
  • Loading branch information
vgavro committed Feb 15, 2022
1 parent cd59f46 commit 786ddad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fluent/sender.py
Expand Up @@ -53,6 +53,7 @@ def __init__(self,
verbose=False,
buffer_overflow_handler=None,
nanosecond_precision=False,
forward_packet_error=True,
msgpack_kwargs=None,
**kwargs):
"""
Expand All @@ -66,6 +67,7 @@ def __init__(self,
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 @@ -82,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, timestamp,
{"level": "CRITICAL",
Expand Down Expand Up @@ -125,6 +127,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 786ddad

Please sign in to comment.