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