Skip to content

Commit 354c83f

Browse files
authored
Remove StatusCode::as_str (#741)
The spec does not define a string representation, this was a jaeger-specific conversion.
1 parent 5f1bd35 commit 354c83f

File tree

2 files changed

+7
-18
lines changed
  • opentelemetry-api/src/trace
  • opentelemetry-jaeger/src/exporter

2 files changed

+7
-18
lines changed

opentelemetry-api/src/trace/span.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,3 @@ pub enum StatusCode {
260260
/// The operation contains an error.
261261
Error,
262262
}
263-
264-
impl StatusCode {
265-
/// Return a static str that represent the status code
266-
pub fn as_str(&self) -> &'static str {
267-
match self {
268-
StatusCode::Unset => "",
269-
StatusCode::Ok => "OK",
270-
StatusCode::Error => "ERROR",
271-
}
272-
}
273-
}

opentelemetry-jaeger/src/exporter/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,11 @@ fn build_span_tags(
773773
tags.push(Key::new(ERROR).bool(true).into());
774774
}
775775
if !user_overrides.status_code {
776-
tags.push(
777-
Key::new(OTEL_STATUS_CODE)
778-
.string::<&'static str>(status_code.as_str())
779-
.into(),
780-
);
776+
if status_code == StatusCode::Ok {
777+
tags.push(KeyValue::new(OTEL_STATUS_CODE, "OK").into());
778+
} else if status_code == StatusCode::Error {
779+
tags.push(KeyValue::new(OTEL_STATUS_CODE, "ERROR").into());
780+
}
781781
}
782782
// set status message if there is one
783783
if !status_description.is_empty() && !user_overrides.status_description {
@@ -1057,7 +1057,7 @@ mod tests {
10571057
let user_status_description = "Something bad happened";
10581058
attributes.insert(KeyValue::new("error", user_error));
10591059
attributes.insert(KeyValue::new(SPAN_KIND, user_kind));
1060-
attributes.insert(KeyValue::new(OTEL_STATUS_CODE, user_status_code.as_str()));
1060+
attributes.insert(KeyValue::new(OTEL_STATUS_CODE, "ERROR"));
10611061
attributes.insert(KeyValue::new(
10621062
OTEL_STATUS_DESCRIPTION,
10631063
user_status_description,
@@ -1075,7 +1075,7 @@ mod tests {
10751075
.filter(|tag| tag.key.as_str() == "error")
10761076
.all(|tag| tag.v_bool.unwrap()));
10771077
assert_tag_contains(tags.clone(), SPAN_KIND, user_kind);
1078-
assert_tag_contains(tags.clone(), OTEL_STATUS_CODE, user_status_code.as_str());
1078+
assert_tag_contains(tags.clone(), OTEL_STATUS_CODE, "ERROR");
10791079
assert_tag_contains(tags, OTEL_STATUS_DESCRIPTION, user_status_description);
10801080
}
10811081

0 commit comments

Comments
 (0)