You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Fix opentracing.Bridge where it miss identifying the spanKind (#3096)
* Fix opentracing.Bridge where it was not identifying the spanKinf correctly * fix test * changelog * Keeping backward comppatibillity * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
This commit is contained in:
@@ -13,6 +13,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Support Go 1.19.
|
||||
Include compatibility testing and document support. (#3077)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix misidentification of OpenTelemetry `SpanKind` in OpenTracing bridge (`go.opentelemetry.io/otel/bridge/opentracing`). (#3096)
|
||||
|
||||
## [1.9.0/0.0.3] - 2022-08-01
|
||||
|
||||
### Added
|
||||
|
||||
@@ -502,17 +502,19 @@ func otTagsToOTelAttributesKindAndError(tags map[string]interface{}) ([]attribut
|
||||
for k, v := range tags {
|
||||
switch k {
|
||||
case string(otext.SpanKind):
|
||||
sk := v
|
||||
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
|
||||
}
|
||||
sk = otext.SpanKindEnum(strings.ToLower(s))
|
||||
}
|
||||
switch sk {
|
||||
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 {
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
"testing"
|
||||
|
||||
ot "github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/bridge/opentracing/internal"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
@@ -425,3 +427,44 @@ 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,
|
||||
},
|
||||
{
|
||||
name: "client string",
|
||||
opt: []ot.StartSpanOption{ot.Tag{Key: "span.kind", Value: "client"}},
|
||||
expected: trace.SpanKindClient,
|
||||
},
|
||||
{
|
||||
name: "server string",
|
||||
opt: []ot.StartSpanOption{ot.Tag{Key: "span.kind", Value: "server"}},
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user