From 8c68c8d2437ef1856d762f23b960c146277d3f53 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Nov 2022 12:06:14 -0800 Subject: [PATCH] Add status code to OTLP grpc trace log --- exporters/otlp/BUILD | 2 + exporters/otlp/CMakeLists.txt | 2 +- .../exporters/otlp/otlp_grpc_utils.h | 25 ++++++++ exporters/otlp/src/otlp_grpc_exporter.cc | 8 +-- exporters/otlp/src/otlp_grpc_utils.cc | 62 +++++++++++++++++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_utils.h create mode 100644 exporters/otlp/src/otlp_grpc_utils.cc diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 04f922f1d8..d35e46be5c 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -19,6 +19,7 @@ load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") cc_library( name = "otlp_recordable", srcs = [ + "src/otlp_grpc_utils.cc", "src/otlp_log_recordable.cc", "src/otlp_metric_utils.cc", "src/otlp_populate_attribute_utils.cc", @@ -26,6 +27,7 @@ cc_library( "src/otlp_recordable_utils.cc", ], hdrs = [ + "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/otlp_log_recordable.h", "include/opentelemetry/exporters/otlp/otlp_metric_utils.h", "include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h", diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index bb8e602f77..1ab0c7cb33 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -2,7 +2,7 @@ add_library( opentelemetry_otlp_recordable src/otlp_log_recordable.cc src/otlp_recordable.cc src/otlp_populate_attribute_utils.cc src/otlp_recordable_utils.cc - src/otlp_metric_utils.cc) + src/otlp_metric_utils.cc src/otlp_grpc_utils.cc) set_target_properties(opentelemetry_otlp_recordable PROPERTIES EXPORT_NAME otlp_recordable) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_utils.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_utils.h new file mode 100644 index 0000000000..504b0e9df3 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_utils.h @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/version/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE + +namespace exporter +{ +namespace otlp +{ +namespace grpc_utils +{ + +const char *grpc_status_code_to_string(::grpc::StatusCode status_code); + +} // namespace grpc_utils +} // namespace otlp +} // namespace exporter + +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index 28a8aa173b..b3878443e1 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -11,7 +11,7 @@ #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/sdk_config.h" -#include +#include "opentelemetry/exporters/otlp/otlp_grpc_utils.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -64,9 +64,9 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( if (!status.ok()) { - - OTEL_INTERNAL_LOG_ERROR( - "[OTLP TRACE GRPC Exporter] Export() failed: " << status.error_message()); + OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] Export() failed with statuc_code: \"" + << grpc_utils::grpc_status_code_to_string(status.error_code()) + << "\" error_message: \"" << status.error_message() << "\""); return sdk::common::ExportResult::kFailure; } return sdk::common::ExportResult::kSuccess; diff --git a/exporters/otlp/src/otlp_grpc_utils.cc b/exporters/otlp/src/otlp_grpc_utils.cc new file mode 100644 index 0000000000..02094fb3f9 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_utils.cc @@ -0,0 +1,62 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_utils.h" + +OPENTELEMETRY_BEGIN_NAMESPACE + +namespace exporter +{ +namespace otlp +{ +namespace grpc_utils +{ + +const char *grpc_status_code_to_string(::grpc::StatusCode status_code) +{ + switch (status_code) + { + case GRPC_STATUS_OK: + return "OK"; + case GRPC_STATUS_CANCELLED: + return "CANCELLED"; + case GRPC_STATUS_UNKNOWN: + return "UNKNOWN"; + case GRPC_STATUS_INVALID_ARGUMENT: + return "INVALID_ARGUMENT"; + case GRPC_STATUS_DEADLINE_EXCEEDED: + return "DEADLINE_EXCEEDED"; + case GRPC_STATUS_NOT_FOUND: + return "NOT_FOUND"; + case GRPC_STATUS_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case GRPC_STATUS_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case GRPC_STATUS_UNAUTHENTICATED: + return "UNAUTHENTICATED"; + case GRPC_STATUS_RESOURCE_EXHAUSTED: + return "RESOURCE_EXHAUSTED"; + case GRPC_STATUS_FAILED_PRECONDITION: + return "FAILED_PRECONDITION"; + case GRPC_STATUS_ABORTED: + return "ABORTED"; + case GRPC_STATUS_OUT_OF_RANGE: + return "OUT_OF_RANGE"; + case GRPC_STATUS_UNIMPLEMENTED: + return "UNIMPLEMENTED"; + case GRPC_STATUS_INTERNAL: + return "INTERNAL"; + case GRPC_STATUS_UNAVAILABLE: + return "UNAVAILABLE"; + case GRPC_STATUS_DATA_LOSS: + return "DATA_LOSS"; + default: + return "UNKNOWN"; + } +} + +} // namespace grpc_utils +} // namespace otlp +} // namespace exporter + +OPENTELEMETRY_END_NAMESPACE