3131from opentelemetry .semconv ._incubating .attributes import (
3232 gen_ai_attributes as GenAIAttributes ,
3333)
34+ from opentelemetry .semconv ._incubating .attributes .error_attributes import (
35+ ERROR_TYPE ,
36+ )
3437from opentelemetry .semconv ._incubating .metrics .gen_ai_metrics import (
3538 GEN_AI_CLIENT_OPERATION_DURATION ,
3639 GEN_AI_CLIENT_TOKEN_USAGE ,
@@ -270,7 +273,9 @@ def assert_message_in_logs(log, event_name, expected_content, parent_span):
270273 assert_log_parent (log , parent_span )
271274
272275
273- def assert_all_metric_attributes (data_point , operation_name , model ):
276+ def assert_all_metric_attributes (
277+ data_point , operation_name : str , model : str , error_type : str | None = None
278+ ):
274279 assert GenAIAttributes .GEN_AI_OPERATION_NAME in data_point .attributes
275280 assert (
276281 data_point .attributes [GenAIAttributes .GEN_AI_OPERATION_NAME ]
@@ -284,13 +289,20 @@ def assert_all_metric_attributes(data_point, operation_name, model):
284289 assert GenAIAttributes .GEN_AI_REQUEST_MODEL in data_point .attributes
285290 assert data_point .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == model
286291
292+ if error_type is not None :
293+ assert ERROR_TYPE in data_point .attributes
294+ assert data_point .attributes [ERROR_TYPE ] == error_type
295+ else :
296+ assert ERROR_TYPE not in data_point .attributes
297+
287298
288299def assert_metrics (
289300 resource_metrics : ResourceMetrics ,
290301 operation_name : str ,
291302 model : str ,
292303 input_tokens : float | None = None ,
293304 output_tokens : float | None = None ,
305+ error_type : str | None = None ,
294306):
295307 assert len (resource_metrics ) == 1
296308
@@ -309,7 +321,9 @@ def assert_metrics(
309321
310322 duration_point = duration_metric .data .data_points [0 ]
311323 assert duration_point .sum > 0
312- assert_all_metric_attributes (duration_point , operation_name , model )
324+ assert_all_metric_attributes (
325+ duration_point , operation_name , model , error_type
326+ )
313327 assert duration_point .explicit_bounds == tuple (
314328 _GEN_AI_CLIENT_OPERATION_DURATION_BUCKETS
315329 )
0 commit comments