diff --git a/CHANGELOG.md b/CHANGELOG.md index 79760b035bc..faeccbc936b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Flush pending measurements with the `PeriodicReader` in the `go.opentelemetry.io/otel/sdk/metric` when `ForceFlush` or `Shutdown` are called. (#3220) - Update histogram default bounds to match the requirements of the latest specification. (#3222) +- Encode the HTTP status code in the OpenTracing bridge (`go.opentelemetry.io/otel/bridge/opentracing`) as an integer. (#3265) ### Fixed diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 967aaa20d4b..39b19276881 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -546,6 +546,14 @@ func otTagToOTelAttr(k string, v interface{}) attribute.KeyValue { return key.String(fmt.Sprintf("%d", val)) case float64: return key.Float64(val) + case int8: + return key.Int64(int64(val)) + case uint8: + return key.Int64(int64(val)) + case int16: + return key.Int64(int64(val)) + case uint16: + return key.Int64(int64(val)) case int32: return key.Int64(int64(val)) case uint32: diff --git a/bridge/opentracing/bridge_test.go b/bridge/opentracing/bridge_test.go index 7286bd77823..6b80da9004d 100644 --- a/bridge/opentracing/bridge_test.go +++ b/bridge/opentracing/bridge_test.go @@ -17,7 +17,9 @@ package opentracing import ( "context" "errors" + "fmt" "net/http" + "reflect" "strings" "testing" @@ -26,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/bridge/opentracing/internal" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" @@ -428,6 +431,38 @@ func TestBridgeTracer_StartSpan(t *testing.T) { } } +func Test_otTagToOTelAttr(t *testing.T) { + key := attribute.Key("test") + testCases := []struct { + value interface{} + expected attribute.KeyValue + }{ + { + value: int8(12), + expected: key.Int64(int64(12)), + }, + { + value: uint8(12), + expected: key.Int64(int64(12)), + }, + { + value: int16(12), + expected: key.Int64(int64(12)), + }, + { + value: uint16(12), + expected: key.Int64(int64(12)), + }, + } + + for _, tc := range testCases { + t.Run(fmt.Sprintf("%s %v", reflect.TypeOf(tc.value), tc.value), func(t *testing.T) { + att := otTagToOTelAttr(string(key), tc.value) + assert.Equal(t, tc.expected, att) + }) + } +} + func Test_otTagsToOTelAttributesKindAndError(t *testing.T) { tracer := internal.NewMockTracer() sc := &bridgeSpanContext{}