|
31 | 31 |
|
32 | 32 | namespace grpc { |
33 | 33 |
|
| 34 | +void RegisterOpenCensusPlugin() { |
| 35 | + RegisterChannelFilter<CensusChannelData, CensusClientCallData>( |
| 36 | + "opencensus_client", GRPC_CLIENT_CHANNEL, INT_MAX /* priority */, |
| 37 | + nullptr /* condition function */); |
| 38 | + RegisterChannelFilter<CensusChannelData, CensusServerCallData>( |
| 39 | + "opencensus_server", GRPC_SERVER_CHANNEL, INT_MAX /* priority */, |
| 40 | + nullptr /* condition function */); |
| 41 | + |
| 42 | + // Access measures to ensure they are initialized. Otherwise, creating a view |
| 43 | + // before the first RPC would cause an error. |
| 44 | + RpcClientSentBytesPerRpc(); |
| 45 | + RpcClientReceivedBytesPerRpc(); |
| 46 | + RpcClientRoundtripLatency(); |
| 47 | + RpcClientServerLatency(); |
| 48 | + RpcClientSentMessagesPerRpc(); |
| 49 | + RpcClientReceivedMessagesPerRpc(); |
| 50 | + |
| 51 | + RpcServerSentBytesPerRpc(); |
| 52 | + RpcServerReceivedBytesPerRpc(); |
| 53 | + RpcServerServerLatency(); |
| 54 | + RpcServerSentMessagesPerRpc(); |
| 55 | + RpcServerReceivedMessagesPerRpc(); |
| 56 | +} |
| 57 | + |
| 58 | +::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context) { |
| 59 | + return reinterpret_cast<const CensusContext*>(context->census_context()) |
| 60 | + ->Span(); |
| 61 | +} |
| 62 | + |
34 | 63 | // These measure definitions should be kept in sync across opencensus |
35 | 64 | // implementations--see |
36 | 65 | // https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java. |
@@ -98,39 +127,5 @@ ABSL_CONST_INIT const absl::string_view |
98 | 127 |
|
99 | 128 | ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName = |
100 | 129 | "grpc.io/server/server_latency"; |
101 | | -} // namespace grpc |
102 | | -namespace grpc_impl { |
103 | 130 |
|
104 | | -void RegisterOpenCensusPlugin() { |
105 | | - grpc::RegisterChannelFilter<grpc::CensusChannelData, |
106 | | - grpc::CensusClientCallData>( |
107 | | - "opencensus_client", GRPC_CLIENT_CHANNEL, INT_MAX /* priority */, |
108 | | - nullptr /* condition function */); |
109 | | - grpc::RegisterChannelFilter<grpc::CensusChannelData, |
110 | | - grpc::CensusServerCallData>( |
111 | | - "opencensus_server", GRPC_SERVER_CHANNEL, INT_MAX /* priority */, |
112 | | - nullptr /* condition function */); |
113 | | - |
114 | | - // Access measures to ensure they are initialized. Otherwise, creating a view |
115 | | - // before the first RPC would cause an error. |
116 | | - grpc::RpcClientSentBytesPerRpc(); |
117 | | - grpc::RpcClientReceivedBytesPerRpc(); |
118 | | - grpc::RpcClientRoundtripLatency(); |
119 | | - grpc::RpcClientServerLatency(); |
120 | | - grpc::RpcClientSentMessagesPerRpc(); |
121 | | - grpc::RpcClientReceivedMessagesPerRpc(); |
122 | | - |
123 | | - grpc::RpcServerSentBytesPerRpc(); |
124 | | - grpc::RpcServerReceivedBytesPerRpc(); |
125 | | - grpc::RpcServerServerLatency(); |
126 | | - grpc::RpcServerSentMessagesPerRpc(); |
127 | | - grpc::RpcServerReceivedMessagesPerRpc(); |
128 | | -} |
129 | | - |
130 | | -::opencensus::trace::Span GetSpanFromServerContext( |
131 | | - grpc::ServerContext* context) { |
132 | | - return reinterpret_cast<const grpc::CensusContext*>(context->census_context()) |
133 | | - ->Span(); |
134 | | -} |
135 | | - |
136 | | -} // namespace grpc_impl |
| 131 | +} // namespace grpc |
0 commit comments