Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / go.opencensus.io / plugin / ocgrpc / client_stats_handler.go
1 // Copyright 2017, OpenCensus Authors
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 //
15
16 package ocgrpc
17
18 import (
19         "time"
20
21         "go.opencensus.io/tag"
22         "golang.org/x/net/context"
23         "google.golang.org/grpc/grpclog"
24         "google.golang.org/grpc/stats"
25 )
26
27 // statsTagRPC gets the tag.Map populated by the application code, serializes
28 // its tags into the GRPC metadata in order to be sent to the server.
29 func (h *ClientHandler) statsTagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
30         startTime := time.Now()
31         if info == nil {
32                 if grpclog.V(2) {
33                         grpclog.Infof("clientHandler.TagRPC called with nil info.", info.FullMethodName)
34                 }
35                 return ctx
36         }
37
38         d := &rpcData{
39                 startTime: startTime,
40                 method:    info.FullMethodName,
41         }
42         ts := tag.FromContext(ctx)
43         if ts != nil {
44                 encoded := tag.Encode(ts)
45                 ctx = stats.SetTags(ctx, encoded)
46         }
47
48         return context.WithValue(ctx, rpcDataKey, d)
49 }