Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions google/cloud/internal/grpc_opentelemetry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> MakeSpanGrpc(
namespace sc = opentelemetry::semconv;
opentelemetry::trace::StartSpanOptions options;
options.kind = opentelemetry::trace::SpanKind::kClient;
return internal::MakeSpan(
// OpenTelemetry RPC semantic conventions specify that `rpc.method` should
// be the fully-qualified logical name (e.g. "<service>/<method>") and that
// `rpc.service` is deprecated in favor of it.
// https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/
auto fully_qualified_method =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, auto should not be used when it obscures function return types. Since absl::StrCat returns a std::string, please declare the variable with an explicit std::string type.

  std::string fully_qualified_method =
References
  1. Reject auto when it hides function return types. (link)

absl::StrCat(absl::string_view{service.data(), service.size()}, "/",
absl::string_view{method.data(), method.size()}),
{{sc::rpc::kRpcSystem, sc::rpc::RpcSystemValues::kGrpc},
{sc::rpc::kRpcService, service},
{sc::rpc::kRpcMethod, method},
absl::string_view{method.data(), method.size()});
return internal::MakeSpan(
fully_qualified_method,
{{sc::rpc::kRpcSystemName, sc::rpc::RpcSystemNameValues::kGrpc},
{sc::rpc::kRpcMethod, fully_qualified_method},
{/*sc::kNetworkTransport=*/"network.transport",
sc::network::NetworkTransportValues::kTcp},
{"grpc.version", grpc::Version()}},
Expand Down
9 changes: 4 additions & 5 deletions google/cloud/internal/grpc_opentelemetry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ TEST(OpenTelemetry, MakeSpanGrpc) {
SpanHasInstrumentationScope(), SpanKindIsClient(),
SpanNamed("google.cloud.foo.v1.Foo/GetBar"),
SpanHasAttributes(
OTelAttribute<std::string>(sc::rpc::kRpcSystem,
sc::rpc::RpcSystemValues::kGrpc),
OTelAttribute<std::string>(sc::rpc::kRpcService,
"google.cloud.foo.v1.Foo"),
OTelAttribute<std::string>(sc::rpc::kRpcMethod, "GetBar"),
OTelAttribute<std::string>(sc::rpc::kRpcSystemName,
sc::rpc::RpcSystemNameValues::kGrpc),
OTelAttribute<std::string>(sc::rpc::kRpcMethod,
"google.cloud.foo.v1.Foo/GetBar"),
OTelAttribute<std::string>(
/*sc::kNetworkTransport=*/"network.transport",
sc::network::NetworkTransportValues::kTcp),
Expand Down
Loading