...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package ocgrpc
17
18 import (
19 "time"
20
21 "context"
22
23 "go.opencensus.io/tag"
24 "google.golang.org/grpc/grpclog"
25 "google.golang.org/grpc/stats"
26 )
27
28
29
30 func (h *ServerHandler) statsTagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
31 startTime := time.Now()
32 if info == nil {
33 if grpclog.V(2) {
34 grpclog.Infof("opencensus: TagRPC called with nil info.")
35 }
36 return ctx
37 }
38 d := &rpcData{
39 startTime: startTime,
40 method: info.FullMethodName,
41 }
42 propagated := h.extractPropagatedTags(ctx)
43 ctx = tag.NewContext(ctx, propagated)
44 ctx, _ = tag.New(ctx, tag.Upsert(KeyServerMethod, methodName(info.FullMethodName)))
45 return context.WithValue(ctx, rpcDataKey, d)
46 }
47
48
49
50 func (h *ServerHandler) extractPropagatedTags(ctx context.Context) *tag.Map {
51 buf := stats.Tags(ctx)
52 if buf == nil {
53 return nil
54 }
55 propagated, err := tag.Decode(buf)
56 if err != nil {
57 if grpclog.V(2) {
58 grpclog.Warningf("opencensus: Failed to decode tags from gRPC metadata failed to decode: %v", err)
59 }
60 return nil
61 }
62 return propagated
63 }
64
View as plain text