1 // Copyright 2018, OpenCensus Authors
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
18 "go.opencensus.io/trace"
19 "golang.org/x/net/context"
21 "google.golang.org/grpc/stats"
24 // ClientHandler implements a gRPC stats.Handler for recording OpenCensus stats and
25 // traces. Use with gRPC clients only.
26 type ClientHandler struct {
27 // StartOptions allows configuring the StartOptions used to create new spans.
29 // StartOptions.SpanKind will always be set to trace.SpanKindClient
30 // for spans started by this handler.
31 StartOptions trace.StartOptions
34 // HandleConn exists to satisfy gRPC stats.Handler.
35 func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats) {
39 // TagConn exists to satisfy gRPC stats.Handler.
40 func (c *ClientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context {
45 // HandleRPC implements per-RPC tracing and stats instrumentation.
46 func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
47 traceHandleRPC(ctx, rs)
48 statsHandleRPC(ctx, rs)
51 // TagRPC implements per-RPC context management.
52 func (c *ClientHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context {
53 ctx = c.traceTagRPC(ctx, rti)
54 ctx = c.statsTagRPC(ctx, rti)