@@ -416,83 +416,6 @@ def test_grpc_client_request_hook():
416416 mock_span_custom .update_name .assert_not_called ()
417417
418418
419- def test_extract_error_attributes_none ():
420- """Proves that _extract_error_attributes returns an empty dict when exception is None."""
421- assert _observability ._extract_error_attributes (None ) == {}
422-
423-
424- def test_extract_error_attributes_standard_exception ():
425- """Proves that _extract_error_attributes returns an empty dict for standard exceptions without ErrorInfo."""
426- assert (
427- _observability ._extract_error_attributes (ValueError ("unexpected error" )) == {}
428- )
429-
430-
431- def test_extract_error_attributes_with_error_info ():
432- """Proves that _extract_error_attributes extracts domain, error.type, and metadata from ErrorInfo."""
433- error_info = types .SimpleNamespace (
434- domain = "googleapis.com" ,
435- reason = "SERVICE_DISABLED" ,
436- metadata = {
437- "service" : "secretmanager.googleapis.com" ,
438- "consumer" : "projects/123" ,
439- },
440- )
441- exc = types .SimpleNamespace (error_info = error_info )
442- attrs = _observability ._extract_error_attributes (exc )
443- assert attrs == {
444- "gcp.errors.domain" : "googleapis.com" ,
445- "error.type" : "SERVICE_DISABLED" ,
446- "gcp.errors.metadata.service" : "secretmanager.googleapis.com" ,
447- "gcp.errors.metadata.consumer" : "projects/123" ,
448- }
449-
450-
451- def test_extract_error_attributes_from_grpc_trailing_metadata (monkeypatch ):
452- """Proves that _extract_error_attributes parses error_info from gRPC trailing metadata."""
453- from google .api_core import exceptions
454-
455- mock_exc = mock .Mock ()
456- mock_exc .error_info = None
457- mock_exc .trailing_metadata = mock .Mock ()
458-
459- parsed_error_info = types .SimpleNamespace (
460- domain = "googleapis.com" ,
461- reason = "RESOURCE_EXHAUSTED" ,
462- metadata = {"quota_limit" : "100" },
463- )
464-
465- monkeypatch .setattr (
466- exceptions ,
467- "_parse_grpc_error_details" ,
468- mock .Mock (return_value = (None , parsed_error_info )),
469- )
470-
471- attrs = _observability ._extract_error_attributes (mock_exc )
472- assert attrs == {
473- "gcp.errors.domain" : "googleapis.com" ,
474- "error.type" : "RESOURCE_EXHAUSTED" ,
475- "gcp.errors.metadata.quota_limit" : "100" ,
476- }
477-
478-
479- def test_extract_error_attributes_trailing_metadata_failure (monkeypatch ):
480- """Proves that _extract_error_attributes safely handles exceptions during trailing metadata parsing."""
481- from google .api_core import exceptions
482-
483- mock_exc = mock .Mock ()
484- mock_exc .error_info = None
485- mock_exc .trailing_metadata = mock .Mock ()
486-
487- monkeypatch .setattr (
488- exceptions ,
489- "_parse_grpc_error_details" ,
490- mock .Mock (side_effect = RuntimeError ("Parse failed" )),
491- )
492-
493- assert _observability ._extract_error_attributes (mock_exc ) == {}
494-
495-
496419def test_get_otel_interceptor_with_api_endpoint (monkeypatch ):
497420 """Proves that get_otel_interceptor injects server.address, server.port, and url.domain when api_endpoint is set."""
498421 monkeypatch .setenv ("GOOGLE_SDK_EXPERIMENTAL_PYTHON_TRACING_ENABLED" , "true" )
0 commit comments