Add method to add annotations to call tracer (#31901)

pull/31900/head
Yash Tibrewal 2 years ago committed by GitHub
parent 149fc38356
commit 6a97f492ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      include/grpcpp/opencensus.h
  2. 8
      src/core/lib/channel/call_tracer.h
  3. 9
      src/cpp/ext/filters/census/client_filter.cc
  4. 2
      src/cpp/ext/filters/census/open_census_call_tracer.h

@ -186,6 +186,11 @@ class CensusContext {
span_.AddAttribute(key, attribute); span_.AddAttribute(key, attribute);
} }
void AddSpanAnnotation(absl::string_view description,
opencensus::trace::AttributesRef attributes) {
span_.AddAnnotation(description, attributes);
}
const ::opencensus::trace::Span& Span() const { return span_; } const ::opencensus::trace::Span& Span() const { return span_; }
const ::opencensus::tags::TagMap& tags() const { return tags_; } const ::opencensus::tags::TagMap& tags() const { return tags_; }

@ -75,6 +75,10 @@ class CallTracer {
// Should be the last API call to the object. Once invoked, the tracer // Should be the last API call to the object. Once invoked, the tracer
// library is free to destroy the object. // library is free to destroy the object.
virtual void RecordEnd(const gpr_timespec& latency) = 0; virtual void RecordEnd(const gpr_timespec& latency) = 0;
// Records an annotation on the call attempt.
// TODO(yashykt): If needed, extend this to attach attributes with
// annotations.
virtual void RecordAnnotation(absl::string_view annotation) = 0;
}; };
virtual ~CallTracer() {} virtual ~CallTracer() {}
@ -87,6 +91,10 @@ class CallTracer {
// serves as an indication that the call stack is done with all API calls, and // serves as an indication that the call stack is done with all API calls, and
// the tracer library is free to destroy it after that. // the tracer library is free to destroy it after that.
virtual CallAttemptTracer* StartNewAttempt(bool is_transparent_retry) = 0; virtual CallAttemptTracer* StartNewAttempt(bool is_transparent_retry) = 0;
// Records an annotation on the call attempt.
// TODO(yashykt): If needed, extend this to attach attributes with
// annotations.
virtual void RecordAnnotation(absl::string_view annotation) = 0;
}; };
} // namespace grpc_core } // namespace grpc_core

@ -246,6 +246,11 @@ void OpenCensusCallTracer::OpenCensusCallAttemptTracer::RecordEnd(
} }
} }
void OpenCensusCallTracer::OpenCensusCallAttemptTracer::RecordAnnotation(
absl::string_view annotation) {
context_.AddSpanAnnotation(annotation, {});
}
// //
// OpenCensusCallTracer // OpenCensusCallTracer
// //
@ -312,6 +317,10 @@ OpenCensusCallTracer::StartNewAttempt(bool is_transparent_retry) {
this, attempt_num, is_transparent_retry, false /* arena_allocated */); this, attempt_num, is_transparent_retry, false /* arena_allocated */);
} }
void OpenCensusCallTracer::RecordAnnotation(absl::string_view annotation) {
context_.AddSpanAnnotation(annotation, {});
}
CensusContext OpenCensusCallTracer::CreateCensusContextForCallAttempt() { CensusContext OpenCensusCallTracer::CreateCensusContextForCallAttempt() {
if (!OpenCensusTracingEnabled() || !tracing_enabled_) return CensusContext(); if (!OpenCensusTracingEnabled() || !tracing_enabled_) return CensusContext();
GPR_DEBUG_ASSERT(context_.Context().IsValid()); GPR_DEBUG_ASSERT(context_.Context().IsValid());

@ -81,6 +81,7 @@ class OpenCensusCallTracer : public grpc_core::CallTracer {
const grpc_transport_stream_stats* transport_stream_stats) override; const grpc_transport_stream_stats* transport_stream_stats) override;
void RecordCancel(grpc_error_handle cancel_error) override; void RecordCancel(grpc_error_handle cancel_error) override;
void RecordEnd(const gpr_timespec& /*latency*/) override; void RecordEnd(const gpr_timespec& /*latency*/) override;
void RecordAnnotation(absl::string_view annotation) override;
experimental::CensusContext* context() { return &context_; } experimental::CensusContext* context() { return &context_; }
@ -108,6 +109,7 @@ class OpenCensusCallTracer : public grpc_core::CallTracer {
void GenerateContext(); void GenerateContext();
OpenCensusCallAttemptTracer* StartNewAttempt( OpenCensusCallAttemptTracer* StartNewAttempt(
bool is_transparent_retry) override; bool is_transparent_retry) override;
void RecordAnnotation(absl::string_view annotation) override;
private: private:
experimental::CensusContext CreateCensusContextForCallAttempt(); experimental::CensusContext CreateCensusContextForCallAttempt();

Loading…
Cancel
Save