Skip to content

Commit 1e815d8

Browse files
committed
reduce spans on conn
1 parent bc61e61 commit 1e815d8

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

spans/driver.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,28 @@ func driver(adapter Adapter) trace.Driver { //nolint:gocyclo,funlen
169169
if adapter.Details()&trace.DriverConnStreamEvents == 0 {
170170
return nil
171171
}
172-
start := childSpanWithReplaceCtx(
173-
adapter,
174-
info.Context,
175-
info.Call.FunctionID(),
172+
173+
var (
174+
call = info.Call
175+
start = adapter.SpanFromContext(*info.Context)
176176
)
177177

178178
return func(info trace.DriverConnStreamCloseSendDoneInfo) {
179-
finish(start, info.Error)
179+
if info.Error != nil {
180+
start.Log(call.FunctionID(), kv.Error(info.Error))
181+
}
180182
}
181183
},
182184
OnConnStreamFinish: func(info trace.DriverConnStreamFinishInfo) {
183185
if adapter.Details()&trace.DriverConnStreamEvents == 0 {
184186
return
185187
}
186-
start := childSpanWithReplaceCtx(
187-
adapter,
188-
&info.Context,
189-
info.Call.FunctionID(),
188+
189+
var (
190+
call = info.Call
191+
start = adapter.SpanFromContext(info.Context)
192+
counters = grpcStreamMsgCountersFromContext(info.Context)
190193
)
191-
counters := grpcStreamMsgCountersFromContext(info.Context)
192194

193195
attributes := make([]kv.KeyValue, 0, 2)
194196
if counters != nil {
@@ -197,42 +199,47 @@ func driver(adapter Adapter) trace.Driver { //nolint:gocyclo,funlen
197199
kv.Int64("sent_messages", counters.sentMessages()),
198200
)
199201
}
200-
finish(start, info.Error, attributes...)
202+
203+
if info.Error != nil {
204+
attributes = append(attributes, kv.Error(info.Error))
205+
}
206+
207+
start.Log(call.FunctionID(), attributes...)
201208
},
202209
OnConnPark: func(info trace.DriverConnParkStartInfo) func(trace.DriverConnParkDoneInfo) {
203210
if adapter.Details()&trace.DriverConnEvents == 0 {
204211
return nil
205212
}
206-
start := childSpanWithReplaceCtx(
207-
adapter,
208-
info.Context,
209-
info.Call.FunctionID(),
210-
kv.String("address", safeAddress(info.Endpoint)),
213+
214+
var (
215+
call = info.Call
216+
start = adapter.SpanFromContext(*info.Context)
211217
)
212218

213219
return func(info trace.DriverConnParkDoneInfo) {
214-
finish(
215-
start,
216-
info.Error,
217-
)
220+
if info.Error != nil {
221+
start.Log(call.FunctionID(), kv.Error(info.Error))
222+
} else {
223+
start.Log(call.FunctionID())
224+
}
218225
}
219226
},
220227
OnConnClose: func(info trace.DriverConnCloseStartInfo) func(trace.DriverConnCloseDoneInfo) {
221228
if adapter.Details()&trace.DriverConnEvents == 0 {
222229
return nil
223230
}
224-
start := childSpanWithReplaceCtx(
225-
adapter,
226-
info.Context,
227-
info.Call.FunctionID(),
228-
kv.String("address", safeAddress(info.Endpoint)),
231+
232+
var (
233+
call = info.Call
234+
start = adapter.SpanFromContext(*info.Context)
229235
)
230236

231237
return func(info trace.DriverConnCloseDoneInfo) {
232-
finish(
233-
start,
234-
info.Error,
235-
)
238+
if info.Error != nil {
239+
start.Log(call.FunctionID(), kv.Error(info.Error))
240+
} else {
241+
start.Log(call.FunctionID())
242+
}
236243
}
237244
},
238245
OnConnBan: func(info trace.DriverConnBanStartInfo) func(trace.DriverConnBanDoneInfo) {

0 commit comments

Comments
 (0)