[OTel C++] OTel plugin improvements (#34441)

Changes -
* Use `grpc-c++` as the meter name and the proper version string when
creating the meter for OTel
* setting metric description and unit. (Pointed out by @DNVindhya )
create-pull-request/patch-5c8858f
Yash Tibrewal 1 year ago committed by GitHub
parent c6b4952d74
commit d491fc5993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/cpp/ext/otel/BUILD
  2. 45
      src/cpp/ext/otel/otel_plugin.cc

@ -62,6 +62,7 @@ grpc_cc_library(
"//:config",
"//:gpr",
"//:gpr_platform",
"//:grpc++",
"//:grpc_base",
"//:grpc_client_channel",
"//:grpc_public_hdrs",

@ -31,6 +31,7 @@
#include "opentelemetry/nostd/unique_ptr.h"
#include <grpc/support/log.h>
#include <grpcpp/version_info.h>
#include "src/core/ext/filters/client_channel/client_channel.h"
#include "src/core/lib/channel/call_tracer.h"
@ -175,47 +176,61 @@ void OpenTelemetryPluginBuilder::BuildAndRegisterGlobal() {
if (meter_provider == nullptr) {
return;
}
auto meter = meter_provider->GetMeter("grpc");
auto meter = meter_provider->GetMeter("grpc-c++", GRPC_CPP_VERSION_STRING);
if (metrics_.contains(OTelClientAttemptStartedInstrumentName())) {
g_otel_plugin_state_->client.attempt.started = meter->CreateUInt64Counter(
std::string(OTelClientAttemptStartedInstrumentName()));
std::string(OTelClientAttemptStartedInstrumentName()),
"Number of client call attempts started", "{attempt}");
}
if (metrics_.contains(OTelClientAttemptDurationInstrumentName())) {
g_otel_plugin_state_->client.attempt.duration =
meter->CreateDoubleHistogram(
std::string(OTelClientAttemptDurationInstrumentName()));
std::string(OTelClientAttemptDurationInstrumentName()),
"End-to-end time taken to complete a client call attempt", "s");
}
if (metrics_.contains(
OTelClientAttemptSentTotalCompressedMessageSizeInstrumentName())) {
g_otel_plugin_state_->client.attempt.sent_total_compressed_message_size =
meter->CreateUInt64Histogram(std::string(
OTelClientAttemptSentTotalCompressedMessageSizeInstrumentName()));
g_otel_plugin_state_->client.attempt
.sent_total_compressed_message_size = meter->CreateUInt64Histogram(
std::string(
OTelClientAttemptSentTotalCompressedMessageSizeInstrumentName()),
"Compressed message bytes sent per client call attempt", "By");
}
if (metrics_.contains(
OTelClientAttemptRcvdTotalCompressedMessageSizeInstrumentName())) {
g_otel_plugin_state_->client.attempt.rcvd_total_compressed_message_size =
meter->CreateUInt64Histogram(std::string(
OTelClientAttemptRcvdTotalCompressedMessageSizeInstrumentName()));
g_otel_plugin_state_->client.attempt
.rcvd_total_compressed_message_size = meter->CreateUInt64Histogram(
std::string(
OTelClientAttemptRcvdTotalCompressedMessageSizeInstrumentName()),
"Compressed message bytes received per call attempt", "By");
}
if (metrics_.contains(OTelServerCallStartedInstrumentName())) {
g_otel_plugin_state_->server.call.started = meter->CreateUInt64Counter(
std::string(OTelServerCallStartedInstrumentName()));
std::string(OTelServerCallStartedInstrumentName()),
"Number of server calls started", "{call}");
}
if (metrics_.contains(OTelServerCallDurationInstrumentName())) {
g_otel_plugin_state_->server.call.duration = meter->CreateDoubleHistogram(
std::string(OTelServerCallDurationInstrumentName()));
std::string(OTelServerCallDurationInstrumentName()),
"End-to-end time taken to complete a call from server transport's "
"perspective",
"s");
}
if (metrics_.contains(
OTelServerCallSentTotalCompressedMessageSizeInstrumentName())) {
g_otel_plugin_state_->server.call.sent_total_compressed_message_size =
meter->CreateUInt64Histogram(std::string(
OTelServerCallSentTotalCompressedMessageSizeInstrumentName()));
meter->CreateUInt64Histogram(
std::string(
OTelServerCallSentTotalCompressedMessageSizeInstrumentName()),
"Compressed message bytes sent per server call", "By");
}
if (metrics_.contains(
OTelServerCallRcvdTotalCompressedMessageSizeInstrumentName())) {
g_otel_plugin_state_->server.call.rcvd_total_compressed_message_size =
meter->CreateUInt64Histogram(std::string(
OTelServerCallRcvdTotalCompressedMessageSizeInstrumentName()));
meter->CreateUInt64Histogram(
std::string(
OTelServerCallRcvdTotalCompressedMessageSizeInstrumentName()),
"Compressed message bytes received per server call", "By");
}
g_otel_plugin_state_->labels_injector = std::move(labels_injector_);
g_otel_plugin_state_->target_attribute_filter =

Loading…
Cancel
Save