From e5020ff8083b52b0fa9d5df76538bd94c4847e0e Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Nov 2022 12:06:14 -0800 Subject: [PATCH 1/8] 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 From af2a905d2b1e01f7e117d56f7bab1aa8cbf84926 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Nov 2022 15:42:27 -0800 Subject: [PATCH 2/8] Fix typo --- exporters/otlp/src/otlp_grpc_exporter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index b3878443e1..5f4cbc99e2 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -64,7 +64,7 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( if (!status.ok()) { - OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] Export() failed with statuc_code: \"" + OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] Export() failed with status_code: \"" << grpc_utils::grpc_status_code_to_string(status.error_code()) << "\" error_message: \"" << status.error_message() << "\""); return sdk::common::ExportResult::kFailure; From 8c68c8d2437ef1856d762f23b960c146277d3f53 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Nov 2022 12:06:14 -0800 Subject: [PATCH 3/8] 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 From a9ba58a6e2a3ca61e47a055e7e989b95380e4d35 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Nov 2022 15:42:27 -0800 Subject: [PATCH 4/8] Fix typo --- exporters/otlp/src/otlp_grpc_exporter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index b3878443e1..5f4cbc99e2 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -64,7 +64,7 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( if (!status.ok()) { - OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] Export() failed with statuc_code: \"" + OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] Export() failed with status_code: \"" << grpc_utils::grpc_status_code_to_string(status.error_code()) << "\" error_message: \"" << status.error_message() << "\""); return sdk::common::ExportResult::kFailure; From 935165f48ebe397aba784b3865a7cb089e1ef5dc Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 23 Nov 2022 16:48:34 -0800 Subject: [PATCH 5/8] Add OTLP grpc utils to bazel BUILD --- exporters/otlp/BUILD | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index d35e46be5c..f36126c96e 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -19,7 +19,6 @@ 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", @@ -27,7 +26,6 @@ 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", @@ -48,6 +46,21 @@ cc_library( ], ) +cc_library( + name = "otlp_grpc_utils", + srcs = [ + "src/otlp_grpc_utils.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", + ], + strip_include_prefix = "include", + tags = ["otlp"], + deps = [ + "@com_github_grpc_grpc//:grpc++", + ], +) + cc_library( name = "otlp_grpc_client", srcs = [ @@ -84,6 +97,7 @@ cc_library( "include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -95,6 +109,7 @@ cc_library( deps = [ ":otlp_recordable", ":otlp_grpc_client", + ":otlp_grpc_utils", "//ext:headers", "//sdk/src/trace", From 3d231a80403953d9561d622691d88afde288599d Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 23 Nov 2022 17:05:41 -0800 Subject: [PATCH 6/8] Add API to otlp_grpc_utils which provides version.h --- exporters/otlp/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index f36126c96e..591c438467 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -57,6 +57,7 @@ cc_library( strip_include_prefix = "include", tags = ["otlp"], deps = [ + "//api", "@com_github_grpc_grpc//:grpc++", ], ) From 2200a529c06c5af2202e8740dfc3ebceecdf6fb5 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 23 Nov 2022 17:23:07 -0800 Subject: [PATCH 7/8] Add SDK headers --- exporters/otlp/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index a6b9af555d..fb3cfa8460 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -57,7 +57,7 @@ cc_library( strip_include_prefix = "include", tags = ["otlp"], deps = [ - "//api", + "//sdk:headers", "@com_github_grpc_grpc//:grpc++", ], ) From c7df675d0687f14275cf9df65e0f159e872950c9 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 23 Nov 2022 17:45:07 -0800 Subject: [PATCH 8/8] Add API headers --- exporters/otlp/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index fb3cfa8460..2aab339e8d 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -57,6 +57,7 @@ cc_library( strip_include_prefix = "include", tags = ["otlp"], deps = [ + "//api", "//sdk:headers", "@com_github_grpc_grpc//:grpc++", ],