[tracing] Only set tracers to stream when sampled. (#34870)

Generating an annotation is often expensive, there's no need to annotate
when not sampled.




<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/34896/head
Yousuk Seung 1 year ago committed by GitHub
parent d77e5c0dd3
commit 52c08f4498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc

@ -229,30 +229,33 @@ static void send_goaway(grpc_chttp2_transport* t, grpc_error_handle error,
#define GRPC_ARG_SETTINGS_TIMEOUT "grpc.http2.settings_timeout"
namespace {
grpc_core::CallTracerInterface* CallTracerIfEnabled(grpc_chttp2_stream* s) {
grpc_core::CallTracerInterface* CallTracerIfSampled(grpc_chttp2_stream* s) {
if (s->context == nullptr || !grpc_core::IsTraceRecordCallopsEnabled()) {
return nullptr;
}
return static_cast<grpc_core::CallTracerInterface*>(
auto* call_tracer = static_cast<grpc_core::CallTracerInterface*>(
static_cast<grpc_call_context_element*>(
s->context)[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE]
.value);
if (call_tracer == nullptr || !call_tracer->IsSampled()) {
return nullptr;
}
return call_tracer;
}
std::shared_ptr<grpc_core::TcpTracerInterface> TcpTracerIfEnabled(
std::shared_ptr<grpc_core::TcpTracerInterface> TcpTracerIfSampled(
grpc_chttp2_stream* s) {
if (s->context == nullptr || !s->traced ||
!grpc_core::IsTraceRecordCallopsEnabled()) {
if (s->context == nullptr || !grpc_core::IsTraceRecordCallopsEnabled()) {
return nullptr;
}
auto* call_tracer = static_cast<grpc_core::CallTracerInterface*>(
auto* call_attempt_tracer = static_cast<grpc_core::CallTracerInterface*>(
static_cast<grpc_call_context_element*>(
s->context)[GRPC_CONTEXT_CALL_TRACER]
.value);
if (!call_tracer) {
if (call_attempt_tracer == nullptr || !call_attempt_tracer->IsSampled()) {
return nullptr;
}
return call_tracer->StartNewTcpTrace();
return call_attempt_tracer->StartNewTcpTrace();
}
grpc_core::WriteTimestampsCallback g_write_timestamps_callback = nullptr;
@ -1471,8 +1474,8 @@ static void perform_stream_op_locked(void* stream_op,
s->context = op->payload->context;
s->traced = op->is_traced;
s->call_tracer = CallTracerIfEnabled(s);
s->tcp_tracer = TcpTracerIfEnabled(s);
s->call_tracer = CallTracerIfSampled(s);
s->tcp_tracer = TcpTracerIfSampled(s);
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_INFO,
"perform_stream_op_locked[s=%p; op=%p]: %s; on_complete = %p", s,

Loading…
Cancel
Save