2525#include " examples/grpc/exporters.h"
2626#include " examples/grpc/hello.grpc.pb.h"
2727#include " examples/grpc/hello.pb.h"
28+ #include " opencensus/stats/aggregation.h"
29+ #include " opencensus/stats/bucket_boundaries.h"
30+ #include " opencensus/stats/view_descriptor.h"
2831#include " opencensus/tags/context_util.h"
2932#include " opencensus/tags/tag_key.h"
3033#include " opencensus/tags/tag_map.h"
@@ -40,6 +43,32 @@ using examples::HelloReply;
4043using examples::HelloRequest;
4144using examples::HelloService;
4245
46+ opencensus::tags::TagKey MyKey () {
47+ static const auto key = opencensus::tags::TagKey::Register (" my_key" );
48+ return key;
49+ }
50+
51+ opencensus::stats::Aggregation MillisDistributionAggregation () {
52+ return opencensus::stats::Aggregation::Distribution (
53+ opencensus::stats::BucketBoundaries::Explicit (
54+ {0 , 0.1 , 1 , 10 , 100 , 1000 }));
55+ }
56+
57+ ABSL_CONST_INIT const absl::string_view kRpcClientRoundtripLatencyMeasureName =
58+ " grpc.io/client/roundtrip_latency" ;
59+
60+ ::opencensus::tags::TagKey ClientMethodTagKey () {
61+ static const auto method_tag_key =
62+ ::opencensus::tags::TagKey::Register (" grpc_client_method" );
63+ return method_tag_key;
64+ }
65+
66+ ::opencensus::tags::TagKey ClientStatusTagKey () {
67+ static const auto status_tag_key =
68+ ::opencensus::tags::TagKey::Register (" grpc_client_status" );
69+ return status_tag_key;
70+ }
71+
4372} // namespace
4473
4574int main (int argc, char **argv) {
@@ -56,6 +85,16 @@ int main(int argc, char **argv) {
5685 // Register the OpenCensus gRPC plugin to enable stats and tracing in gRPC.
5786 grpc::RegisterOpenCensusPlugin ();
5887
88+ // Add a view of client RPC latency broken down by our custom key.
89+ opencensus::stats::ViewDescriptor ()
90+ .set_name (" example/client/roundtrip_latency/cumulative" )
91+ .set_measure (kRpcClientRoundtripLatencyMeasureName )
92+ .set_aggregation (MillisDistributionAggregation ())
93+ .add_column (ClientMethodTagKey ())
94+ .add_column (ClientStatusTagKey ())
95+ .add_column (MyKey ())
96+ .RegisterForExport ();
97+
5998 RegisterExporters ();
6099
61100 // Create a Channel to send RPCs over.
0 commit comments