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

trace: ParseTraceState ignores duplicated tracestate keys #4638

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- `go.opentelemetry.io/otel/bridge/opencensus.NewMetricProducer` returns a `*MetricProducer` struct instead of the metric.Producer interface. (#4583)
- `ParseTraceState` in `go.opentelemetry.io/otel/trace` ignores duplicated tracestate keys. (#4638)

## [1.19.0/0.42.0/0.0.7] 2023-09-28

Expand Down
7 changes: 3 additions & 4 deletions trace/tracestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const (
errInvalidValue errorConst = "invalid tracestate value"
errInvalidMember errorConst = "invalid tracestate list-member"
errMemberNumber errorConst = "too many list-members in tracestate"
errDuplicate errorConst = "duplicate list-member in tracestate"
)

var (
Expand Down Expand Up @@ -87,8 +86,8 @@ func (m member) String() string {
// (https://www.w3.org/TR/trace-context-1). All operations that create or copy
// a TraceState do so by validating all input and will only produce TraceState
// that conform to the specification. Specifically, this means that all
// list-member's key/value pairs are valid, no duplicate list-members exist,
// and the maximum number of list-members (32) is not exceeded.
// list-member's key/value pairs are valid, and the maximum number of
// list-members (32) is not exceeded.
type TraceState struct { //nolint:revive // revive complains about stutter of `trace.TraceState`
// list is the members in order.
list []member
Expand Down Expand Up @@ -121,7 +120,7 @@ func ParseTraceState(tracestate string) (TraceState, error) {
}

if _, ok := found[m.Key]; ok {
return TraceState{}, wrapErr(errDuplicate)
continue // Duplicate is ignored per https://github.com/w3c/trace-context/blob/551a5b0855171281e98b4c2a814bf9e1f837cd53/test/test.py#L563-L568.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a link to W3C unit tests. Can you instead link to the part of the W3C specification that describes this behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not found anything better than the test code in the specification that describes it. See: https://github.com/instana/trace-context/blob/master/spec/20-http_request_header_format.md

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@pellared pellared Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any other suggestion or can this comment be resolved?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this behavior is only mentioned in the editor draft of the W3C trace-context as optional. This PR seems premature given that unreleased state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to draft

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this behavior is only mentioned in the editor draft of the W3C trace-context as optional.

For me even the editor draft does not clearly defines this behavior thus I created w3c/trace-context#548

}
found[m.Key] = struct{}{}

Expand Down
16 changes: 14 additions & 2 deletions trace/tracestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ var testcases = []struct {
{
name: "duplicate with the same value",
in: "foo=1,foo=1",
err: errDuplicate,
out: "foo=1",
tracestate: TraceState{list: []member{
{
Key: "foo",
Value: "1",
},
}},
},
{
name: "duplicate with different values",
in: "foo=1,foo=2",
err: errDuplicate,
out: "foo=1",
tracestate: TraceState{list: []member{
{
Key: "foo",
Value: "1",
},
}},
},
{
name: "improperly formatted key/value pair",
Expand Down
Loading