Skip to content

Commit 5b6bf7e

Browse files
Copilotlalitb
andauthored
fix: [Geneva Exporter] Optimize duplicate timestamp calculation in Geneva exporter OTLP encoder (#415)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: lalitb <[email protected]>
1 parent 94b56d3 commit 5b6bf7e

File tree

1 file changed

+11
-8
lines changed
  • opentelemetry-exporter-geneva/geneva-uploader/src/payload_encoder

1 file changed

+11
-8
lines changed

opentelemetry-exporter-geneva/geneva-uploader/src/payload_encoder/otlp_encoder.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,22 @@ impl OtlpEncoder {
256256
fn write_row_data(&self, log: &LogRecord, sorted_fields: &[FieldDef]) -> Vec<u8> {
257257
let mut buffer = Vec::with_capacity(sorted_fields.len() * 50); //TODO - estimate better
258258

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+
259269
for field in sorted_fields {
260270
match field.name.as_ref() {
261271
FIELD_ENV_NAME => BondWriter::write_string(&mut buffer, "TestEnv"), // TODO - placeholder for actual env name
262272
FIELD_ENV_VER => BondWriter::write_string(&mut buffer, "4.0"), // TODO - placeholder for actual env version
263273
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);
272275
}
273276
FIELD_TRACE_ID => {
274277
let hex_bytes = Self::encode_id_to_hex::<32>(&log.trace_id);

0 commit comments

Comments
 (0)