Skip to content

Commit

Permalink
Fix Http Status Code with Otel Bridge (#3265)
Browse files Browse the repository at this point in the history
* Fix Http Status Code with Otel Bridge

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
alanprot and MrAlias committed Oct 13, 2022
1 parent a8b9ddc commit 84e28fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions bridge/opentracing/bridge.go
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions bridge/opentracing/bridge_test.go
Expand Up @@ -17,7 +17,9 @@ package opentracing
import (
"context"
"errors"
"fmt"
"net/http"
"reflect"
"strings"
"testing"

Expand All @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 84e28fd

Please sign in to comment.