diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index a17419df7e..8562ecc7ae 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -293,7 +293,10 @@ void OtlpRecordable::AddLink(const opentelemetry::trace::SpanContext &span_conte void OtlpRecordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept { span_.mutable_status()->set_code(opentelemetry::proto::trace::v1::Status_StatusCode(code)); - span_.mutable_status()->set_message(description.data(), description.size()); + if (code == trace::StatusCode::kError) + { + span_.mutable_status()->set_message(description.data(), description.size()); + } } void OtlpRecordable::SetName(nostd::string_view name) noexcept diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 9d34cd26a4..bc5e76bac0 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -93,13 +93,21 @@ TEST(OtlpRecordable, SetDuration) TEST(OtlpRecordable, SetStatus) { - OtlpRecordable rec; - trace::StatusCode code(trace::StatusCode::kOk); + OtlpRecordable rec1; + trace::StatusCode code_error(trace::StatusCode::kError); nostd::string_view description = "For test"; - rec.SetStatus(code, description); - - EXPECT_EQ(rec.span().status().code(), opentelemetry::proto::trace::v1::Status_StatusCode(code)); - EXPECT_EQ(rec.span().status().message(), description); + rec1.SetStatus(code_error, description); + + EXPECT_EQ(rec1.span().status().code(), + opentelemetry::proto::trace::v1::Status_StatusCode(code_error)); + EXPECT_EQ(rec1.span().status().message(), description); + + OtlpRecordable rec2; + trace::StatusCode code_ok(trace::StatusCode::kOk); + rec2.SetStatus(code_ok, description); + EXPECT_EQ(rec2.span().status().code(), + opentelemetry::proto::trace::v1::Status_StatusCode(code_ok)); + EXPECT_EQ(rec2.span().status().message(), ""); } TEST(OtlpRecordable, AddEventDefault)