Skip to content

Commit 492a3c9

Browse files
committed
Msg => Log+Warn+Error
1 parent a9786a7 commit 492a3c9

File tree

9 files changed

+53
-37
lines changed

9 files changed

+53
-37
lines changed

otel/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ type (
1212
Span interface {
1313
TraceID() string
1414

15-
Relation(span Span)
15+
Link(link Span, attributes ...KeyValue)
1616

17-
Msg(msg string, attributes ...KeyValue)
17+
Log(msg string, attributes ...KeyValue)
18+
Warn(err error, attributes ...KeyValue)
19+
Error(err error, attributes ...KeyValue)
1820

1921
End(attributes ...KeyValue)
2022
}

otel/driver.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
219219
return nil
220220
}
221221
s := cfg.SpanFromContext(*info.Context)
222-
s.Msg(info.Call.FunctionID(),
222+
s.Log(info.Call.FunctionID(),
223223
kv.String("cause", safeError(info.Cause)),
224224
)
225225

@@ -234,7 +234,7 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
234234
functionID := info.Call.FunctionID()
235235

236236
return func(info trace.DriverConnStateChangeDoneInfo) {
237-
s.Msg(functionID,
237+
s.Log(functionID,
238238
kv.String("old state", oldState),
239239
kv.String("new state", safeStringer(info.State)),
240240
)
@@ -318,11 +318,9 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
318318

319319
return func(info trace.DriverBalancerChooseEndpointDoneInfo) {
320320
if info.Error != nil {
321-
parent.Msg(functionID,
322-
kv.Error(info.Error),
323-
)
321+
parent.Error(info.Error)
324322
} else {
325-
parent.Msg(functionID,
323+
parent.Log(functionID,
326324
kv.String("address", safeAddress(info.Endpoint)),
327325
kv.String("nodeID", safeNodeID(info.Endpoint)),
328326
)
@@ -338,9 +336,7 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
338336

339337
return func(info trace.DriverGetCredentialsDoneInfo) {
340338
if info.Error != nil {
341-
parent.Msg(functionID,
342-
kv.Error(info.Error),
343-
)
339+
parent.Error(info.Error)
344340
} else {
345341
var mask bytes.Buffer
346342
if len(info.Token) > 16 {
@@ -351,7 +347,7 @@ func driver(cfg Config) trace.Driver { //nolint:gocyclo,funlen
351347
mask.WriteString("****")
352348
}
353349
mask.WriteString(fmt.Sprintf("(CRC-32c: %08X)", crc32.Checksum([]byte(info.Token), crc32.IEEETable)))
354-
parent.Msg(functionID,
350+
parent.Log(functionID,
355351
kv.String("token", mask.String()),
356352
)
357353
}

otel/field.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package otel
2+
3+
import (
4+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/kv"
5+
)
6+
7+
type (
8+
Field = kv.KeyValue
9+
)
10+
11+
const (
12+
IntType = kv.IntType
13+
Int64Type = kv.Int64Type
14+
StringType = kv.StringType
15+
BoolType = kv.BoolType
16+
StringsType = kv.StringsType
17+
StringerType = kv.StringerType
18+
)

otel/helpers.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func finish(
3737
fields ...KeyValue,
3838
) {
3939
if err != nil {
40-
s.Msg(err.Error(), kv.Error(err))
40+
s.Error(err)
4141
}
4242
s.End(fields...)
4343
}
@@ -50,12 +50,11 @@ func logError(
5050
var ydbErr ydb.Error
5151
if xerrors.As(err, &ydbErr) {
5252
fields = append(fields,
53-
kv.Error(err),
5453
kv.Int("error.ydb.code", int(ydbErr.Code())),
5554
kv.String("error.ydb.name", ydbErr.Name()),
5655
)
5756
}
58-
s.Msg(err.Error(), fields...)
57+
s.Error(err, fields...)
5958
}
6059

6160
func logToParentSpan(
@@ -65,7 +64,7 @@ func logToParentSpan(
6564
fields ...KeyValue, //nolint:unparam
6665
) {
6766
parent := cfg.SpanFromContext(ctx)
68-
parent.Msg(msg, fields...)
67+
parent.Log(msg, fields...)
6968
}
7069

7170
func logToParentSpanError(

otel/noop.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ func (noopConfig) Start(ctx context.Context, _ string, _ ...KeyValue) (context.C
2828
return ctx, noopSpan{}
2929
}
3030

31-
func (noopSpan) Relation(Span) {}
31+
func (noopSpan) Link(Span, ...KeyValue) {}
3232

3333
func (noopSpan) TraceID() string {
3434
return ""
3535
}
3636

37-
func (n noopSpan) Msg(string, ...KeyValue) {}
37+
func (n noopSpan) Log(string, ...KeyValue) {}
38+
func (n noopSpan) Warn(error, ...KeyValue) {}
39+
func (n noopSpan) Error(error, ...KeyValue) {}
3840

3941
func (n noopSpan) End(...KeyValue) {}

otel/retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func retry(cfg Config) (t trace.Retry) {
7575
kv.Bool("idempotent", info.Idempotent),
7676
)
7777
if info.NestedCall {
78-
start.Msg("nested call", kv.Error(errNestedCall))
78+
start.Warn(errNestedCall)
7979
}
8080
ctx := *info.Context
8181

@@ -87,7 +87,7 @@ func retry(cfg Config) (t trace.Retry) {
8787
fields = append(fields, fieldsFromStore...)
8888
}
8989
if info.Error != nil {
90-
fields = append(fields, kv.Error(info.Error))
90+
start.Error(info.Error)
9191
}
9292
start.End(fields...)
9393
}

otel/scripting.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ func scripting(cfg Config) (t trace.Scripting) {
5555
) func(
5656
trace.ScriptingStreamExecuteDoneInfo,
5757
) {
58-
start.Msg("", kv.Error(info.Error))
58+
if info.Error != nil {
59+
start.Warn(info.Error)
60+
}
5961

6062
return func(info trace.ScriptingStreamExecuteDoneInfo) {
61-
start.Msg("")
6263
if info.Error != nil {
63-
start.End(kv.Error(info.Error))
64-
} else {
65-
start.End()
64+
start.Error(info.Error)
6665
}
66+
start.End()
6767
}
6868
}
6969
}

otel/sql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func databaseSQL(cfg Config) (t trace.DatabaseSQL) {
212212
)
213213

214214
if !isStmtCall(*info.Context) {
215-
start.Relation(cfg.SpanFromContext(info.TxContext))
215+
start.Link(cfg.SpanFromContext(info.TxContext))
216216
}
217217

218218
return func(info trace.DatabaseSQLTxExecDoneInfo) {
@@ -235,7 +235,7 @@ func databaseSQL(cfg Config) (t trace.DatabaseSQL) {
235235
)
236236

237237
if !isStmtCall(*info.Context) {
238-
start.Relation(cfg.SpanFromContext(info.TxContext))
238+
start.Link(cfg.SpanFromContext(info.TxContext))
239239
}
240240

241241
return func(info trace.DatabaseSQLTxQueryDoneInfo) {
@@ -275,7 +275,7 @@ func databaseSQL(cfg Config) (t trace.DatabaseSQL) {
275275
kv.String("query", info.Query),
276276
)
277277

278-
start.Relation(cfg.SpanFromContext(info.StmtContext))
278+
start.Link(cfg.SpanFromContext(info.StmtContext))
279279

280280
*info.Context = markStmtCall(*info.Context)
281281

@@ -297,7 +297,7 @@ func databaseSQL(cfg Config) (t trace.DatabaseSQL) {
297297
kv.String("query", info.Query),
298298
)
299299

300-
start.Relation(cfg.SpanFromContext(info.StmtContext))
300+
start.Link(cfg.SpanFromContext(info.StmtContext))
301301

302302
*info.Context = markStmtCall(*info.Context)
303303

otel/table.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func table(cfg Config) (t trace.Table) { //nolint:gocyclo
5151
kv.Bool("idempotent", info.Idempotent),
5252
)
5353
if info.NestedCall {
54-
start.Msg("nested call", kv.Error(errNestedCall))
54+
start.Warn(errNestedCall)
5555
}
5656

5757
return func(info trace.TableDoDoneInfo) {
5858
fields := []KeyValue{
5959
kv.Int("attempts", info.Attempts),
6060
}
6161
if info.Error != nil {
62-
fields = append(fields, kv.Error(info.Error))
62+
start.Error(info.Error)
6363
}
6464
start.End(fields...)
6565
}
@@ -81,15 +81,15 @@ func table(cfg Config) (t trace.Table) { //nolint:gocyclo
8181
kv.Bool("idempotent", info.Idempotent),
8282
)
8383
if info.NestedCall {
84-
start.Msg("nested call", kv.Error(errNestedCall))
84+
start.Warn(errNestedCall)
8585
}
8686

8787
return func(info trace.TableDoTxDoneInfo) {
8888
fields := []KeyValue{
8989
kv.Int("attempts", info.Attempts),
9090
}
9191
if info.Error != nil {
92-
fields = append(fields, kv.Error(info.Error))
92+
start.Error(info.Error)
9393
}
9494
start.End(fields...)
9595
}
@@ -247,10 +247,9 @@ func table(cfg Config) (t trace.Table) { //nolint:gocyclo
247247

248248
return func(info trace.TableSessionQueryStreamExecuteDoneInfo) {
249249
if info.Error != nil {
250-
start.End(kv.Error(info.Error))
251-
} else {
252-
start.End()
250+
start.Error(info.Error)
253251
}
252+
start.End()
254253
}
255254
}
256255

@@ -272,7 +271,7 @@ func table(cfg Config) (t trace.Table) { //nolint:gocyclo
272271

273272
return func(info trace.TableSessionQueryStreamReadDoneInfo) {
274273
if info.Error != nil {
275-
start.End(kv.Error(info.Error))
274+
start.Error(info.Error)
276275
} else {
277276
start.End()
278277
}

0 commit comments

Comments
 (0)