mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-20 03:30:02 +02:00
fix(tracestate): drop right-most member in tracestate (#2592)
* todo(tracestate): drop right-most member in tracestate Signed-off-by: 1046102779 <seachen@tencent.com> * fix(tracestate): drop right-most member in tracestate Signed-off-by: 1046102779 <seachen@tencent.com> * fix(tracestate): drop right-most member in tracestate Signed-off-by: 1046102779 <seachen@tencent.com> * fix(tracestate): drop right-most member in tracestate Signed-off-by: 1046102779 <seachen@tencent.com> * fix(tracestate): drop right-most member in tracestate Signed-off-by: 1046102779 <seachen@tencent.com> * Update trace/tracestate.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
d51d1b3090
commit
94b1848a56
@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- For tracestate's members, prepend the new element and remove the oldest one, which is over capacity (#2592)
|
||||||
- Add event and link drop counts to the exported data from the `oltptrace` exporter. (#2601)
|
- Add event and link drop counts to the exported data from the `oltptrace` exporter. (#2601)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -171,7 +171,8 @@ func (ts TraceState) Get(key string) string {
|
|||||||
// specification an error is returned with the original TraceState.
|
// specification an error is returned with the original TraceState.
|
||||||
//
|
//
|
||||||
// If adding a new list-member means the TraceState would have more members
|
// If adding a new list-member means the TraceState would have more members
|
||||||
// than is allowed an error is returned instead with the original TraceState.
|
// then is allowed, the new list-member will be inserted and the right-most
|
||||||
|
// list-member will be dropped in the returned TraceState.
|
||||||
func (ts TraceState) Insert(key, value string) (TraceState, error) {
|
func (ts TraceState) Insert(key, value string) (TraceState, error) {
|
||||||
m, err := newMember(key, value)
|
m, err := newMember(key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -179,17 +180,10 @@ func (ts TraceState) Insert(key, value string) (TraceState, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cTS := ts.Delete(key)
|
cTS := ts.Delete(key)
|
||||||
if cTS.Len()+1 > maxListMembers {
|
if cTS.Len()+1 <= maxListMembers {
|
||||||
// TODO (MrAlias): When the second version of the Trace Context
|
cTS.list = append(cTS.list, member{})
|
||||||
// specification is published this needs to not return an error.
|
|
||||||
// Instead it should drop the "right-most" member and insert the new
|
|
||||||
// member at the front.
|
|
||||||
//
|
|
||||||
// https://github.com/w3c/trace-context/pull/448
|
|
||||||
return ts, fmt.Errorf("failed to insert: %w", errMemberNumber)
|
|
||||||
}
|
}
|
||||||
|
// When the number of members exceeds capacity, drop the "right-most".
|
||||||
cTS.list = append(cTS.list, member{})
|
|
||||||
copy(cTS.list[1:], cTS.list)
|
copy(cTS.list[1:], cTS.list)
|
||||||
cTS.list[0] = m
|
cTS.list[0] = m
|
||||||
|
|
||||||
|
@ -482,14 +482,20 @@ func TestTraceStateInsert(t *testing.T) {
|
|||||||
err: errInvalidKey,
|
err: errInvalidKey,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "too many entries",
|
name: "drop the right-most member(oldest) in queue",
|
||||||
tracestate: maxMembers,
|
tracestate: maxMembers,
|
||||||
key: "keyx",
|
key: "keyx",
|
||||||
value: "valx",
|
value: "valx",
|
||||||
expected: maxMembers,
|
expected: func() TraceState {
|
||||||
err: errMemberNumber,
|
// Prepend the new element and remove the oldest one, which is over capacity.
|
||||||
},
|
return TraceState{
|
||||||
}
|
list: append(
|
||||||
|
[]member{{Key: "keyx", Value: "valx"}},
|
||||||
|
maxMembers.list[:len(maxMembers.list)-1]...,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}(),
|
||||||
|
}}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user