@@ -373,6 +373,27 @@ def _assert_uninstrumented_rpc(
373373 assert wrapped ._span_attributes is None
374374
375375
376+ _BASE_SPAN_ATTRIBUTES = {
377+ "rpc.system" : "grpc" ,
378+ "rpc.service" : "google.cloud.secretmanager.v1.SecretManagerService" ,
379+ "rpc.method" : "ListSecrets" ,
380+ "gcp.client.service" : "SecretManagerService" ,
381+ }
382+
383+ _DEFAULT_SPAN_ATTRIBUTES = {
384+ ** _BASE_SPAN_ATTRIBUTES ,
385+ "gcp.client.repo" : "googleapis/google-cloud-python" ,
386+ }
387+
388+ _ASYNC_SERVICE_DEFAULT_SPAN_ATTRIBUTES = {
389+ "rpc.system" : "grpc" ,
390+ "rpc.service" : "google.test.AsyncService" ,
391+ "rpc.method" : "AsyncMethod" ,
392+ "gcp.client.service" : "AsyncService" ,
393+ "gcp.client.repo" : "googleapis/google-cloud-python" ,
394+ }
395+
396+
376397@pytest .fixture
377398def mock_otel (monkeypatch ):
378399 """Provides a mocked OpenTelemetry environment with tracing enabled."""
@@ -473,13 +494,7 @@ def test_wrap_method_otel_tracing_enabled_success(mock_otel, method_name):
473494 mock_otel .tracer .start_as_current_span .assert_called_once_with (
474495 "google.cloud.secretmanager.v1.SecretManagerService/ListSecrets" ,
475496 kind = "CLIENT" ,
476- attributes = {
477- "rpc.system" : "grpc" ,
478- "rpc.service" : "google.cloud.secretmanager.v1.SecretManagerService" ,
479- "rpc.method" : "ListSecrets" ,
480- "gcp.client.service" : "SecretManagerService" ,
481- "gcp.client.repo" : "googleapis/google-cloud-python" ,
482- },
497+ attributes = _DEFAULT_SPAN_ATTRIBUTES ,
483498 )
484499
485500
@@ -630,13 +645,7 @@ def test_wrap_method_async_otel_tracing(mock_otel):
630645 mock_otel .tracer .start_as_current_span .assert_called_once_with (
631646 "google.test.AsyncService/AsyncMethod" ,
632647 kind = "CLIENT" ,
633- attributes = {
634- "rpc.system" : "grpc" ,
635- "rpc.service" : "google.test.AsyncService" ,
636- "rpc.method" : "AsyncMethod" ,
637- "gcp.client.service" : "AsyncService" ,
638- "gcp.client.repo" : "googleapis/google-cloud-python" ,
639- },
648+ attributes = _ASYNC_SERVICE_DEFAULT_SPAN_ATTRIBUTES ,
640649 )
641650
642651
@@ -685,10 +694,7 @@ def test_wrap_method_otel_tracing_attributes_with_client_info(mock_otel):
685694 "google.cloud.secretmanager.v1.SecretManagerService/ListSecrets" ,
686695 kind = "CLIENT" ,
687696 attributes = {
688- "rpc.system" : "grpc" ,
689- "rpc.service" : "google.cloud.secretmanager.v1.SecretManagerService" ,
690- "rpc.method" : "ListSecrets" ,
691- "gcp.client.service" : "SecretManagerService" ,
697+ ** _DEFAULT_SPAN_ATTRIBUTES ,
692698 "gcp.client.repo" : "googleapis/google-cloud-python-test" ,
693699 "gcp.client.version" : "2.16.0" ,
694700 "gcp.client.artifact" : "google-cloud-secretmanager" ,
@@ -716,11 +722,7 @@ def test_wrap_method_otel_tracing_attributes_fallback_gapic_version(mock_otel):
716722 "google.cloud.secretmanager.v1.SecretManagerService/ListSecrets" ,
717723 kind = "CLIENT" ,
718724 attributes = {
719- "rpc.system" : "grpc" ,
720- "rpc.service" : "google.cloud.secretmanager.v1.SecretManagerService" ,
721- "rpc.method" : "ListSecrets" ,
722- "gcp.client.service" : "SecretManagerService" ,
723- "gcp.client.repo" : "googleapis/google-cloud-python" ,
725+ ** _DEFAULT_SPAN_ATTRIBUTES ,
724726 "gcp.client.version" : "1.5.0" ,
725727 },
726728 )
@@ -741,12 +743,7 @@ def test_wrap_method_otel_tracing_attributes_no_client_info(mock_otel):
741743 mock_otel .tracer .start_as_current_span .assert_called_once_with (
742744 "google.cloud.secretmanager.v1.SecretManagerService/ListSecrets" ,
743745 kind = "CLIENT" ,
744- attributes = {
745- "rpc.system" : "grpc" ,
746- "rpc.service" : "google.cloud.secretmanager.v1.SecretManagerService" ,
747- "rpc.method" : "ListSecrets" ,
748- "gcp.client.service" : "SecretManagerService" ,
749- },
746+ attributes = _BASE_SPAN_ATTRIBUTES ,
750747 )
751748
752749
@@ -793,11 +790,7 @@ def test_wrap_method_async_otel_tracing_with_client_info(mock_otel):
793790 "google.test.AsyncService/AsyncMethod" ,
794791 kind = "CLIENT" ,
795792 attributes = {
796- "rpc.system" : "grpc" ,
797- "rpc.service" : "google.test.AsyncService" ,
798- "rpc.method" : "AsyncMethod" ,
799- "gcp.client.service" : "AsyncService" ,
800- "gcp.client.repo" : "googleapis/google-cloud-python" ,
793+ ** _ASYNC_SERVICE_DEFAULT_SPAN_ATTRIBUTES ,
801794 "gcp.client.version" : "3.0.0" ,
802795 },
803796 )
0 commit comments