@@ -30,15 +30,23 @@ def close(): # pragma: no cover
30
30
31
31
32
32
class EventTime (msgpack .ExtType ):
33
- def __new__ (cls , timestamp ):
34
- seconds = int (timestamp )
35
- nanoseconds = int (timestamp % 1 * 10 ** 9 )
33
+ def __new__ (cls , timestamp , nanoseconds = None ):
34
+ if nanoseconds is None :
35
+ seconds = int (timestamp )
36
+ nanoseconds = int (timestamp % 1 * 10 ** 9 )
37
+ else :
38
+ seconds = int (timestamp )
36
39
return super ().__new__ (
37
40
cls ,
38
41
code = 0 ,
39
42
data = struct .pack (">II" , seconds , nanoseconds ),
40
43
)
41
44
45
+ @classmethod
46
+ def from_unix_nano (cls , unix_nano ):
47
+ seconds , nanos = divmod (unix_nano , 10 ** 9 )
48
+ return cls (seconds , nanos )
49
+
42
50
43
51
class FluentSender :
44
52
def __init__ (
@@ -78,7 +86,7 @@ def __init__(
78
86
79
87
def emit (self , label , data ):
80
88
if self .nanosecond_precision :
81
- cur_time = EventTime (time .time ())
89
+ cur_time = EventTime . from_unix_nano (time .time_ns ())
82
90
else :
83
91
cur_time = int (time .time ())
84
92
return self .emit_with_time (label , cur_time , data )
@@ -129,7 +137,7 @@ def close(self):
129
137
130
138
def _make_packet (self , label , timestamp , data ):
131
139
if label :
132
- tag = "." . join (( self .tag , label )) if self .tag else label
140
+ tag = f" { self .tag } . { label } " if self .tag else label
133
141
else :
134
142
tag = self .tag
135
143
if self .nanosecond_precision and isinstance (timestamp , float ):
0 commit comments