Skip to content

Commit 8f4d64e

Browse files
authored
Remove target from LogRecord::attributes for log events emitted through tracing pipeline (#2101)
1 parent 38f7fd5 commit 8f4d64e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

opentelemetry-appender-tracing/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## vNext
44

5+
- [2101](https://github.com/open-telemetry/opentelemetry-rust/pull/2101) The `log` events emitted via the `tracing` pipeline using the `log-tracing` crate no longer include the target metadata as attributes. Exporters or backends that rely on this attribute should now access the target directly from the `LogRecord::target` field.
6+
7+
58
## v0.25.0
69

710
- Update `opentelemetry` dependency version to 0.25

opentelemetry-appender-tracing/src/layer.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ impl<'a, LR: LogRecord> EventVisitor<'a, LR> {
4444

4545
#[cfg(feature = "experimental_metadata_attributes")]
4646
fn visit_experimental_metadata(&mut self, meta: &Metadata) {
47-
self.log_record.add_attribute(
48-
Key::new("log.target"),
49-
AnyValue::from(meta.target().to_owned()),
50-
);
51-
5247
if let Some(module_path) = meta.module_path() {
5348
self.log_record.add_attribute(
5449
Key::new("code.namespace"),
@@ -164,6 +159,7 @@ where
164159
) {
165160
#[cfg(feature = "experimental_metadata_attributes")]
166161
let normalized_meta = event.normalized_metadata();
162+
167163
#[cfg(feature = "experimental_metadata_attributes")]
168164
let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata());
169165

@@ -269,7 +265,7 @@ mod tests {
269265
#[cfg(not(feature = "experimental_metadata_attributes"))]
270266
assert_eq!(log.record.attributes_iter().count(), 3);
271267
#[cfg(feature = "experimental_metadata_attributes")]
272-
assert_eq!(log.record.attributes_iter().count(), 8);
268+
assert_eq!(log.record.attributes_iter().count(), 7);
273269
assert!(attributes_contains(
274270
&log.record,
275271
&Key::new("event_id"),
@@ -307,7 +303,7 @@ mod tests {
307303
.collect();
308304
assert!(attributes_key.contains(&Key::new("code.filepath")));
309305
assert!(attributes_key.contains(&Key::new("code.lineno")));
310-
assert!(attributes_key.contains(&Key::new("log.target")));
306+
assert!(!attributes_key.contains(&Key::new("log.target")));
311307
}
312308
}
313309

@@ -381,7 +377,7 @@ mod tests {
381377
#[cfg(not(feature = "experimental_metadata_attributes"))]
382378
assert_eq!(log.record.attributes_iter().count(), 3);
383379
#[cfg(feature = "experimental_metadata_attributes")]
384-
assert_eq!(log.record.attributes_iter().count(), 8);
380+
assert_eq!(log.record.attributes_iter().count(), 7);
385381
assert!(attributes_contains(
386382
&log.record,
387383
&Key::new("event_id"),
@@ -419,7 +415,7 @@ mod tests {
419415
.collect();
420416
assert!(attributes_key.contains(&Key::new("code.filepath")));
421417
assert!(attributes_key.contains(&Key::new("code.lineno")));
422-
assert!(attributes_key.contains(&Key::new("log.target")));
418+
assert!(!attributes_key.contains(&Key::new("log.target")));
423419
}
424420
}
425421

@@ -461,7 +457,7 @@ mod tests {
461457

462458
// Attributes can be polluted when we don't use this feature.
463459
#[cfg(feature = "experimental_metadata_attributes")]
464-
assert_eq!(log.record.attributes_iter().count(), 5);
460+
assert_eq!(log.record.attributes_iter().count(), 4);
465461

466462
#[cfg(feature = "experimental_metadata_attributes")]
467463
{
@@ -485,7 +481,7 @@ mod tests {
485481
.collect();
486482
assert!(attributes_key.contains(&Key::new("code.filepath")));
487483
assert!(attributes_key.contains(&Key::new("code.lineno")));
488-
assert!(attributes_key.contains(&Key::new("log.target")));
484+
assert!(!attributes_key.contains(&Key::new("log.target")));
489485
}
490486
}
491487

@@ -558,7 +554,7 @@ mod tests {
558554

559555
// Attributes can be polluted when we don't use this feature.
560556
#[cfg(feature = "experimental_metadata_attributes")]
561-
assert_eq!(log.record.attributes_iter().count(), 5);
557+
assert_eq!(log.record.attributes_iter().count(), 4);
562558

563559
#[cfg(feature = "experimental_metadata_attributes")]
564560
{
@@ -582,7 +578,7 @@ mod tests {
582578
.collect();
583579
assert!(attributes_key.contains(&Key::new("code.filepath")));
584580
assert!(attributes_key.contains(&Key::new("code.lineno")));
585-
assert!(attributes_key.contains(&Key::new("log.target")));
581+
assert!(!attributes_key.contains(&Key::new("log.target")));
586582
}
587583
}
588584
}

0 commit comments

Comments
 (0)