Skip to content

Commit cc40172

Browse files
authored
Merge pull request grpc#22247 from karthikravis/move-opencensus-to-grpc
Revert "Revert "Revert "Fold opencensus into grpc_impl namespace"""
2 parents c134909 + 7c2b70d commit cc40172

File tree

5 files changed

+68
-111
lines changed

5 files changed

+68
-111
lines changed

BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,6 @@ grpc_cc_library(
23222322
],
23232323
hdrs = [
23242324
"include/grpcpp/opencensus.h",
2325-
"include/grpcpp/opencensus_impl.h",
23262325
"src/cpp/ext/filters/census/channel_filter.h",
23272326
"src/cpp/ext/filters/census/client_filter.h",
23282327
"src/cpp/ext/filters/census/context.h",

include/grpcpp/opencensus.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@
1919
#ifndef GRPCPP_OPENCENSUS_H
2020
#define GRPCPP_OPENCENSUS_H
2121

22-
#include "grpcpp/opencensus_impl.h"
22+
#include "opencensus/trace/span.h"
23+
24+
namespace grpc_impl {
25+
class ServerContext;
26+
}
2327

2428
namespace grpc {
29+
// These symbols in this file will not be included in the binary unless
30+
// grpc_opencensus_plugin build target was added as a dependency. At the moment
31+
// it is only setup to be built with Bazel.
2532

26-
static inline void RegisterOpenCensusPlugin() {
27-
::grpc_impl::RegisterOpenCensusPlugin();
28-
}
29-
static inline void RegisterOpenCensusViewsForExport() {
30-
::grpc_impl::RegisterOpenCensusViewsForExport();
31-
}
32-
static inline ::opencensus::trace::Span GetSpanFromServerContext(
33-
::grpc_impl::ServerContext* context) {
34-
return ::grpc_impl::GetSpanFromServerContext(context);
35-
}
33+
// Registers the OpenCensus plugin with gRPC, so that it will be used for future
34+
// RPCs. This must be called before any views are created.
35+
void RegisterOpenCensusPlugin();
36+
37+
// RPC stats definitions, defined by
38+
// https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md
39+
40+
// Registers the cumulative gRPC views so that they will be exported by any
41+
// registered stats exporter. For on-task stats, construct a View using the
42+
// ViewDescriptors below.
43+
void RegisterOpenCensusViewsForExport();
44+
45+
// Returns the tracing Span for the current RPC.
46+
::opencensus::trace::Span GetSpanFromServerContext(
47+
::grpc_impl::ServerContext* context);
3648

3749
} // namespace grpc
3850

include/grpcpp/opencensus_impl.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/cpp/ext/filters/census/grpc_plugin.cc

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@
3131

3232
namespace grpc {
3333

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+
3463
// These measure definitions should be kept in sync across opencensus
3564
// implementations--see
3665
// 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
98127

99128
ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName =
100129
"grpc.io/server/server_latency";
101-
} // namespace grpc
102-
namespace grpc_impl {
103130

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

src/cpp/ext/filters/census/views.cc

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,6 @@
2525
#include "opencensus/stats/internal/set_aggregation_window.h"
2626
#include "opencensus/stats/stats.h"
2727

28-
namespace grpc_impl {
29-
30-
void RegisterOpenCensusViewsForExport() {
31-
grpc::ClientSentMessagesPerRpcCumulative().RegisterForExport();
32-
grpc::ClientSentBytesPerRpcCumulative().RegisterForExport();
33-
grpc::ClientReceivedMessagesPerRpcCumulative().RegisterForExport();
34-
grpc::ClientReceivedBytesPerRpcCumulative().RegisterForExport();
35-
grpc::ClientRoundtripLatencyCumulative().RegisterForExport();
36-
grpc::ClientServerLatencyCumulative().RegisterForExport();
37-
38-
grpc::ServerSentMessagesPerRpcCumulative().RegisterForExport();
39-
grpc::ServerSentBytesPerRpcCumulative().RegisterForExport();
40-
grpc::ServerReceivedMessagesPerRpcCumulative().RegisterForExport();
41-
grpc::ServerReceivedBytesPerRpcCumulative().RegisterForExport();
42-
grpc::ServerServerLatencyCumulative().RegisterForExport();
43-
}
44-
} // namespace grpc_impl
4528
namespace grpc {
4629

4730
using ::opencensus::stats::Aggregation;
@@ -88,6 +71,21 @@ ViewDescriptor HourDescriptor() {
8871

8972
} // namespace
9073

74+
void RegisterOpenCensusViewsForExport() {
75+
ClientSentMessagesPerRpcCumulative().RegisterForExport();
76+
ClientSentBytesPerRpcCumulative().RegisterForExport();
77+
ClientReceivedMessagesPerRpcCumulative().RegisterForExport();
78+
ClientReceivedBytesPerRpcCumulative().RegisterForExport();
79+
ClientRoundtripLatencyCumulative().RegisterForExport();
80+
ClientServerLatencyCumulative().RegisterForExport();
81+
82+
ServerSentMessagesPerRpcCumulative().RegisterForExport();
83+
ServerSentBytesPerRpcCumulative().RegisterForExport();
84+
ServerReceivedMessagesPerRpcCumulative().RegisterForExport();
85+
ServerReceivedBytesPerRpcCumulative().RegisterForExport();
86+
ServerServerLatencyCumulative().RegisterForExport();
87+
}
88+
9189
// client cumulative
9290
const ViewDescriptor& ClientSentBytesPerRpcCumulative() {
9391
const static ViewDescriptor descriptor =

0 commit comments

Comments
 (0)