Skip to content

Commit a9786a7

Browse files
committed
fix
1 parent 9289a08 commit a9786a7

File tree

9 files changed

+113
-100
lines changed

9 files changed

+113
-100
lines changed

internal/balancer/balancer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ func (b *Balancer) clusterDiscoveryAttempt(ctx context.Context) (err error) {
8888
onDone = trace.DriverOnBalancerClusterDiscoveryAttempt(
8989
b.driverConfig.Trace(), &ctx,
9090
stack.FunctionID(
91-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).clusterDiscoveryAttempt"),
91+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).clusterDiscoveryAttempt",
92+
),
9293
address,
94+
b.driverConfig.Database(),
9395
)
9496
endpoints []endpoint.Endpoint
9597
localDC string
@@ -130,6 +132,7 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, newest []endpoi
130132
stack.FunctionID(
131133
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.(*Balancer).applyDiscoveredEndpoints"),
132134
b.config.DetectNearestDC,
135+
b.driverConfig.Database(),
133136
)
134137
previous = b.connections().All()
135138
)

internal/repeater/repeater.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,8 @@ func (r *repeater) Force() {
139139
}
140140
}
141141

142-
func (r *repeater) wakeUp(ctx context.Context, e Event) (err error) {
143-
if err = ctx.Err(); err != nil {
144-
return err
145-
}
146-
147-
ctx = WithEvent(ctx, e)
142+
func (r *repeater) wakeUp(e Event) (err error) {
143+
ctx := WithEvent(context.Background(), e)
148144

149145
onDone := trace.DriverOnRepeaterWakeUp(r.trace, &ctx,
150146
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/repeater.(*repeater).wakeUp"),
@@ -203,7 +199,7 @@ func (r *repeater) worker(ctx context.Context, tick clockwork.Ticker) {
203199
if event == EventCancel {
204200
return
205201
}
206-
if err := r.wakeUp(ctx, event); err != nil {
202+
if err := r.wakeUp(event); err != nil {
207203
forceIndex++
208204
} else {
209205
forceIndex = 0

log/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ func internalDriver(l Logger, d trace.Detailer) trace.Driver {
464464
ctx := with(*info.Context, TRACE, "ydb", "driver", "balancer", "update")
465465
l.Log(ctx, "start",
466466
kv.Bool("needLocalDC", info.NeedLocalDC),
467+
kv.String("database", info.Database),
467468
)
468469
start := time.Now()
469470

otel/config.go

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package otel
33
import (
44
"context"
55

6-
"github.com/ydb-platform/ydb-go-sdk/v3"
76
"github.com/ydb-platform/ydb-go-sdk/v3/internal/kv"
8-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
97
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
108
)
119

@@ -27,73 +25,3 @@ type (
2725
Start(ctx context.Context, operationName string, attributes ...KeyValue) (context.Context, Span)
2826
}
2927
)
30-
31-
func childSpanWithReplaceCtx(
32-
cfg Config,
33-
ctx *context.Context,
34-
operationName string,
35-
fields ...KeyValue,
36-
) (s Span) {
37-
*ctx, s = childSpan(cfg, *ctx, operationName, fields...)
38-
39-
return s
40-
}
41-
42-
func childSpan(
43-
cfg Config,
44-
ctx context.Context, //nolint:revive
45-
operationName string,
46-
fields ...KeyValue,
47-
) (context.Context, Span) {
48-
return cfg.Start(ctx,
49-
operationName,
50-
fields...,
51-
)
52-
}
53-
54-
func finish(
55-
s Span,
56-
err error,
57-
fields ...KeyValue,
58-
) {
59-
if err != nil {
60-
s.Msg(err.Error(), kv.Error(err))
61-
}
62-
s.End(fields...)
63-
}
64-
65-
func logError(
66-
s Span,
67-
err error,
68-
fields ...KeyValue,
69-
) {
70-
var ydbErr ydb.Error
71-
if xerrors.As(err, &ydbErr) {
72-
fields = append(fields,
73-
kv.Error(err),
74-
kv.Int("error.ydb.code", int(ydbErr.Code())),
75-
kv.String("error.ydb.name", ydbErr.Name()),
76-
)
77-
}
78-
s.Msg(err.Error(), fields...)
79-
}
80-
81-
func logToParentSpan(
82-
cfg Config,
83-
ctx context.Context, //nolint:revive
84-
msg string,
85-
fields ...KeyValue, //nolint:unparam
86-
) {
87-
parent := cfg.SpanFromContext(ctx)
88-
parent.Msg(msg, fields...)
89-
}
90-
91-
func logToParentSpanError(
92-
cfg Config,
93-
ctx context.Context, //nolint:revive
94-
err error,
95-
fields ...KeyValue, //nolint:unparam
96-
) {
97-
parent := cfg.SpanFromContext(ctx)
98-
logError(parent, err, fields...)
99-
}

otel/driver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
265265
cfg,
266266
info.Context,
267267
info.Call.FunctionID(),
268+
kv.String("address", info.Address),
268269
)
269270

270271
return func(info trace.DriverBalancerClusterDiscoveryAttemptDoneInfo) {
@@ -275,9 +276,11 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
275276
if cfg.Details()&trace.DriverBalancerEvents == 0 {
276277
return nil
277278
}
278-
needLocalDC := info.NeedLocalDC
279-
functionID := info.Call.FunctionID()
280-
s := cfg.SpanFromContext(*info.Context)
279+
start := childSpanWithReplaceCtx(cfg, info.Context,
280+
info.Call.FunctionID(),
281+
kv.String("database", info.Database),
282+
kv.Bool("need_local_dc", info.NeedLocalDC),
283+
)
281284

282285
return func(info trace.DriverBalancerUpdateDoneInfo) {
283286
var (
@@ -294,12 +297,11 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
294297
for i, e := range info.Dropped {
295298
dropped[i] = e.String()
296299
}
297-
s.Msg(functionID,
300+
start.End(
298301
kv.String("local_dc", info.LocalDC),
299302
kv.Strings("endpoints", endpoints),
300303
kv.Strings("added", added),
301304
kv.Strings("dropped", dropped),
302-
kv.Bool("need_local_dc", needLocalDC),
303305
)
304306
}
305307
},

otel/helpers.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package otel
2+
3+
import (
4+
"context"
5+
6+
"github.com/ydb-platform/ydb-go-sdk/v3"
7+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/kv"
8+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
9+
)
10+
11+
func childSpanWithReplaceCtx(
12+
cfg Config,
13+
ctx *context.Context,
14+
operationName string,
15+
fields ...KeyValue,
16+
) (s Span) {
17+
*ctx, s = childSpan(cfg, *ctx, operationName, fields...)
18+
19+
return s
20+
}
21+
22+
func childSpan(
23+
cfg Config,
24+
ctx context.Context, //nolint:revive
25+
operationName string,
26+
fields ...KeyValue,
27+
) (context.Context, Span) {
28+
return cfg.Start(ctx,
29+
operationName,
30+
fields...,
31+
)
32+
}
33+
34+
func finish(
35+
s Span,
36+
err error,
37+
fields ...KeyValue,
38+
) {
39+
if err != nil {
40+
s.Msg(err.Error(), kv.Error(err))
41+
}
42+
s.End(fields...)
43+
}
44+
45+
func logError(
46+
s Span,
47+
err error,
48+
fields ...KeyValue,
49+
) {
50+
var ydbErr ydb.Error
51+
if xerrors.As(err, &ydbErr) {
52+
fields = append(fields,
53+
kv.Error(err),
54+
kv.Int("error.ydb.code", int(ydbErr.Code())),
55+
kv.String("error.ydb.name", ydbErr.Name()),
56+
)
57+
}
58+
s.Msg(err.Error(), fields...)
59+
}
60+
61+
func logToParentSpan(
62+
cfg Config,
63+
ctx context.Context, //nolint:revive
64+
msg string,
65+
fields ...KeyValue, //nolint:unparam
66+
) {
67+
parent := cfg.SpanFromContext(ctx)
68+
parent.Msg(msg, fields...)
69+
}
70+
71+
func logToParentSpanError(
72+
cfg Config,
73+
ctx context.Context, //nolint:revive
74+
err error,
75+
fields ...KeyValue, //nolint:unparam
76+
) {
77+
parent := cfg.SpanFromContext(ctx)
78+
logError(parent, err, fields...)
79+
}

otel/noop.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ type (
1616
noopSpan struct{}
1717
)
1818

19-
func (noopSpan) Relation(Span) {}
20-
21-
func (noopSpan) TraceID() string {
22-
return ""
23-
}
24-
25-
func (n noopSpan) Msg(string, ...KeyValue) {}
26-
27-
func (n noopSpan) End(...KeyValue) {}
28-
2919
func (noopConfig) Details() trace.Details {
3020
return 0
3121
}
@@ -37,3 +27,13 @@ func (noopConfig) SpanFromContext(context.Context) Span {
3727
func (noopConfig) Start(ctx context.Context, _ string, _ ...KeyValue) (context.Context, Span) {
3828
return ctx, noopSpan{}
3929
}
30+
31+
func (noopSpan) Relation(Span) {}
32+
33+
func (noopSpan) TraceID() string {
34+
return ""
35+
}
36+
37+
func (n noopSpan) Msg(string, ...KeyValue) {}
38+
39+
func (n noopSpan) End(...KeyValue) {}

trace/driver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ type (
189189
Context *context.Context
190190
Call call
191191
NeedLocalDC bool
192+
Database string
192193
}
193194
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
194195
DriverBalancerUpdateDoneInfo struct {
@@ -203,9 +204,10 @@ type (
203204
// Pointer to context provide replacement of context in trace callback function.
204205
// Warning: concurrent access to pointer on client side must be excluded.
205206
// Safe replacement of context are provided only inside callback function
206-
Context *context.Context
207-
Call call
208-
Address string
207+
Context *context.Context
208+
Call call
209+
Address string
210+
Database string
209211
}
210212
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
211213
DriverBalancerClusterDiscoveryAttemptDoneInfo struct {

trace/driver_gtrace.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)