@@ -196,93 +196,104 @@ func TestDeprecatedStatusCode(t *testing.T) {
196196 // See specification for handling status code here:
197197 // https://github.com/open-telemetry/opentelemetry-proto/blob/59c488bfb8fb6d0458ad6425758b70259ff4a2bd/opentelemetry/proto/trace/v1/trace.proto#L231
198198 tests := []struct {
199- sendCode otlptrace.Status_StatusCode
200- sendDeprecatedCode otlptrace.Status_DeprecatedStatusCode
201- expectedRcvCode otlptrace.Status_StatusCode
199+ sendCode otlptrace.Status_StatusCode
200+ sendDeprecatedCode otlptrace.Status_DeprecatedStatusCode
201+ expectedRcvCode otlptrace.Status_StatusCode
202+ expectedDeprecatedCode otlptrace.Status_DeprecatedStatusCode
202203 }{
203204 {
204205 // If code==STATUS_CODE_UNSET then the value of `deprecated_code` is the
205206 // carrier of the overall status according to these rules:
206207 //
207208 // if deprecated_code==DEPRECATED_STATUS_CODE_OK then the receiver MUST interpret
208209 // the overall status to be STATUS_CODE_UNSET.
209- sendCode : otlptrace .Status_STATUS_CODE_UNSET ,
210- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
211- expectedRcvCode : otlptrace .Status_STATUS_CODE_UNSET ,
210+ sendCode : otlptrace .Status_STATUS_CODE_UNSET ,
211+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
212+ expectedRcvCode : otlptrace .Status_STATUS_CODE_UNSET ,
213+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
212214 },
213215 {
214216 // if deprecated_code!=DEPRECATED_STATUS_CODE_OK then the receiver MUST interpret
215217 // the overall status to be STATUS_CODE_ERROR.
216- sendCode : otlptrace .Status_STATUS_CODE_UNSET ,
217- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
218- expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
218+ sendCode : otlptrace .Status_STATUS_CODE_UNSET ,
219+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_ABORTED ,
220+ expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
221+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_ABORTED ,
219222 },
220223 {
221224 // If code!=STATUS_CODE_UNSET then the value of `deprecated_code` MUST be
222- // ignored, the `code` field is the sole carrier of the status.
223- sendCode : otlptrace .Status_STATUS_CODE_OK ,
224- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
225- expectedRcvCode : otlptrace .Status_STATUS_CODE_OK ,
225+ // overwritten, the `code` field is the sole carrier of the status.
226+ sendCode : otlptrace .Status_STATUS_CODE_OK ,
227+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
228+ expectedRcvCode : otlptrace .Status_STATUS_CODE_OK ,
229+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
226230 },
227231 {
228232 // If code!=STATUS_CODE_UNSET then the value of `deprecated_code` MUST be
229- // ignored, the `code` field is the sole carrier of the status.
230- sendCode : otlptrace .Status_STATUS_CODE_OK ,
231- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
232- expectedRcvCode : otlptrace .Status_STATUS_CODE_OK ,
233+ // overwritten, the `code` field is the sole carrier of the status.
234+ sendCode : otlptrace .Status_STATUS_CODE_OK ,
235+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
236+ expectedRcvCode : otlptrace .Status_STATUS_CODE_OK ,
237+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
233238 },
234239 {
235240 // If code!=STATUS_CODE_UNSET then the value of `deprecated_code` MUST be
236- // ignored, the `code` field is the sole carrier of the status.
237- sendCode : otlptrace .Status_STATUS_CODE_ERROR ,
238- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
239- expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
241+ // overwritten, the `code` field is the sole carrier of the status.
242+ sendCode : otlptrace .Status_STATUS_CODE_ERROR ,
243+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_OK ,
244+ expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
245+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
240246 },
241247 {
242248 // If code!=STATUS_CODE_UNSET then the value of `deprecated_code` MUST be
243- // ignored, the `code` field is the sole carrier of the status.
244- sendCode : otlptrace .Status_STATUS_CODE_ERROR ,
245- sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
246- expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
249+ // overwritten, the `code` field is the sole carrier of the status.
250+ sendCode : otlptrace .Status_STATUS_CODE_ERROR ,
251+ sendDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
252+ expectedRcvCode : otlptrace .Status_STATUS_CODE_ERROR ,
253+ expectedDeprecatedCode : otlptrace .Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR ,
247254 },
248255 }
249256
250257 for _ , test := range tests {
251- resourceSpans := []* otlptrace.ResourceSpans {
252- {
253- InstrumentationLibrarySpans : []* otlptrace.InstrumentationLibrarySpans {
254- {
255- Spans : []* otlptrace.Span {
256- {
257- Status : otlptrace.Status {
258- Code : test .sendCode ,
259- DeprecatedCode : test .sendDeprecatedCode ,
258+ t .Run (test .sendCode .String ()+ "/" + test .sendDeprecatedCode .String (), func (t * testing.T ) {
259+ resourceSpans := []* otlptrace.ResourceSpans {
260+ {
261+ InstrumentationLibrarySpans : []* otlptrace.InstrumentationLibrarySpans {
262+ {
263+ Spans : []* otlptrace.Span {
264+ {
265+ Status : otlptrace.Status {
266+ Code : test .sendCode ,
267+ DeprecatedCode : test .sendDeprecatedCode ,
268+ },
260269 },
261270 },
262271 },
263272 },
264273 },
265- },
266- }
274+ }
267275
268- req := & collectortrace.ExportTraceServiceRequest {
269- ResourceSpans : resourceSpans ,
270- }
276+ req := & collectortrace.ExportTraceServiceRequest {
277+ ResourceSpans : resourceSpans ,
278+ }
279+
280+ traceSink .Reset ()
271281
272- traceSink .Reset ()
282+ resp , err := traceClient .Export (context .Background (), req )
283+ require .NoError (t , err , "Failed to export trace: %v" , err )
284+ require .NotNil (t , resp , "The response is missing" )
273285
274- resp , err := traceClient .Export (context .Background (), req )
275- require .NoError (t , err , "Failed to export trace: %v" , err )
276- require .NotNil (t , resp , "The response is missing" )
286+ require .Equal (t , 1 , len (traceSink .AllTraces ()), "unexpected length: %v" , len (traceSink .AllTraces ()))
277287
278- require . Equal ( t , 1 , len ( traceSink .AllTraces ()), "unexpected length: %v" , len ( traceSink . AllTraces ()) )
288+ rcvdStatus := traceSink .AllTraces ()[ 0 ]. ResourceSpans (). At ( 0 ). InstrumentationLibrarySpans (). At ( 0 ). Spans (). At ( 0 ). Status ( )
279289
280- rcvdStatus := traceSink .AllTraces ()[0 ].ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).Spans ().At (0 ).Status ()
290+ // Check that Code is as expected.
291+ assert .EqualValues (t , rcvdStatus .Code (), test .expectedRcvCode )
281292
282- // Check that Code is as expected.
283- assert .EqualValues (t , rcvdStatus .Code (), test .expectedRcvCode )
293+ spanProto := pdata .TracesToOtlp (traceSink .AllTraces ()[0 ])[0 ].InstrumentationLibrarySpans [0 ].Spans [0 ]
284294
285- // Check that DeprecatedCode is passed as is.
286- assert .EqualValues (t , rcvdStatus .DeprecatedCode (), test .sendDeprecatedCode )
295+ // Check that DeprecatedCode is passed as is.
296+ assert .EqualValues (t , spanProto .Status .DeprecatedCode , test .expectedDeprecatedCode )
297+ })
287298 }
288299}
0 commit comments