@@ -67,7 +67,7 @@ const traceContextKey = "grpc-trace-bin"
67
67
// SpanContext added to the outgoing gRPC metadata.
68
68
func (c * ClientStatsHandler ) TagRPC (ctx context.Context , rti * stats.RPCTagInfo ) context.Context {
69
69
name := "Sent" + strings .Replace (rti .FullMethodName , "/" , "." , - 1 )
70
- ctx = trace .StartSpanWithOptions (ctx , name , trace.StartSpanOptions {RecordEvents : true , RegisterNameForLocalSpanStore : true })
70
+ ctx , _ = trace .StartSpanWithOptions (ctx , name , trace.StartOptions {RecordEvents : true , RegisterNameForLocalSpanStore : true })
71
71
traceContextBinary := propagation .Binary (trace .FromContext (ctx ).SpanContext ())
72
72
if len (traceContextBinary ) == 0 {
73
73
return ctx
@@ -88,13 +88,15 @@ func (c *ClientStatsHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo)
88
88
func (s * ServerStatsHandler ) TagRPC (ctx context.Context , rti * stats.RPCTagInfo ) context.Context {
89
89
md , _ := metadata .FromIncomingContext (ctx )
90
90
name := "Recv" + strings .Replace (rti .FullMethodName , "/" , "." , - 1 )
91
- opt := trace.StartSpanOptions {RecordEvents : true , RegisterNameForLocalSpanStore : true }
91
+ opt := trace.StartOptions {RecordEvents : true , RegisterNameForLocalSpanStore : true }
92
92
if s := md [traceContextKey ]; len (s ) > 0 {
93
93
if parent , ok := propagation .FromBinary ([]byte (s [0 ])); ok {
94
- return trace .StartSpanWithRemoteParent (ctx , name , parent , opt )
94
+ ctx , _ = trace .StartSpanWithRemoteParent (ctx , name , parent , opt )
95
+ return ctx
95
96
}
96
97
}
97
- return trace .StartSpanWithOptions (ctx , name , opt )
98
+ ctx , _ = trace .StartSpanWithOptions (ctx , name , opt )
99
+ return ctx
98
100
}
99
101
100
102
// HandleRPC processes the RPC stats, adding information to the current trace span.
@@ -108,30 +110,31 @@ func (s *ServerStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
108
110
}
109
111
110
112
func handleRPC (ctx context.Context , rs stats.RPCStats ) {
113
+ span := trace .FromContext (ctx )
111
114
// TODO: compressed and uncompressed sizes are not populated in every message.
112
115
switch rs := rs .(type ) {
113
116
case * stats.Begin :
114
- trace . SetSpanAttributes ( ctx ,
117
+ span . SetAttributes (
115
118
trace.BoolAttribute {Key : "Client" , Value : rs .Client },
116
119
trace.BoolAttribute {Key : "FailFast" , Value : rs .FailFast })
117
120
case * stats.InPayload :
118
- trace .AddMessageReceiveEvent (ctx , 0 /* TODO: messageID */ , int64 (rs .Length ), int64 (rs .WireLength ))
121
+ span .AddMessageReceiveEvent (0 /* TODO: messageID */ , int64 (rs .Length ), int64 (rs .WireLength ))
119
122
case * stats.InHeader :
120
- trace .AddMessageReceiveEvent (ctx , 0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
123
+ span .AddMessageReceiveEvent (0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
121
124
case * stats.InTrailer :
122
- trace .AddMessageReceiveEvent (ctx , 0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
125
+ span .AddMessageReceiveEvent (0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
123
126
case * stats.OutPayload :
124
- trace .AddMessageSendEvent (ctx , 0 , int64 (rs .Length ), int64 (rs .WireLength ))
127
+ span .AddMessageSendEvent (0 , int64 (rs .Length ), int64 (rs .WireLength ))
125
128
case * stats.OutHeader :
126
- trace .AddMessageSendEvent (ctx , 0 , 0 , 0 )
129
+ span .AddMessageSendEvent (0 , 0 , 0 )
127
130
case * stats.OutTrailer :
128
- trace .AddMessageSendEvent (ctx , 0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
131
+ span .AddMessageSendEvent (0 , int64 (rs .WireLength ), int64 (rs .WireLength ))
129
132
case * stats.End :
130
133
if rs .Error != nil {
131
134
code , desc := grpc .Code (rs .Error ), grpc .ErrorDesc (rs .Error )
132
- trace . SetSpanStatus ( ctx , trace.Status {Code : int32 (code ), Message : desc })
135
+ span . SetStatus ( trace.Status {Code : int32 (code ), Message : desc })
133
136
}
134
- trace . EndSpan ( ctx )
137
+ span . End ( )
135
138
}
136
139
}
137
140
0 commit comments