Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Otlp exporter: Ignore status description if status code is not Error. #962

Merged
merged 5 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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