@@ -256,19 +256,22 @@ impl OtlpEncoder {
256
256
fn write_row_data ( & self , log : & LogRecord , sorted_fields : & [ FieldDef ] ) -> Vec < u8 > {
257
257
let mut buffer = Vec :: with_capacity ( sorted_fields. len ( ) * 50 ) ; //TODO - estimate better
258
258
259
+ // Pre-calculate timestamp to avoid duplicate computation for FIELD_TIMESTAMP and FIELD_ENV_TIME
260
+ let formatted_timestamp = {
261
+ let timestamp_nanos = if log. time_unix_nano != 0 {
262
+ log. time_unix_nano
263
+ } else {
264
+ log. observed_time_unix_nano
265
+ } ;
266
+ Self :: format_timestamp ( timestamp_nanos)
267
+ } ;
268
+
259
269
for field in sorted_fields {
260
270
match field. name . as_ref ( ) {
261
271
FIELD_ENV_NAME => BondWriter :: write_string ( & mut buffer, "TestEnv" ) , // TODO - placeholder for actual env name
262
272
FIELD_ENV_VER => BondWriter :: write_string ( & mut buffer, "4.0" ) , // TODO - placeholder for actual env version
263
273
FIELD_TIMESTAMP | FIELD_ENV_TIME => {
264
- // Use the same timestamp precedence logic: prefer time_unix_nano, fall back to observed_time_unix_nano
265
- let timestamp_nanos = if log. time_unix_nano != 0 {
266
- log. time_unix_nano
267
- } else {
268
- log. observed_time_unix_nano
269
- } ;
270
- let dt = Self :: format_timestamp ( timestamp_nanos) ;
271
- BondWriter :: write_string ( & mut buffer, & dt) ;
274
+ BondWriter :: write_string ( & mut buffer, & formatted_timestamp) ;
272
275
}
273
276
FIELD_TRACE_ID => {
274
277
let hex_bytes = Self :: encode_id_to_hex :: < 32 > ( & log. trace_id ) ;
0 commit comments