Skip to content

Commit 460d45b

Browse files
committed
fix
1 parent 89e939d commit 460d45b

File tree

1 file changed

+36
-36
lines changed
  • opentelemetry-appender-tracing/src

1 file changed

+36
-36
lines changed

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,62 @@ fn get_filename(filepath: &str) -> &str {
3535
filepath
3636
}
3737

38-
impl <'a, LR: LogRecord> EventVisitor<'a, LR> {
38+
impl<'a, LR: LogRecord> EventVisitor<'a, LR> {
3939
fn new(log_record: &'a mut LR) -> Self {
40-
EventVisitor{log_record}
40+
EventVisitor { log_record }
4141
}
4242
fn visit_metadata(&mut self, meta: &Metadata) {
43-
self.log_record.add_attribute(Key::new("name"), AnyValue::from(meta.name()));
43+
self.log_record
44+
.add_attribute(Key::new("name"), AnyValue::from(meta.name()));
4445

4546
#[cfg(feature = "experimental_metadata_attributes")]
4647
self.visit_experimental_metadata(meta);
4748
}
4849

4950
#[cfg(feature = "experimental_metadata_attributes")]
5051
fn visit_experimental_metadata(&mut self, meta: &Metadata) {
51-
self.log_record_attributes
52-
.push(("log.target".into(), meta.target().to_owned().into()));
52+
self.log_record.add_attribute(
53+
Key::new("log.target"),
54+
AnyValue::from(meta.target().to_owned()),
55+
);
5356

5457
if let Some(module_path) = meta.module_path() {
55-
self.log_record_attributes
56-
.push(("code.namespace".into(), module_path.to_owned().into()));
58+
self.log_record.add_attribute(
59+
Key::new("code.namespace"),
60+
AnyValue::from(module_path.to_owned()),
61+
);
62+
s
5763
}
5864

5965
if let Some(filepath) = meta.file() {
60-
self.log_record_attributes
61-
.push(("code.filepath".into(), filepath.to_owned().into()));
62-
self.log_record_attributes.push((
63-
"code.filename".into(),
64-
get_filename(filepath).to_owned().into(),
65-
));
66+
self.log_record.add_attribute(
67+
Key::new("code.filepath"),
68+
AnyValue::from(filepath.to_owned()),
69+
);
70+
self.log_record.add_attribute(
71+
Key::new("code.filename"),
72+
AnyValue::from(get_filename(filepath).to_owned()),
73+
);
6674
}
6775

6876
if let Some(line) = meta.line() {
69-
self.log_record_attributes
70-
.push(("code.lineno".into(), line.into()));
71-
}
72-
}
73-
74-
fn push_to_otel_log_record<LR: LogRecord>(self, log_record: &mut LR) {
75-
if let Some(body) = self.log_record_body {
76-
log_record.set_body(body);
77+
self.log_record
78+
.add_attribute(Key::new("code.lineno"), AnyValue::from(line));
7779
}
78-
log_record.add_attributes(self.log_record_attributes);
7980
}
8081
}
8182

82-
impl tracing::field::Visit for EventVisitor {
83+
impl<'a, LR: LogRecord> tracing::field::Visit for EventVisitor<'a, LR> {
8384
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
8485
#[cfg(feature = "experimental_metadata_attributes")]
8586
if is_duplicated_metadata(field.name()) {
8687
return;
8788
}
8889
if field.name() == "message" {
89-
self.log_record_body = Some(format!("{value:?}").into());
90+
self.log_record.set_body(format!("{:?}", value).into());
9091
} else {
91-
self.log_record_attributes
92-
.push((field.name().into(), format!("{value:?}").into()));
92+
self.log_record
93+
.add_attribute(Key::new(field.name()), AnyValue::from(format!("{value:?}")));
9394
}
9495
}
9596

@@ -98,27 +99,27 @@ impl tracing::field::Visit for EventVisitor {
9899
if is_duplicated_metadata(field.name()) {
99100
return;
100101
}
101-
self.log_record_attributes
102-
.push((field.name().into(), value.to_owned().into()));
102+
self.log_record
103+
.add_attribute(Key::new(field.name()), AnyValue::from(value.to_owned()));
103104
}
104105

105106
fn record_bool(&mut self, field: &tracing_core::Field, value: bool) {
106-
self.log_record_attributes
107-
.push((field.name().into(), value.into()));
107+
self.log_record
108+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
108109
}
109110

110111
fn record_f64(&mut self, field: &tracing::field::Field, value: f64) {
111-
self.log_record_attributes
112-
.push((field.name().into(), value.into()));
112+
self.log_record
113+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
113114
}
114115

115116
fn record_i64(&mut self, field: &tracing::field::Field, value: i64) {
116117
#[cfg(feature = "experimental_metadata_attributes")]
117118
if is_duplicated_metadata(field.name()) {
118119
return;
119120
}
120-
self.log_record_attributes
121-
.push((field.name().into(), value.into()));
121+
self.log_record
122+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
122123
}
123124

124125
// TODO: Remaining field types from AnyValue : Bytes, ListAny, Boolean
@@ -173,11 +174,10 @@ where
173174
log_record.set_severity_number(severity_of_level(meta.level()));
174175
log_record.set_severity_text(meta.level().to_string().into());
175176

176-
let mut visitor = EventVisitor::default();
177+
let mut visitor = EventVisitor::new(&mut log_record);
177178
visitor.visit_metadata(meta);
178179
// Visit fields.
179180
event.record(&mut visitor);
180-
visitor.push_to_otel_log_record(&mut log_record);
181181

182182
self.logger.emit(log_record);
183183
}

0 commit comments

Comments
 (0)