Skip to content

Commit

Permalink
Otlp exporter: Ignore status description if status code is not `Error…
Browse files Browse the repository at this point in the history
…`. (#962)
  • Loading branch information
lalitb authored Aug 27, 2021
1 parent c7d6409 commit 4ae969b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion exporters/otlp/src/otlp_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions exporters/otlp/test/otlp_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4ae969b

Please sign in to comment.