|
|
|
@ -26,6 +26,8 @@ |
|
|
|
|
|
|
|
|
|
#include <google/protobuf/timestamp.pb.h> |
|
|
|
|
|
|
|
|
|
#include "absl/strings/escaping.h" |
|
|
|
|
#include "absl/strings/match.h" |
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
#include "absl/strings/str_format.h" |
|
|
|
|
#include "absl/types/optional.h" |
|
|
|
@ -34,6 +36,7 @@ |
|
|
|
|
#include "google/logging/v2/logging.grpc.pb.h" |
|
|
|
|
#include "google/logging/v2/logging.pb.h" |
|
|
|
|
|
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
#include <grpc/support/time.h> |
|
|
|
|
#include <grpcpp/grpcpp.h> |
|
|
|
|
#include <grpcpp/security/credentials.h> |
|
|
|
@ -134,8 +137,13 @@ void PayloadToJsonStructProto(LoggingSink::Entry::Payload payload, |
|
|
|
|
auto* metadata_proto = |
|
|
|
|
(*payload_proto->mutable_fields())["metadata"].mutable_struct_value(); |
|
|
|
|
for (auto& metadata : payload.metadata) { |
|
|
|
|
(*metadata_proto->mutable_fields())[metadata.first].set_string_value( |
|
|
|
|
std::move(metadata.second)); |
|
|
|
|
if (absl::EndsWith(metadata.first, "-bin")) { |
|
|
|
|
(*metadata_proto->mutable_fields())[metadata.first].set_string_value( |
|
|
|
|
absl::WebSafeBase64Escape(metadata.second)); |
|
|
|
|
} else { |
|
|
|
|
(*metadata_proto->mutable_fields())[metadata.first].set_string_value( |
|
|
|
|
std::move(metadata.second)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (payload.timeout != grpc_core::Duration::Zero()) { |
|
|
|
@ -152,7 +160,7 @@ void PayloadToJsonStructProto(LoggingSink::Entry::Payload payload, |
|
|
|
|
} |
|
|
|
|
if (!payload.status_details.empty()) { |
|
|
|
|
(*payload_proto->mutable_fields())["statusDetails"].set_string_value( |
|
|
|
|
std::move(payload.status_details)); |
|
|
|
|
absl::Base64Escape(payload.status_details)); |
|
|
|
|
} |
|
|
|
|
if (payload.message_length != 0) { |
|
|
|
|
(*payload_proto->mutable_fields())["messageLength"].set_number_value( |
|
|
|
@ -160,7 +168,7 @@ void PayloadToJsonStructProto(LoggingSink::Entry::Payload payload, |
|
|
|
|
} |
|
|
|
|
if (!payload.message.empty()) { |
|
|
|
|
(*payload_proto->mutable_fields())["message"].set_string_value( |
|
|
|
|
std::move(payload.message)); |
|
|
|
|
absl::Base64Escape(payload.message)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -264,14 +272,17 @@ void ObservabilityLoggingSink::LogEntry(Entry entry) { |
|
|
|
|
proto_entry->mutable_timestamp()->set_nanos(timespec.tv_nsec); |
|
|
|
|
// TODO(yashykt): Check if we need to fill receive timestamp
|
|
|
|
|
EntryToJsonStructProto(std::move(entry), proto_entry->mutable_json_payload()); |
|
|
|
|
stub_->async()->WriteLogEntries(&(call->context), &(call->request), |
|
|
|
|
&(call->response), [call](Status status) { |
|
|
|
|
if (!status.ok()) { |
|
|
|
|
// TODO(yashykt): Log the contents of the
|
|
|
|
|
// request on a failure.
|
|
|
|
|
} |
|
|
|
|
delete call; |
|
|
|
|
}); |
|
|
|
|
stub_->async()->WriteLogEntries( |
|
|
|
|
&(call->context), &(call->request), &(call->response), |
|
|
|
|
[call](Status status) { |
|
|
|
|
if (!status.ok()) { |
|
|
|
|
// TODO(yashykt): Log the contents of the
|
|
|
|
|
// request on a failure.
|
|
|
|
|
gpr_log(GPR_ERROR, "GCP Observability Logging Error %d: %s", |
|
|
|
|
status.error_code(), status.error_message().c_str()); |
|
|
|
|
} |
|
|
|
|
delete call; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ObservabilityLoggingSink::Configuration::Configuration( |
|
|
|
|