Skip to content

Commit 065b200

Browse files
fix(extra/redisotel): set span.kind attribute to client
According to the opentelemetry specification this should always be set to client for database client libraries. I've also removed the SetAttributes call and instead set the attributes during creation of the span. This is what the library SHOULD be doing according to the opentelemetry api specification.
1 parent 38d398f commit 065b200

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

extra/redisotel/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
3333
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
3434
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
3535
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
36+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
3637
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
3738
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
3839
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=

extra/redisotel/redisotel.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.
2727
return ctx, nil
2828
}
2929

30-
ctx, span := tracer.Start(ctx, cmd.FullName())
31-
span.SetAttributes(
30+
attrs := []attribute.KeyValue{
3231
attribute.String("db.system", "redis"),
3332
attribute.String("db.statement", rediscmd.CmdString(cmd)),
34-
)
33+
}
34+
opts := []trace.SpanStartOption{
35+
trace.WithSpanKind(trace.SpanKindClient),
36+
trace.WithAttributes(attrs...),
37+
}
38+
39+
ctx, _ = tracer.Start(ctx, cmd.FullName(), opts...)
3540

3641
return ctx, nil
3742
}
@@ -52,12 +57,17 @@ func (TracingHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder
5257

5358
summary, cmdsString := rediscmd.CmdsString(cmds)
5459

55-
ctx, span := tracer.Start(ctx, "pipeline "+summary)
56-
span.SetAttributes(
60+
attrs := []attribute.KeyValue{
5761
attribute.String("db.system", "redis"),
5862
attribute.Int("db.redis.num_cmd", len(cmds)),
5963
attribute.String("db.statement", cmdsString),
60-
)
64+
}
65+
opts := []trace.SpanStartOption{
66+
trace.WithSpanKind(trace.SpanKindClient),
67+
trace.WithAttributes(attrs...),
68+
}
69+
70+
ctx, _ = tracer.Start(ctx, "pipeline "+summary, opts...)
6171

6272
return ctx, nil
6373
}

0 commit comments

Comments
 (0)