Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opentracing.Bridge where it miss identifying the spanKind #3096

Merged
merged 6 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"net/http"
"strings"
"sync"

ot "github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -502,17 +501,15 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]attribut
for k, v := range tags {
switch k {
case string(otext.SpanKind):
if s, ok := v.(string); ok {
switch strings.ToLower(s) {
case "client":
kind = trace.SpanKindClient
case "server":
kind = trace.SpanKindServer
case "producer":
kind = trace.SpanKindProducer
case "consumer":
kind = trace.SpanKindConsumer
}
switch v {
case otext.SpanKindRPCClientEnum:
kind = trace.SpanKindClient
case otext.SpanKindRPCServerEnum:
kind = trace.SpanKindServer
case otext.SpanKindProducerEnum:
kind = trace.SpanKindProducer
case otext.SpanKindConsumerEnum:
kind = trace.SpanKindConsumer
}
case string(otext.Error):
if b, ok := v.(bool); ok && b {
Expand Down
33 changes: 33 additions & 0 deletions bridge/opentracing/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"testing"

ot "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/bridge/opentracing/internal"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -425,3 +427,34 @@ func TestBridgeTracer_StartSpan(t *testing.T) {
})
}
}

func Test_otTagsToOTelAttributesKindAndError(t *testing.T) {
tracer := internal.NewMockTracer()
sc := &bridgeSpanContext{}

testCases := []struct {
name string
opt []ot.StartSpanOption
expected trace.SpanKind
}{
{
name: "client",
opt: []ot.StartSpanOption{ext.SpanKindRPCClient},
expected: trace.SpanKindClient,
},
{
name: "server",
opt: []ot.StartSpanOption{ext.RPCServerOption(sc)},
expected: trace.SpanKindServer,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
b, _ := NewTracerPair(tracer)

s := b.StartSpan(tc.name, tc.opt...)
assert.Equal(t, s.(*bridgeSpan).otelSpan.(*internal.MockSpan).SpanKind, tc.expected)
})
}
}