52
52
from test_utils .retry import RetryResult
53
53
from test_utils .system import unique_resource_id
54
54
from tests ._fixtures import DDL_STATEMENTS
55
- from tests ._helpers import OpenTelemetryBase
55
+ from tests ._helpers import OpenTelemetryBase , HAS_OPENTELEMETRY_INSTALLED
56
56
57
57
58
58
CREATE_INSTANCE = os .getenv ("GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE" ) is not None
@@ -805,11 +805,11 @@ def tearDownClass(cls):
805
805
cls ._db .drop ()
806
806
807
807
def setUp (self ):
808
- super ().setUp ()
808
+ super (TestSessionAPI , self ).setUp ()
809
809
self .to_delete = []
810
810
811
811
def tearDown (self ):
812
- super ().tearDown ()
812
+ super (TestSessionAPI , self ).tearDown ()
813
813
for doomed in self .to_delete :
814
814
doomed .delete ()
815
815
@@ -835,39 +835,45 @@ def test_batch_insert_then_read(self):
835
835
rows = list (snapshot .read (self .TABLE , self .COLUMNS , self .ALL ))
836
836
self ._check_rows_data (rows )
837
837
838
- span_list = self .memory_exporter .get_finished_spans ()
839
- self .assertEqual (len (span_list ), 4 )
840
- self .assertSpanAttributes (
841
- "CloudSpanner.GetSession" ,
842
- attributes = dict (
843
- BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }, session_found = True
844
- ),
845
- span = span_list [0 ],
846
- )
847
- self .assertSpanAttributes (
848
- "CloudSpanner.Commit" ,
849
- attributes = dict (
850
- BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }, num_mutations = 2
851
- ),
852
- span = span_list [1 ],
853
- )
854
- self .assertSpanAttributes (
855
- "CloudSpanner.GetSession" ,
856
- attributes = dict (
857
- BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }, session_found = True
858
- ),
859
- span = span_list [2 ],
860
- )
861
- self .assertSpanAttributes (
862
- "CloudSpanner.ReadOnlyTransaction" ,
863
- attributes = dict (
864
- BASE_ATTRIBUTES ,
865
- ** {"db.instance" : self ._db .name },
866
- columns = self .COLUMNS ,
867
- table_id = self .TABLE
868
- ),
869
- span = span_list [3 ],
870
- )
838
+ if HAS_OPENTELEMETRY_INSTALLED :
839
+ span_list = self .memory_exporter .get_finished_spans ()
840
+ self .assertEqual (len (span_list ), 4 )
841
+ self .assertSpanAttributes (
842
+ "CloudSpanner.GetSession" ,
843
+ attributes = dict (
844
+ BASE_ATTRIBUTES ,
845
+ ** {"db.instance" : self ._db .name , "session_found" : True }
846
+ ),
847
+ span = span_list [0 ],
848
+ )
849
+ self .assertSpanAttributes (
850
+ "CloudSpanner.Commit" ,
851
+ attributes = dict (
852
+ BASE_ATTRIBUTES ,
853
+ ** {"db.instance" : self ._db .name , "num_mutations" : 2 }
854
+ ),
855
+ span = span_list [1 ],
856
+ )
857
+ self .assertSpanAttributes (
858
+ "CloudSpanner.GetSession" ,
859
+ attributes = dict (
860
+ BASE_ATTRIBUTES ,
861
+ ** {"db.instance" : self ._db .name , "session_found" : True }
862
+ ),
863
+ span = span_list [2 ],
864
+ )
865
+ self .assertSpanAttributes (
866
+ "CloudSpanner.ReadOnlyTransaction" ,
867
+ attributes = dict (
868
+ BASE_ATTRIBUTES ,
869
+ ** {
870
+ "db.instance" : self ._db .name ,
871
+ "columns" : self .COLUMNS ,
872
+ "table_id" : self .TABLE ,
873
+ }
874
+ ),
875
+ span = span_list [3 ],
876
+ )
871
877
872
878
def test_batch_insert_then_read_string_array_of_string (self ):
873
879
TABLE = "string_plus_array_of_string"
@@ -967,67 +973,76 @@ def test_transaction_read_and_insert_then_rollback(self):
967
973
rows = list (session .read (self .TABLE , self .COLUMNS , self .ALL ))
968
974
self .assertEqual (rows , [])
969
975
970
- span_list = self .memory_exporter .get_finished_spans ()
971
- self .assertEqual (len (span_list ), 8 )
972
- self .assertSpanAttributes (
973
- "CloudSpanner.CreateSession" ,
974
- attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
975
- span = span_list [0 ],
976
- )
977
- self .assertSpanAttributes (
978
- "CloudSpanner.GetSession" ,
979
- attributes = dict (
980
- BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }, session_found = True
981
- ),
982
- span = span_list [1 ],
983
- )
984
- self .assertSpanAttributes (
985
- "CloudSpanner.Commit" ,
986
- attributes = dict (
987
- BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }, num_mutations = 1
988
- ),
989
- span = span_list [2 ],
990
- )
991
- self .assertSpanAttributes (
992
- "CloudSpanner.BeginTransaction" ,
993
- attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
994
- span = span_list [3 ],
995
- )
996
- self .assertSpanAttributes (
997
- "CloudSpanner.ReadOnlyTransaction" ,
998
- attributes = dict (
999
- BASE_ATTRIBUTES ,
1000
- ** {"db.instance" : self ._db .name },
1001
- table_id = self .TABLE ,
1002
- columns = self .COLUMNS
1003
- ),
1004
- span = span_list [4 ],
1005
- )
1006
- self .assertSpanAttributes (
1007
- "CloudSpanner.ReadOnlyTransaction" ,
1008
- attributes = dict (
1009
- BASE_ATTRIBUTES ,
1010
- ** {"db.instance" : self ._db .name },
1011
- table_id = self .TABLE ,
1012
- columns = self .COLUMNS
1013
- ),
1014
- span = span_list [5 ],
1015
- )
1016
- self .assertSpanAttributes (
1017
- "CloudSpanner.Rollback" ,
1018
- attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
1019
- span = span_list [6 ],
1020
- )
1021
- self .assertSpanAttributes (
1022
- "CloudSpanner.ReadOnlyTransaction" ,
1023
- attributes = dict (
1024
- BASE_ATTRIBUTES ,
1025
- ** {"db.instance" : self ._db .name },
1026
- table_id = self .TABLE ,
1027
- columns = self .COLUMNS
1028
- ),
1029
- span = span_list [7 ],
1030
- )
976
+ if HAS_OPENTELEMETRY_INSTALLED :
977
+ span_list = self .memory_exporter .get_finished_spans ()
978
+ self .assertEqual (len (span_list ), 8 )
979
+ self .assertSpanAttributes (
980
+ "CloudSpanner.CreateSession" ,
981
+ attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
982
+ span = span_list [0 ],
983
+ )
984
+ self .assertSpanAttributes (
985
+ "CloudSpanner.GetSession" ,
986
+ attributes = dict (
987
+ BASE_ATTRIBUTES ,
988
+ ** {"db.instance" : self ._db .name , "session_found" : True }
989
+ ),
990
+ span = span_list [1 ],
991
+ )
992
+ self .assertSpanAttributes (
993
+ "CloudSpanner.Commit" ,
994
+ attributes = dict (
995
+ BASE_ATTRIBUTES ,
996
+ ** {"db.instance" : self ._db .name , "num_mutations" : 1 }
997
+ ),
998
+ span = span_list [2 ],
999
+ )
1000
+ self .assertSpanAttributes (
1001
+ "CloudSpanner.BeginTransaction" ,
1002
+ attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
1003
+ span = span_list [3 ],
1004
+ )
1005
+ self .assertSpanAttributes (
1006
+ "CloudSpanner.ReadOnlyTransaction" ,
1007
+ attributes = dict (
1008
+ BASE_ATTRIBUTES ,
1009
+ ** {
1010
+ "db.instance" : self ._db .name ,
1011
+ "table_id" : self .TABLE ,
1012
+ "columns" : self .COLUMNS ,
1013
+ }
1014
+ ),
1015
+ span = span_list [4 ],
1016
+ )
1017
+ self .assertSpanAttributes (
1018
+ "CloudSpanner.ReadOnlyTransaction" ,
1019
+ attributes = dict (
1020
+ BASE_ATTRIBUTES ,
1021
+ ** {
1022
+ "db.instance" : self ._db .name ,
1023
+ "table_id" : self .TABLE ,
1024
+ "columns" : self .COLUMNS ,
1025
+ }
1026
+ ),
1027
+ span = span_list [5 ],
1028
+ )
1029
+ self .assertSpanAttributes (
1030
+ "CloudSpanner.Rollback" ,
1031
+ attributes = dict (BASE_ATTRIBUTES , ** {"db.instance" : self ._db .name }),
1032
+ span = span_list [6 ],
1033
+ )
1034
+ self .assertSpanAttributes (
1035
+ "CloudSpanner.ReadOnlyTransaction" ,
1036
+ attributes = dict (
1037
+ BASE_ATTRIBUTES ,
1038
+ ** {
1039
+ "db.instance" : self ._db .name ,
1040
+ "table_id" : self .TABLE ,
1041
+ "columns" : self .COLUMNS ,
1042
+ }
1043
+ ),
1044
+ span = span_list [7 ],
1045
+ )
1031
1046
1032
1047
def _transaction_read_then_raise (self , transaction ):
1033
1048
rows = list (transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
0 commit comments