diff --git a/src/cpp/ext/filters/logging/logging_filter.cc b/src/cpp/ext/filters/logging/logging_filter.cc index 2388a5a5d17..2e664e92d18 100644 --- a/src/cpp/ext/filters/logging/logging_filter.cc +++ b/src/cpp/ext/filters/logging/logging_filter.cc @@ -20,8 +20,8 @@ #include "src/cpp/ext/filters/logging/logging_filter.h" +#include #include -#include #include #include @@ -117,10 +117,11 @@ class MetadataEncoder { } uint64_t mdentry_len = key.length() + value.length(); if (mdentry_len > log_len_) { - gpr_log(GPR_DEBUG, - "Skipped metadata key because of max metadata logging bytes %lu " - "(current) vs %lu (max less already accounted metadata)", - mdentry_len, log_len_); + gpr_log( + GPR_DEBUG, + "Skipped metadata key because of max metadata logging bytes %" PRIu64 + " (current) vs %" PRIu64 " (max less already accounted metadata)", + mdentry_len, log_len_); truncated_ = true; return; } diff --git a/src/cpp/ext/gcp/BUILD b/src/cpp/ext/gcp/BUILD index 91686afeaa1..a25f621b385 100644 --- a/src/cpp/ext/gcp/BUILD +++ b/src/cpp/ext/gcp/BUILD @@ -51,9 +51,11 @@ grpc_cc_library( visibility = ["//:__subpackages__"], deps = [ "observability_config", + "observability_logging_sink", "//:gpr", "//:grpc++", "//:grpc_opencensus_plugin", + "//src/cpp/ext/filters/logging:logging_filter", ], ) diff --git a/src/cpp/ext/gcp/observability.cc b/src/cpp/ext/gcp/observability.cc index 95f6fbb1da3..5566ab2a716 100644 --- a/src/cpp/ext/gcp/observability.cc +++ b/src/cpp/ext/gcp/observability.cc @@ -40,7 +40,9 @@ #include "src/cpp/ext/filters/census/grpc_plugin.h" #include "src/cpp/ext/filters/census/open_census_call_tracer.h" +#include "src/cpp/ext/filters/logging/logging_filter.h" #include "src/cpp/ext/gcp/observability_config.h" +#include "src/cpp/ext/gcp/observability_logging_sink.h" namespace grpc { namespace experimental { @@ -80,7 +82,8 @@ absl::Status GcpObservabilityInit() { return config.status(); } if (!config->cloud_trace.has_value() && - !config->cloud_monitoring.has_value()) { + !config->cloud_monitoring.has_value() && + !config->cloud_logging.has_value()) { return absl::OkStatus(); } grpc::RegisterOpenCensusPlugin(); @@ -116,6 +119,11 @@ absl::Status GcpObservabilityInit() { // Disable OpenCensus stats EnableOpenCensusStats(false); } + if (config->cloud_logging.has_value()) { + grpc::internal::RegisterLoggingFilter( + new grpc::internal::ObservabilityLoggingSink( + config->cloud_logging.value(), config->project_id)); + } return absl::OkStatus(); }