This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
/
types.go
78 lines (70 loc) · 1.91 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package tracing
import (
"context"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/retry"
"net/url"
)
func logError(s opentracing.Span, err error) {
s.SetTag(string(ext.Error), true)
s.LogFields(otlog.Error(err))
m := retry.Check(err)
if v := s.BaggageItem("idempotent"); v != "" {
s.SetTag(string(ext.Error)+".retryable", m.MustRetry(v == "true"))
}
s.SetTag(string(ext.Error)+".delete_session", m.MustDeleteSession())
}
func finish(s opentracing.Span, err error, fields ...otlog.Field) {
if err != nil {
logError(s, err)
}
s.LogFields(fields...)
s.Finish()
}
type counter struct {
span opentracing.Span
counter int64
name string
}
func startSpanWithCounter(ctx *context.Context, operationName string, counterName string, fields ...otlog.Field) (c *counter) {
defer func() {
c.span.SetTag("ydb.driver.sensor", operationName+"_"+counterName)
}()
return &counter{
span: startSpan(ctx, operationName, fields...),
counter: 0,
name: counterName,
}
}
func startSpan(ctx *context.Context, operationName string, fields ...otlog.Field) (s opentracing.Span) {
if ctx != nil {
var childCtx context.Context
s, childCtx = opentracing.StartSpanFromContext(*ctx, operationName)
*ctx = childCtx
} else {
s = opentracing.StartSpan(operationName)
}
s.SetTag("ydb-go-sdk", "v"+ydb.Version)
s.LogFields(fields...)
return s
}
func followSpan(
related opentracing.SpanContext,
operationName string,
fields ...otlog.Field,
) (s opentracing.Span) {
s = opentracing.StartSpan(operationName, opentracing.FollowsFrom(related))
s.SetTag("ydb-go-sdk", "v"+ydb.Version)
s.LogFields(fields...)
return s
}
func nodeID(sessionID string) string {
u, err := url.Parse(sessionID)
if err != nil {
return ""
}
return u.Query().Get("node_id")
}