Skip to content

Commit 3e5fd65

Browse files
author
pananton
committed
feat grpc: add 'error_msg' tag to client span in case gRPC call was interrupted
commit_hash:24738f06f74becf63beebbf60deb3445a2ac394b
1 parent aac1295 commit 3e5fd65

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

grpc/include/userver/ugrpc/client/completion_status.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ enum class SpecialCaseCompletionType : std::uint8_t {
5353
/// @brief Convert SpecialCaseCompletionType to string representation.
5454
std::string_view ToString(SpecialCaseCompletionType type);
5555

56+
/// @brief Convert SpecialCaseCompletionType to human-readable description.
57+
std::string_view GetSpecialCaseCompletionTypeDescription(SpecialCaseCompletionType type);
58+
5659
/// @ingroup userver_ugrpc
5760
///
5861
/// @brief Result type for gRPC client call completion.

grpc/src/ugrpc/client/completion_status.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ std::string_view ToString(SpecialCaseCompletionType type) {
1818
return "unknown";
1919
}
2020

21+
std::string_view GetSpecialCaseCompletionTypeDescription(SpecialCaseCompletionType type) {
22+
switch (type) {
23+
case SpecialCaseCompletionType::kNetworkError:
24+
return "underlying network operation failed (e.g., connection lost, socket error)";
25+
case SpecialCaseCompletionType::kTimeoutDeadlinePropagated:
26+
return "timed out because of the propagated deadline from the upstream request";
27+
case SpecialCaseCompletionType::kCancelled:
28+
return "task was cancelled (e.g. calling code dropped TaskWithResult object, or upstream client cancelled "
29+
"the request)";
30+
case SpecialCaseCompletionType::kAbandoned:
31+
return "object representing the call was destroyed before the call could complete normally";
32+
}
33+
34+
return "unknown completion type";
35+
}
36+
2137
} // namespace ugrpc::client
2238

2339
USERVER_NAMESPACE_END

grpc/src/ugrpc/client/middlewares/log/middleware.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <ugrpc/client/middlewares/log/middleware.hpp>
22

3+
#include <fmt/format.h>
4+
35
#include <userver/logging/level.hpp>
46
#include <userver/logging/log_extra.hpp>
57
#include <userver/tracing/tags.hpp>
@@ -116,8 +118,15 @@ void Middleware::PostFinish(MiddlewareCallContext& context, const CompletionStat
116118
} else {
117119
// Special case completion
118120
const auto completion_type = result.error();
119-
logging::LogExtra
120-
extra{{ugrpc::impl::kTypeTag, "special_case_completion"}, {"completion_type", ToString(completion_type)}};
121+
logging::LogExtra extra{
122+
{ugrpc::impl::kTypeTag, "special_case_completion"},
123+
{"completion_type", ToString(completion_type)},
124+
{tracing::kErrorMessage,
125+
fmt::format(
126+
"Call is interrupted before it was finished and response with status code was received, reason='{}'",
127+
GetSpecialCaseCompletionTypeDescription(completion_type)
128+
)}
129+
};
121130
logger.Log(logging::Level::kWarning, "gRPC error", std::move(extra));
122131
}
123132
}

0 commit comments

Comments
 (0)