fix(otel): set timestamp on opentelemetry log records (#28625)
Some checks are pending
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions

Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
William Perron 2025-06-03 13:56:32 -04:00 committed by GitHub
parent b42d5906cd
commit a3395ba972
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 9 deletions

View file

@ -882,7 +882,9 @@ pub fn handle_log(record: &log::Record) {
let mut log_record = LogRecord::default();
log_record.set_observed_timestamp(SystemTime::now());
let now = SystemTime::now();
log_record.set_timestamp(now);
log_record.set_observed_timestamp(now);
log_record.set_severity_number(match record.level() {
Level::Error => Severity::Error,
Level::Warn => Severity::Warn,
@ -1124,7 +1126,9 @@ fn op_otel_log<'s>(
};
let mut log_record = LogRecord::default();
log_record.set_observed_timestamp(SystemTime::now());
let now = SystemTime::now();
log_record.set_timestamp(now);
log_record.set_observed_timestamp(now);
let Ok(message) = message.try_cast() else {
return;
};
@ -1188,7 +1192,9 @@ fn op_otel_log_foreign(
let mut log_record = LogRecord::default();
log_record.set_observed_timestamp(SystemTime::now());
let now = SystemTime::now();
log_record.set_timestamp(now);
log_record.set_observed_timestamp(now);
log_record.set_body(message.into());
log_record.set_severity_number(severity);
log_record.set_severity_text(severity.name());

View file

@ -161,7 +161,7 @@
],
"logs": [
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDLINE]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 9,
"severityText": "INFO",
@ -175,7 +175,7 @@
"spanId": "0000000000000004"
},
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDLINE]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 9,
"severityText": "INFO",

View file

@ -2,7 +2,7 @@
"spans": [],
"logs": [
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDCARD]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 9,
"severityText": "INFO",

View file

@ -2,7 +2,7 @@
"spans": [],
"logs": [
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDLINE]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 9,
"severityText": "INFO",

View file

@ -6,7 +6,7 @@ throw new Error("uncaught");
"spans": [],
"logs": [
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDLINE]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 9,
"severityText": "INFO",
@ -20,7 +20,7 @@ throw new Error("uncaught");
"spanId": ""
},
{
"timeUnixNano": "0",
"timeUnixNano": "[WILDLINE]",
"observedTimeUnixNano": "[WILDCARD]",
"severityNumber": 17,
"severityText": "ERROR",