Skip to content

Commit 60a3cbe

Browse files
lalitbTommyCppcijothomas
authored
[Logs] fixing couple of issues in LogRecord move (open-telemetry#1725)
Co-authored-by: Zhongyang Wu <zhongyang.wu@outlook.com> Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
1 parent 431baf6 commit 60a3cbe

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

opentelemetry-sdk/src/logs/log_emitter.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use opentelemetry::{
1313
#[cfg(feature = "logs_level_enabled")]
1414
use opentelemetry::logs::Severity;
1515

16-
use std::sync::atomic::AtomicBool;
1716
use std::{borrow::Cow, sync::Arc};
17+
use std::{sync::atomic::AtomicBool, time::SystemTime};
1818

1919
use once_cell::sync::Lazy;
2020

@@ -242,6 +242,9 @@ impl opentelemetry::logs::Logger for Logger {
242242
if let Some(ref trace_context) = trace_context {
243243
cloned_record.trace_context = Some(trace_context.clone());
244244
}
245+
if cloned_record.observed_timestamp.is_none() {
246+
cloned_record.observed_timestamp = Some(SystemTime::now());
247+
}
245248
let data = LogData {
246249
record: cloned_record,
247250
instrumentation: self.instrumentation_library().clone(),

opentelemetry-sdk/src/logs/record.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use opentelemetry::{
55
};
66
use std::{borrow::Cow, time::SystemTime};
77

8-
#[derive(Debug, Clone, Default)]
8+
#[derive(Debug, Default, Clone)]
99
#[non_exhaustive]
1010
/// LogRecord represents all data carried by a log record, and
1111
/// is provided to `LogExporter`s as input.
1212
pub struct LogRecord {
13+
/// Event name. Optional as not all the logging API support it.
14+
pub event_name: Option<Cow<'static, str>>,
15+
1316
/// Record timestamp
1417
pub timestamp: Option<SystemTime>,
1518

@@ -32,6 +35,13 @@ pub struct LogRecord {
3235
}
3336

3437
impl opentelemetry::logs::LogRecord for LogRecord {
38+
fn set_event_name<T>(&mut self, name: T)
39+
where
40+
T: Into<Cow<'static, str>>,
41+
{
42+
self.event_name = Some(name.into());
43+
}
44+
3545
fn set_timestamp(&mut self, timestamp: SystemTime) {
3646
self.timestamp = Some(timestamp);
3747
}

opentelemetry/src/logs/noop.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ pub struct NoopLogRecord;
4141
impl LogRecord for NoopLogRecord {
4242
// Implement the LogRecord trait methods with empty bodies.
4343
#[inline]
44+
fn set_event_name<T>(&mut self, _name: T)
45+
where
46+
T: Into<Cow<'static, str>>,
47+
{
48+
}
49+
#[inline]
4450
fn set_timestamp(&mut self, _timestamp: SystemTime) {}
4551
#[inline]
4652
fn set_observed_timestamp(&mut self, _timestamp: SystemTime) {}

opentelemetry/src/logs/record.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ use std::{borrow::Cow, collections::HashMap, time::SystemTime};
33

44
/// SDK implemented trait for managing log records
55
pub trait LogRecord {
6+
/// Sets the `event_name` of a record
7+
fn set_event_name<T>(&mut self, _name: T)
8+
where
9+
T: Into<Cow<'static, str>>,
10+
{
11+
}
12+
613
/// Sets the time when the event occurred measured by the origin clock, i.e. the time at the source.
714
fn set_timestamp(&mut self, timestamp: SystemTime);
815

0 commit comments

Comments
 (0)