Skip to content

Commit

Permalink
[zipkin receiver] Fix checking status codes from tags (#24659)
Browse files Browse the repository at this point in the history
**Description:** 

It looks like there was a difference in expectations when it came to
parsing span status in tags, this looks to resolve this and provide
backwards support for existing implementations

**Link to tracking Issue:** 
Fixes
#14965

**Testing:**

Added new unit test to validate span status is correctly set.

**Documentation:** 
NA
  • Loading branch information
MovieStoreGuy authored Jul 31, 2023
1 parent cce00b7 commit 501e5c5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .chloggen/msg_fixup-zipkin-status-code-parsing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Respects zipkin's serialised status tags to be converted to span status

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [14965]

# (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:
5 changes: 5 additions & 0 deletions pkg/translator/zipkin/zipkinv2/to_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,9 @@ var statusCodeValue = map[string]int32{
"STATUS_CODE_UNSET": 0,
"STATUS_CODE_OK": 1,
"STATUS_CODE_ERROR": 2,
// As reported in https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/14965
// The Zipkin exporter used a different set of names when serializing span state.
"Unset": 0,
"Ok": 1,
"Error": 2,
}
93 changes: 93 additions & 0 deletions pkg/translator/zipkin/zipkinv2/to_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,99 @@ func TestZipkinSpansToInternalTraces(t *testing.T) {
td: generateTraceSingleSpanErrorStatus(),
err: nil,
},
{
name: "span ok status",
zs: []*zipkinmodel.SpanModel{
{
SpanContext: zipkinmodel.SpanContext{
TraceID: convertTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80}),
ID: convertSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8}),
},
Name: "min.data",
Tags: map[string]string{
"otel.status_code": "Ok",
},
Timestamp: time.Unix(1596911098, 294000000),
Duration: 1000000,
Shared: false,
},
},
td: func() ptrace.Traces {
td := ptrace.NewTraces()
span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80})
span.SetSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8})
span.SetName("min.data")
span.Status().SetCode(ptrace.StatusCodeOk)
span.SetStartTimestamp(1596911098294000000)
span.SetEndTimestamp(1596911098295000000)
return td
}(),
},
{
name: "span unset status",
zs: []*zipkinmodel.SpanModel{
{
SpanContext: zipkinmodel.SpanContext{
TraceID: convertTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80}),
ID: convertSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8}),
},
Name: "min.data",
Tags: map[string]string{
"otel.status_code": "Unset",
},
Timestamp: time.Unix(1596911098, 294000000),
Duration: 1000000,
Shared: false,
},
},
td: func() ptrace.Traces {
td := ptrace.NewTraces()
span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80})
span.SetSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8})
span.SetName("min.data")
span.Status().SetCode(ptrace.StatusCodeUnset)
span.SetStartTimestamp(1596911098294000000)
span.SetEndTimestamp(1596911098295000000)
return td
}(),
},
{
name: "span error status",
zs: []*zipkinmodel.SpanModel{
{
SpanContext: zipkinmodel.SpanContext{
TraceID: convertTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80}),
ID: convertSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8}),
},
Name: "min.data",
Tags: map[string]string{
"otel.status_code": "Error",
},
Timestamp: time.Unix(1596911098, 294000000),
Duration: 1000000,
Shared: false,
},
},
td: func() ptrace.Traces {
td := ptrace.NewTraces()
span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(
[16]byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80})
span.SetSpanID([8]byte{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8})
span.SetName("min.data")
span.Status().SetCode(ptrace.StatusCodeError)
span.SetStartTimestamp(1596911098294000000)
span.SetEndTimestamp(1596911098295000000)
return td
}(),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit 501e5c5

Please sign in to comment.