Skip to content

Enhancement: Support scope attributes (zipkin exporter) #40713

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/zipkin/zipkinv2/from_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func resourceSpansToZipkinSpans(rs ptrace.ResourceSpans, estSpanCount int) ([]*z
}

func extractScopeTags(il pcommon.InstrumentationScope, zTags map[string]string) {
attrs := il.Attributes()
for k, v := range attrs.All() {
zTags[k] = v.AsString()
}

if ilName := il.Name(); ilName != "" {
zTags[string(conventions.OtelLibraryNameKey)] = ilName
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/translator/zipkin/zipkinv2/from_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,45 @@ func TestInternalTracesToZipkinSpans(t *testing.T) {
}
}

func TestExtractScopeTags(t *testing.T) {
tests := []struct {
name string
scopeCfg func(pcommon.InstrumentationScope)
res map[string]string
}{
{
name: "empty scope",
scopeCfg: func(il pcommon.InstrumentationScope) {},
res: map[string]string{},
},
{
name: "with attributes and name/version",
scopeCfg: func(il pcommon.InstrumentationScope) {
il.SetName("otel-lib")
il.SetVersion("v1.2.3")
il.Attributes().PutStr("custom.key", "custom.val")
},
res: map[string]string{
"custom.key": "custom.val",
"otel.library.name": "otel-lib",
"otel.library.version": "v1.2.3",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
il := pcommon.NewInstrumentationScope()
tt.scopeCfg(il)

got := map[string]string{}
extractScopeTags(il, got)

assert.Equal(t, tt.res, got)
})
}
}

func TestInternalTracesToZipkinSpansAndBack(t *testing.T) {
tds, err := goldendataset.GenerateTraces(
"../../../../internal/coreinternal/goldendataset/testdata/generated_pict_pairs_traces.txt",
Expand Down