Skip to content

Commit

Permalink
[pkg/translator/jaeger] Preserve binary attribute values (open-teleme…
Browse files Browse the repository at this point in the history
…try#32208)

**Description:** translate binary attribute values to/from Jaeger as is,
without encoding them as base64 strings

**Link to tracking Issue:**  Resolves open-telemetry#32204

**Testing:** unit tests in the package

**Documentation:** none

---------

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed Apr 23, 2024
1 parent df80416 commit b2bc497
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
27 changes: 27 additions & 0 deletions .chloggen/translator_jaeger_keep_bin_attrs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/translator/jaeger

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: translate binary attribute values to/from Jaeger as is, without encoding them as base64 strings

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32204]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
3 changes: 1 addition & 2 deletions pkg/translator/jaeger/jaegerproto_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package jaeger // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"

import (
"encoding/base64"
"encoding/binary"
"fmt"
"hash/fnv"
Expand Down Expand Up @@ -240,7 +239,7 @@ func jTagsToInternalAttributes(tags []model.KeyValue, dest pcommon.Map) {
case model.ValueType_FLOAT64:
dest.PutDouble(tag.Key, tag.GetVFloat64())
case model.ValueType_BINARY:
dest.PutStr(tag.Key, base64.StdEncoding.EncodeToString(tag.GetVBinary()))
dest.PutEmptyBytes(tag.Key).FromRaw(tag.GetVBinary())
default:
dest.PutStr(tag.Key, fmt.Sprintf("<Unknown Jaeger TagType %q>", tag.GetVType()))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/translator/jaeger/jaegerproto_to_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestJTagsToInternalAttributes(t *testing.T) {
expected.PutInt("int-val", 123)
expected.PutStr("string-val", "abc")
expected.PutDouble("double-val", 1.23)
expected.PutStr("binary-val", "AAAAAABkfZg=")
expected.PutEmptyBytes("binary-val").FromRaw([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7D, 0x98})

got := pcommon.NewMap()
jTagsToInternalAttributes(tags, got)
Expand Down
3 changes: 1 addition & 2 deletions pkg/translator/jaeger/jaegerthrift_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package jaeger // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"

import (
"encoding/base64"
"fmt"
"reflect"

Expand Down Expand Up @@ -150,7 +149,7 @@ func jThriftTagsToInternalAttributes(tags []*jaeger.Tag, dest pcommon.Map) {
case jaeger.TagType_DOUBLE:
dest.PutDouble(tag.Key, tag.GetVDouble())
case jaeger.TagType_BINARY:
dest.PutStr(tag.Key, base64.StdEncoding.EncodeToString(tag.GetVBinary()))
dest.PutEmptyBytes(tag.Key).FromRaw(tag.GetVBinary())
default:
dest.PutStr(tag.Key, fmt.Sprintf("<Unknown Jaeger TagType %q>", tag.GetVType()))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/translator/jaeger/jaegerthrift_to_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestJThriftTagsToInternalAttributes(t *testing.T) {
expected.PutInt("int-val", 123)
expected.PutStr("string-val", "abc")
expected.PutDouble("double-val", 1.23)
expected.PutStr("binary-val", "AAAAAABkfZg=")
expected.PutEmptyBytes("binary-val").FromRaw([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x7D, 0x98})

got := pcommon.NewMap()
jThriftTagsToInternalAttributes(tags, got)
Expand Down
8 changes: 2 additions & 6 deletions pkg/translator/jaeger/traces_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package jaeger // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"

import (
"encoding/base64"

"github.com/jaegertracing/jaeger/model"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
Expand Down Expand Up @@ -125,8 +123,6 @@ func attributeToJaegerProtoTag(key string, attr pcommon.Value) model.KeyValue {
tag := model.KeyValue{Key: key}
switch attr.Type() {
case pcommon.ValueTypeStr:
// Jaeger-to-Internal maps binary tags to string attributes and encodes them as
// base64 strings. Blindingly attempting to decode base64 seems too much.
tag.VType = model.ValueType_STRING
tag.VStr = attr.Str()
case pcommon.ValueTypeInt:
Expand All @@ -139,8 +135,8 @@ func attributeToJaegerProtoTag(key string, attr pcommon.Value) model.KeyValue {
tag.VType = model.ValueType_FLOAT64
tag.VFloat64 = attr.Double()
case pcommon.ValueTypeBytes:
tag.VType = model.ValueType_STRING
tag.VStr = base64.StdEncoding.EncodeToString(attr.Bytes().AsRaw())
tag.VType = model.ValueType_BINARY
tag.VBinary = attr.Bytes().AsRaw()
case pcommon.ValueTypeMap, pcommon.ValueTypeSlice:
tag.VType = model.ValueType_STRING
tag.VStr = attr.AsString()
Expand Down
6 changes: 3 additions & 3 deletions pkg/translator/jaeger/traces_to_jaegerproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {
VFloat64: 1.23,
},
{
Key: "bytes-val",
VType: model.ValueType_STRING,
VStr: "AQIDBA==", // base64 encoding of the byte array [1,2,3,4]
Key: "bytes-val",
VType: model.ValueType_BINARY,
VBinary: []byte{1, 2, 3, 4},
},
{
Key: conventions.AttributeServiceName,
Expand Down

0 comments on commit b2bc497

Please sign in to comment.