Skip to content

Commit 658c553

Browse files
committed
sets the span kind
Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com>
1 parent 66e0ce9 commit 658c553

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

cmd/query/app/apiv3/otlp_translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func jSpanToOTLP(jSpan *model.Span) (*tracev1.Span, resource, instrumentationLib
109109
Events: jLogsToOTLP(jSpan.GetLogs()),
110110
Links: jReferencesToOTLP(jSpan.GetReferences(), jSpan.ParentSpanID()),
111111
Status: status,
112-
Kind: tracev1.Span_SPAN_KIND_INTERNAL,
112+
Kind: tracev1.Span_SPAN_KIND_UNSPECIFIED,
113113
}
114114
if kind, found := jSpan.GetSpanKind(); found {
115115
s.Kind = jSpanKindToInternal(kind.String())

model/span.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ const (
4141
// Flags is a bit map of flags for a span
4242
type Flags uint32
4343

44-
// Map from string to trace.SpanKind
45-
var spanKindMapping = map[string]trace.SpanKind{
46-
"client": trace.SpanKindClient,
47-
"server": trace.SpanKindServer,
48-
"producer": trace.SpanKindProducer,
49-
"consumer": trace.SpanKindConsumer,
50-
"internal": trace.SpanKindInternal,
44+
// Map from string to trace.SpanKind.
45+
func toSpanKind(s string) (trace.SpanKind, bool) {
46+
sk, found := map[string]trace.SpanKind{
47+
"client": trace.SpanKindClient,
48+
"server": trace.SpanKindServer,
49+
"producer": trace.SpanKindProducer,
50+
"consumer": trace.SpanKindConsumer,
51+
"internal": trace.SpanKindInternal,
52+
}[s]
53+
return sk, found
5154
}
5255

5356
// Hash implements Hash from Hashable.
@@ -69,7 +72,7 @@ func (s *Span) HasSpanKind(kind trace.SpanKind) bool {
6972
// GetSpanKind returns value of `span.kind` tag and whether the tag can be found
7073
func (s *Span) GetSpanKind() (spanKind trace.SpanKind, found bool) {
7174
if tag, ok := KeyValues(s.Tags).FindByKey(keySpanKind); ok {
72-
if kind, ok := spanKindMapping[tag.AsString()]; ok {
75+
if kind, ok := toSpanKind(tag.AsString()); ok {
7376
return kind, true
7477
}
7578
}

model/span_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ var (
122122
}
123123
)
124124

125+
const keySpanKind = "span.kind"
126+
125127
func TestSpanIDMarshalJSON(t *testing.T) {
126128
for _, testCase := range testCasesSpanID {
127129
expected := fmt.Sprintf(`{"traceId":"AAAAAAAAAAAAAAAAAAAAAA==","spanId":"%s"}`, testCase.b64)
@@ -188,7 +190,7 @@ func TestSpanIDUnmarshalJSONErrors(t *testing.T) {
188190
func TestIsRPCClientServer(t *testing.T) {
189191
span1 := &model.Span{
190192
Tags: model.KeyValues{
191-
model.String(string("span.kind"), trace.SpanKindClient.String()),
193+
model.String(keySpanKind, trace.SpanKindClient.String()),
192194
},
193195
}
194196
assert.True(t, span1.IsRPCClient())

0 commit comments

Comments
 (0)