Skip to content

Commit

Permalink
populate scope.version and scope.attributes only if target is present
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Jun 19, 2024
1 parent 907dcb7 commit c88e5fd
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ pub mod tonic {
),
) -> Self {
let (library, target) = data;
InstrumentationScope {
name: target
.map(|t| t.to_string())
.unwrap_or_else(|| library.name.into_owned()),
version: library.version.map(Cow::into_owned).unwrap_or_default(),
attributes: Attributes::from(library.attributes).0,
..Default::default()
if let Some(t) = target {
InstrumentationScope {
name: t.to_string(),
version: String::new(),
attributes: vec![],
..Default::default()
}

Check warning on line 64 in opentelemetry-proto/src/transform/common.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/common.rs#L59-L64

Added lines #L59 - L64 were not covered by tests
} else {
InstrumentationScope {
name: library.name.into_owned(),
version: library.version.map(Cow::into_owned).unwrap_or_default(),
attributes: Attributes::from(library.attributes).0,
..Default::default()
}
}
}
}
Expand All @@ -79,17 +86,24 @@ pub mod tonic {
),
) -> Self {
let (library, target) = data;
InstrumentationScope {
name: target
.map(|t| t.to_string())
.unwrap_or_else(|| library.name.to_string()),
version: library
.version
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
attributes: Attributes::from(library.attributes.clone()).0,
..Default::default()
if let Some(t) = target {
InstrumentationScope {
name: t.to_string(),
version: String::new(),
attributes: vec![],
..Default::default()
}

Check warning on line 95 in opentelemetry-proto/src/transform/common.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/common.rs#L82-L95

Added lines #L82 - L95 were not covered by tests
} else {
InstrumentationScope {
name: library.name.to_string(),
version: library
.version
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
attributes: Attributes::from(library.attributes.clone()).0,
..Default::default()
}

Check warning on line 106 in opentelemetry-proto/src/transform/common.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/common.rs#L97-L106

Added lines #L97 - L106 were not covered by tests
}
}
}
Expand Down

0 comments on commit c88e5fd

Please sign in to comment.