diff --git a/src/core/ext/filters/logging/logging_filter.cc b/src/core/ext/filters/logging/logging_filter.cc index 761d554e57a..474649ab375 100644 --- a/src/core/ext/filters/logging/logging_filter.cc +++ b/src/core/ext/filters/logging/logging_filter.cc @@ -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 { diff --git a/src/core/ext/filters/logging/logging_sink.h b/src/core/ext/filters/logging/logging_sink.h index 355d1447939..dda5961f37b 100644 --- a/src/core/ext/filters/logging/logging_sink.h +++ b/src/core/ext/filters/logging/logging_sink.h @@ -107,6 +107,7 @@ class LoggingSink { std::string trace_id; std::string span_id; bool is_sampled; + bool is_trailer_only; }; virtual ~LoggingSink() = default;