-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added README entry for the feature flag - Added missing mutex lock around reading trace data in `SetAttrOnScopeSpans` - Added tests + benchmarks for `SetAttrOnScopeSpans`
- Loading branch information
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# 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: processor/tailsampling | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: | | ||
Adds support for optionally recording the policy (and any composite policy) associated with an inclusive tail processor sampling decision. | ||
This functionality is disabled by default, you can enable it by passing the following feature flag to the collector: `+processor.tailsamplingprocessor.recordpolicy` | ||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [35180] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
processor/tailsamplingprocessor/internal/sampling/util_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package sampling | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"testing" | ||
) | ||
|
||
func TestSetAttrOnScopeSpans_Empty(t *testing.T) { | ||
traces := ptrace.NewTraces() | ||
traceData := &TraceData{ | ||
ReceivedBatches: traces, | ||
} | ||
|
||
SetAttrOnScopeSpans(traceData, "test.attr", "value") | ||
} | ||
|
||
func TestSetAttrOnScopeSpans_Many(t *testing.T) { | ||
|
||
assertAttrExists := func(t *testing.T, attrs pcommon.Map, key string, value string) { | ||
v, ok := attrs.Get(key) | ||
assert.True(t, ok) | ||
assert.Equal(t, value, v.AsString()) | ||
} | ||
|
||
traces := ptrace.NewTraces() | ||
|
||
rs1 := traces.ResourceSpans().AppendEmpty() | ||
ss1 := rs1.ScopeSpans().AppendEmpty() | ||
span1 := ss1.Spans().AppendEmpty() | ||
span2 := ss1.Spans().AppendEmpty() | ||
ss2 := rs1.ScopeSpans().AppendEmpty() | ||
span3 := ss2.Spans().AppendEmpty() | ||
rs2 := traces.ResourceSpans().AppendEmpty() | ||
ss3 := rs2.ScopeSpans().AppendEmpty() | ||
span4 := ss3.Spans().AppendEmpty() | ||
|
||
traceData := &TraceData{ | ||
ReceivedBatches: traces, | ||
} | ||
|
||
SetAttrOnScopeSpans(traceData, "test.attr", "value") | ||
|
||
assertAttrExists(t, ss1.Scope().Attributes(), "test.attr", "value") | ||
assertAttrExists(t, ss2.Scope().Attributes(), "test.attr", "value") | ||
assertAttrExists(t, ss3.Scope().Attributes(), "test.attr", "value") | ||
|
||
_, ok := span1.Attributes().Get("test.attr") | ||
assert.False(t, ok) | ||
_, ok = span2.Attributes().Get("test.attr") | ||
assert.False(t, ok) | ||
_, ok = span3.Attributes().Get("test.attr") | ||
assert.False(t, ok) | ||
_, ok = span4.Attributes().Get("test.attr") | ||
assert.False(t, ok) | ||
} | ||
|
||
func BenchmarkSetAttrOnScopeSpans(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
|
||
traces := ptrace.NewTraces() | ||
|
||
for i := 0; i < 5; i++ { | ||
rs := traces.ResourceSpans().AppendEmpty() | ||
ss1 := rs.ScopeSpans().AppendEmpty() | ||
ss1.Spans().AppendEmpty() | ||
ss1.Spans().AppendEmpty() | ||
ss1.Spans().AppendEmpty() | ||
|
||
ss2 := rs.ScopeSpans().AppendEmpty() | ||
ss2.Spans().AppendEmpty() | ||
ss2.Spans().AppendEmpty() | ||
|
||
ss3 := rs.ScopeSpans().AppendEmpty() | ||
ss3.Spans().AppendEmpty() | ||
} | ||
|
||
traceData := &TraceData{ | ||
ReceivedBatches: traces, | ||
} | ||
|
||
b.StartTimer() | ||
SetAttrOnScopeSpans(traceData, "test.attr", "value") | ||
b.StopTimer() | ||
} | ||
} |