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 Http Status Code with Otel Bridge #3265

Merged
merged 5 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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