[logging] Handle trailers-only responses (#33461)

Will be used in the internal logging sink.
pull/33470/head
Craig Tiller 1 year ago committed by GitHub
parent d55431995c
commit cb9fe64fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/core/ext/filters/logging/logging_filter.cc
  2. 1
      src/core/ext/filters/logging/logging_sink.h

@ -256,21 +256,19 @@ class CallData {
void LogServerHeader(bool is_client, CallTracerAnnotationInterface* tracer,
const ServerMetadata* metadata) {
LoggingSink::Entry entry;
if (metadata != nullptr) {
if (is_client) {
if (auto* value = metadata->get_pointer(PeerString())) {
peer_ = PeerStringToAddress(*value);
}
if (is_client) {
if (auto* value = metadata->get_pointer(PeerString())) {
peer_ = PeerStringToAddress(*value);
}
}
SetCommonEntryFields(&entry, is_client, tracer,
LoggingSink::Entry::EventType::kServerHeader);
if (metadata != nullptr) {
MetadataEncoder encoder(&entry.payload, nullptr,
config_.max_metadata_bytes());
metadata->Encode(&encoder);
entry.payload_truncated = encoder.truncated();
}
if (metadata->TransportSize() == 0) return;
seen_server_header_ = true;
MetadataEncoder encoder(&entry.payload, nullptr,
config_.max_metadata_bytes());
metadata->Encode(&encoder);
entry.payload_truncated = encoder.truncated();
g_logging_sink->LogEntry(std::move(entry));
}
@ -279,6 +277,7 @@ class CallData {
LoggingSink::Entry entry;
SetCommonEntryFields(&entry, is_client, tracer,
LoggingSink::Entry::EventType::kServerTrailer);
entry.is_trailer_only = !seen_server_header_;
if (metadata != nullptr) {
MetadataEncoder encoder(&entry.payload, &entry.payload.status_details,
config_.max_metadata_bytes());
@ -340,6 +339,7 @@ class CallData {
std::string authority_;
LoggingSink::Entry::Address peer_;
LoggingSink::Config config_;
bool seen_server_header_ = false;
};
class ClientLoggingFilter final : public ChannelFilter {

@ -107,6 +107,7 @@ class LoggingSink {
std::string trace_id;
std::string span_id;
bool is_sampled;
bool is_trailer_only;
};
virtual ~LoggingSink() = default;

Loading…
Cancel
Save