Skip to content

Commit

Permalink
Remove target from LogRecord::attributes for log events emitted t…
Browse files Browse the repository at this point in the history
…hrough `tracing` pipeline (#2101)
  • Loading branch information
lalitb authored Sep 11, 2024
1 parent 38f7fd5 commit 8f4d64e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-appender-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

- [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.


## v0.25.0

- Update `opentelemetry` dependency version to 0.25
Expand Down
22 changes: 9 additions & 13 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ impl<'a, LR: LogRecord> EventVisitor<'a, LR> {

#[cfg(feature = "experimental_metadata_attributes")]
fn visit_experimental_metadata(&mut self, meta: &Metadata) {
self.log_record.add_attribute(
Key::new("log.target"),
AnyValue::from(meta.target().to_owned()),
);

if let Some(module_path) = meta.module_path() {
self.log_record.add_attribute(
Key::new("code.namespace"),
Expand Down Expand Up @@ -164,6 +159,7 @@ where
) {
#[cfg(feature = "experimental_metadata_attributes")]
let normalized_meta = event.normalized_metadata();

#[cfg(feature = "experimental_metadata_attributes")]
let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata());

Expand Down Expand Up @@ -269,7 +265,7 @@ mod tests {
#[cfg(not(feature = "experimental_metadata_attributes"))]
assert_eq!(log.record.attributes_iter().count(), 3);
#[cfg(feature = "experimental_metadata_attributes")]
assert_eq!(log.record.attributes_iter().count(), 8);
assert_eq!(log.record.attributes_iter().count(), 7);
assert!(attributes_contains(
&log.record,
&Key::new("event_id"),
Expand Down Expand Up @@ -307,7 +303,7 @@ mod tests {
.collect();
assert!(attributes_key.contains(&Key::new("code.filepath")));
assert!(attributes_key.contains(&Key::new("code.lineno")));
assert!(attributes_key.contains(&Key::new("log.target")));
assert!(!attributes_key.contains(&Key::new("log.target")));
}
}

Expand Down Expand Up @@ -381,7 +377,7 @@ mod tests {
#[cfg(not(feature = "experimental_metadata_attributes"))]
assert_eq!(log.record.attributes_iter().count(), 3);
#[cfg(feature = "experimental_metadata_attributes")]
assert_eq!(log.record.attributes_iter().count(), 8);
assert_eq!(log.record.attributes_iter().count(), 7);
assert!(attributes_contains(
&log.record,
&Key::new("event_id"),
Expand Down Expand Up @@ -419,7 +415,7 @@ mod tests {
.collect();
assert!(attributes_key.contains(&Key::new("code.filepath")));
assert!(attributes_key.contains(&Key::new("code.lineno")));
assert!(attributes_key.contains(&Key::new("log.target")));
assert!(!attributes_key.contains(&Key::new("log.target")));
}
}

Expand Down Expand Up @@ -461,7 +457,7 @@ mod tests {

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

#[cfg(feature = "experimental_metadata_attributes")]
{
Expand All @@ -485,7 +481,7 @@ mod tests {
.collect();
assert!(attributes_key.contains(&Key::new("code.filepath")));
assert!(attributes_key.contains(&Key::new("code.lineno")));
assert!(attributes_key.contains(&Key::new("log.target")));
assert!(!attributes_key.contains(&Key::new("log.target")));
}
}

Expand Down Expand Up @@ -558,7 +554,7 @@ mod tests {

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

#[cfg(feature = "experimental_metadata_attributes")]
{
Expand All @@ -582,7 +578,7 @@ mod tests {
.collect();
assert!(attributes_key.contains(&Key::new("code.filepath")));
assert!(attributes_key.contains(&Key::new("code.lineno")));
assert!(attributes_key.contains(&Key::new("log.target")));
assert!(!attributes_key.contains(&Key::new("log.target")));
}
}
}

0 comments on commit 8f4d64e

Please sign in to comment.