[observability] Update Python calltracer implementation (#33899)

revert-33442-printExp
Alisha Nanda 2 years ago committed by GitHub
parent 0897f0faf3
commit 15bb1267c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      src/python/grpcio_observability/grpc_observability/client_call_tracer.cc
  2. 2
      src/python/grpcio_observability/grpc_observability/client_call_tracer.h
  3. 14
      src/python/grpcio_observability/grpc_observability/server_call_tracer.cc

@ -56,10 +56,24 @@ void PythonOpenCensusCallTracer::GenerateContext() {}
void PythonOpenCensusCallTracer::RecordAnnotation(
absl::string_view annotation) {
// If tracing is disabled, the following will be a no-op.
if (!context_.SpanContext().IsSampled()) {
return;
}
context_.AddSpanAnnotation(annotation);
}
void PythonOpenCensusCallTracer::RecordAnnotation(
const Annotation& annotation) {
if (!context_.SpanContext().IsSampled()) {
return;
}
switch (annotation.type()) {
default:
context_.AddSpanAnnotation(annotation.ToString());
}
}
PythonOpenCensusCallTracer::~PythonOpenCensusCallTracer() {
if (PythonCensusStatsEnabled()) {
context_.Labels().emplace_back(kClientMethod, std::string(method_));
@ -275,8 +289,22 @@ void PythonOpenCensusCallTracer::PythonOpenCensusCallAttemptTracer::RecordEnd(
void PythonOpenCensusCallTracer::PythonOpenCensusCallAttemptTracer::
RecordAnnotation(absl::string_view annotation) {
// If tracing is disabled, the following will be a no-op.
if (!context_.SpanContext().IsSampled()) {
return;
}
context_.AddSpanAnnotation(annotation);
}
void PythonOpenCensusCallTracer::PythonOpenCensusCallAttemptTracer::
RecordAnnotation(const Annotation& annotation) {
if (!context_.SpanContext().IsSampled()) {
return;
}
switch (annotation.type()) {
default:
context_.AddSpanAnnotation(annotation.ToString());
}
}
} // namespace grpc_observability

@ -76,6 +76,7 @@ class PythonOpenCensusCallTracer : public grpc_core::ClientCallTracer {
void RecordCancel(grpc_error_handle cancel_error) override;
void RecordEnd(const gpr_timespec& /*latency*/) override;
void RecordAnnotation(absl::string_view annotation) override;
void RecordAnnotation(const Annotation& annotation) override;
private:
// Maximum size of trace context is sent on the wire.
@ -115,6 +116,7 @@ class PythonOpenCensusCallTracer : public grpc_core::ClientCallTracer {
bool is_transparent_retry) override;
void RecordAnnotation(absl::string_view annotation) override;
void RecordAnnotation(const Annotation& annotation) override;
private:
PythonCensusContext CreateCensusContextForCallAttempt();

@ -150,9 +150,23 @@ class PythonOpenCensusServerCallTracer : public grpc_core::ServerCallTracer {
void RecordEnd(const grpc_call_final_info* final_info) override;
void RecordAnnotation(absl::string_view annotation) override {
if (!context_.SpanContext().IsSampled()) {
return;
}
context_.AddSpanAnnotation(annotation);
}
void RecordAnnotation(const Annotation& annotation) override {
if (!context_.SpanContext().IsSampled()) {
return;
}
switch (annotation.type()) {
default:
context_.AddSpanAnnotation(annotation.ToString());
}
}
private:
PythonCensusContext context_;
// server method

Loading…
Cancel
Save