| 1 |
// |
| 2 |
// |
| 3 |
// Copyright 2021 gRPC authors. |
| 4 |
// |
| 5 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
// you may not use this file except in compliance with the License. |
| 7 |
// You may obtain a copy of the License at |
| 8 |
// |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
// |
| 11 |
// Unless required by applicable law or agreed to in writing, software |
| 12 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
// See the License for the specific language governing permissions and |
| 15 |
// limitations under the License. |
| 16 |
// |
| 17 |
// |
| 18 |
|
| 19 |
#ifndef GRPC_CORE_LIB_CHANNEL_CALL_TRACER_H |
| 20 |
#define GRPC_CORE_LIB_CHANNEL_CALL_TRACER_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include <stdint.h> |
| 25 |
|
| 26 |
#include "absl/status/status.h" |
| 27 |
|
| 28 |
#include <grpc/impl/codegen/gpr_types.h> |
| 29 |
#include <grpc/support/atm.h> |
| 30 |
|
| 31 |
#include "src/core/lib/iomgr/error.h" |
| 32 |
#include "src/core/lib/slice/slice_buffer.h" |
| 33 |
#include "src/core/lib/transport/metadata_batch.h" |
| 34 |
#include "src/core/lib/transport/transport.h" |
| 35 |
|
| 36 |
namespace grpc_core { |
| 37 |
|
| 38 |
// Interface for a tracer that records activities on a call. Actual attempts for |
| 39 |
// this call are traced with CallAttemptTracer after invoking RecordNewAttempt() |
| 40 |
// on the CallTracer object. |
| 41 |
class CallTracer { |
| 42 |
public: |
| 43 |
// Interface for a tracer that records activities on a particular call |
| 44 |
// attempt. |
| 45 |
// (A single RPC can have multiple attempts due to retry/hedging policies or |
| 46 |
// as transparent retry attempts.) |
| 47 |
class CallAttemptTracer { |
| 48 |
public: |
| 49 |
virtual ~CallAttemptTracer() {} |
| 50 |
// Please refer to `grpc_transport_stream_op_batch_payload` for details on |
| 51 |
// arguments. |
| 52 |
virtual void RecordSendInitialMetadata( |
| 53 |
grpc_metadata_batch* send_initial_metadata) = 0; |
| 54 |
// TODO(yashkt): We are using gpr_atm here instead of absl::string_view |
| 55 |
// since that's what the transport API uses, and performing an atomic load |
| 56 |
// is unnecessary if the census tracer does not need it at present. Fix this |
| 57 |
// when the transport API changes. |
| 58 |
virtual void RecordOnDoneSendInitialMetadata(gpr_atm* peer_string) = 0; |
| 59 |
virtual void RecordSendTrailingMetadata( |
| 60 |
grpc_metadata_batch* send_trailing_metadata) = 0; |
| 61 |
virtual void RecordSendMessage(const SliceBuffer& send_message) = 0; |
| 62 |
// The `RecordReceivedInitialMetadata()` and `RecordReceivedMessage()` |
| 63 |
// methods should only be invoked when the metadata/message was |
| 64 |
// successfully received, i.e., without any error. |
| 65 |
virtual void RecordReceivedInitialMetadata( |
| 66 |
grpc_metadata_batch* recv_initial_metadata, uint32_t flags) = 0; |
| 67 |
virtual void RecordReceivedMessage(const SliceBuffer& recv_message) = 0; |
| 68 |
// If the call was cancelled before the recv_trailing_metadata op |
| 69 |
// was started, recv_trailing_metadata and transport_stream_stats |
| 70 |
// will be null. |
| 71 |
virtual void RecordReceivedTrailingMetadata( |
| 72 |
absl::Status status, grpc_metadata_batch* recv_trailing_metadata, |
| 73 |
const grpc_transport_stream_stats* transport_stream_stats) = 0; |
| 74 |
virtual void RecordCancel(grpc_error_handle cancel_error) = 0; |
| 75 |
// Should be the last API call to the object. Once invoked, the tracer |
| 76 |
// library is free to destroy the object. |
| 77 |
virtual void RecordEnd(const gpr_timespec& latency) = 0; |
| 78 |
}; |
| 79 |
|
| 80 |
virtual ~CallTracer() {} |
| 81 |
|
| 82 |
// Records a new attempt for the associated call. \a transparent denotes |
| 83 |
// whether the attempt is being made as a transparent retry or as a |
| 84 |
// non-transparent retry/heding attempt. (There will be at least one attempt |
| 85 |
// even if the call is not being retried.) The `CallTracer` object retains |
| 86 |
// ownership to the newly created `CallAttemptTracer` object. RecordEnd() |
| 87 |
// serves as an indication that the call stack is done with all API calls, and |
| 88 |
// the tracer library is free to destroy it after that. |
| 89 |
virtual CallAttemptTracer* StartNewAttempt(bool is_transparent_retry) = 0; |
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace grpc_core |
| 93 |
|
| 94 |
#endif // GRPC_CORE_LIB_CHANNEL_CALL_TRACER_H |