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

[translator/jaeger] Convert ValueTypeBytes attributes in Jaeger translator #14574

Merged
merged 2 commits into from
Sep 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/translator/jaeger/traces_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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 @@ -147,6 +149,9 @@ func attributeToJaegerProtoTag(key string, attr pcommon.Value) model.KeyValue {
case pcommon.ValueTypeDouble:
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())
case pcommon.ValueTypeMap, pcommon.ValueTypeSlice:
tag.VType = model.ValueType_STRING
tag.VStr = attr.AsString()
Expand Down
8 changes: 7 additions & 1 deletion pkg/translator/jaeger/traces_to_jaegerproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {
attributes.PutInt("int-val", 123)
attributes.PutString("string-val", "abc")
attributes.PutDouble("double-val", 1.23)
attributes.PutEmptyBytes("bytes-val").FromRaw([]byte{1, 2, 3, 4})
attributes.PutString(conventions.AttributeServiceName, "service-name")

expected := []model.KeyValue{
Expand All @@ -204,6 +205,11 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {
VType: model.ValueType_FLOAT64,
VFloat64: 1.23,
},
{
Key: "bytes-val",
VType: model.ValueType_STRING,
VStr: "AQIDBA==", // base64 encoding of the byte array [1,2,3,4]
},
{
Key: conventions.AttributeServiceName,
VType: model.ValueType_STRING,
Expand All @@ -216,7 +222,7 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {

// The last item in expected ("service-name") must be skipped in resource tags translation
got = appendTagsFromResourceAttributes(make([]model.KeyValue, 0, len(expected)-1), attributes)
require.EqualValues(t, expected[:4], got)
require.EqualValues(t, expected[:5], got)
}

func TestInternalTracesToJaegerProto(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions unreleased/jaeger-bytearray.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adds support for ValueTypeBytes to Jaeger's trace to jaegerproto translator."

# One or more tracking issues related to the change
issues: [14574]

# (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: