Skip to content

Commit c8c9a54

Browse files
Add RPC_GRPC_STATUS_CODE assertions to client error tests
Verify that error spans include the correct gRPC status code attribute (INVALID_ARGUMENT) in both sync and async client interceptor tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b634dee commit c8c9a54

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ async def test_error_simple(self):
224224
span.status.status_code,
225225
trace.StatusCode.ERROR,
226226
)
227+
self.assertEqual(
228+
span.attributes[RPC_GRPC_STATUS_CODE],
229+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
230+
)
227231

228232
async def test_error_unary_stream(self):
229233
with self.assertRaises(grpc.RpcError):
@@ -237,6 +241,10 @@ async def test_error_unary_stream(self):
237241
span.status.status_code,
238242
trace.StatusCode.ERROR,
239243
)
244+
self.assertEqual(
245+
span.attributes[RPC_GRPC_STATUS_CODE],
246+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
247+
)
240248

241249
async def test_error_stream_unary(self):
242250
with self.assertRaises(grpc.RpcError):
@@ -249,6 +257,10 @@ async def test_error_stream_unary(self):
249257
span.status.status_code,
250258
trace.StatusCode.ERROR,
251259
)
260+
self.assertEqual(
261+
span.attributes[RPC_GRPC_STATUS_CODE],
262+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
263+
)
252264

253265
async def test_error_stream_stream(self):
254266
with self.assertRaises(grpc.RpcError):
@@ -264,6 +276,10 @@ async def test_error_stream_stream(self):
264276
span.status.status_code,
265277
trace.StatusCode.ERROR,
266278
)
279+
self.assertEqual(
280+
span.attributes[RPC_GRPC_STATUS_CODE],
281+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
282+
)
267283

268284
# pylint:disable=no-self-use
269285
async def test_client_interceptor_trace_context_propagation(self):

instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ def test_error_simple(self):
277277
span.status.status_code,
278278
trace.StatusCode.ERROR,
279279
)
280+
self.assertEqual(
281+
span.attributes[RPC_GRPC_STATUS_CODE],
282+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
283+
)
280284

281285
def test_error_stream_unary(self):
282286
with self.assertRaises(grpc.RpcError):
@@ -289,6 +293,10 @@ def test_error_stream_unary(self):
289293
span.status.status_code,
290294
trace.StatusCode.ERROR,
291295
)
296+
self.assertEqual(
297+
span.attributes[RPC_GRPC_STATUS_CODE],
298+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
299+
)
292300

293301
def test_error_unary_stream(self):
294302
with self.assertRaises(grpc.RpcError):
@@ -301,6 +309,10 @@ def test_error_unary_stream(self):
301309
span.status.status_code,
302310
trace.StatusCode.ERROR,
303311
)
312+
self.assertEqual(
313+
span.attributes[RPC_GRPC_STATUS_CODE],
314+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
315+
)
304316

305317
def test_error_stream_stream(self):
306318
with self.assertRaises(grpc.RpcError):
@@ -313,6 +325,10 @@ def test_error_stream_stream(self):
313325
span.status.status_code,
314326
trace.StatusCode.ERROR,
315327
)
328+
self.assertEqual(
329+
span.attributes[RPC_GRPC_STATUS_CODE],
330+
grpc.StatusCode.INVALID_ARGUMENT.value[0],
331+
)
316332

317333
def test_client_interceptor_falsy_response(
318334
self,

0 commit comments

Comments
 (0)