@@ -895,15 +895,18 @@ async def test_user_agent_synthetic_bot_detection(self):
895
895
b"bingbot/1.0" ,
896
896
]
897
897
898
- for user_agent in test_cases :
898
+ # Test each user agent case separately to avoid span accumulation
899
+ for i , user_agent in enumerate (test_cases ):
899
900
with self .subTest (user_agent = user_agent ):
900
901
# Clear headers first
901
902
self .scope ["headers" ] = []
902
903
903
- def update_expected_synthetic_bot (expected , ua = user_agent ):
904
+ def update_expected_synthetic_bot (expected ):
904
905
expected [3 ]["attributes" ].update (
905
906
{
906
- SpanAttributes .HTTP_USER_AGENT : ua .decode ("utf8" ),
907
+ SpanAttributes .HTTP_USER_AGENT : user_agent .decode (
908
+ "utf8"
909
+ ),
907
910
USER_AGENT_SYNTHETIC_TYPE : "bot" ,
908
911
}
909
912
)
@@ -918,6 +921,9 @@ def update_expected_synthetic_bot(expected, ua=user_agent):
918
921
outputs , modifiers = [update_expected_synthetic_bot ]
919
922
)
920
923
924
+ # Clear spans after each test case to prevent accumulation
925
+ self .memory_exporter .clear ()
926
+
921
927
async def test_user_agent_synthetic_test_detection (self ):
922
928
"""Test that test user agents are detected as synthetic with type 'test'"""
923
929
test_cases = [
@@ -926,15 +932,18 @@ async def test_user_agent_synthetic_test_detection(self):
926
932
b"test-alwayson-client" ,
927
933
]
928
934
929
- for user_agent in test_cases :
935
+ # Test each user agent case separately to avoid span accumulation
936
+ for i , user_agent in enumerate (test_cases ):
930
937
with self .subTest (user_agent = user_agent ):
931
938
# Clear headers first
932
939
self .scope ["headers" ] = []
933
940
934
- def update_expected_synthetic_test (expected , ua = user_agent ):
941
+ def update_expected_synthetic_test (expected ):
935
942
expected [3 ]["attributes" ].update (
936
943
{
937
- SpanAttributes .HTTP_USER_AGENT : ua .decode ("utf8" ),
944
+ SpanAttributes .HTTP_USER_AGENT : user_agent .decode (
945
+ "utf8"
946
+ ),
938
947
USER_AGENT_SYNTHETIC_TYPE : "test" ,
939
948
}
940
949
)
@@ -949,6 +958,9 @@ def update_expected_synthetic_test(expected, ua=user_agent):
949
958
outputs , modifiers = [update_expected_synthetic_test ]
950
959
)
951
960
961
+ # Clear spans after each test case to prevent accumulation
962
+ self .memory_exporter .clear ()
963
+
952
964
async def test_user_agent_non_synthetic (self ):
953
965
"""Test that normal user agents are not marked as synthetic"""
954
966
test_cases = [
@@ -958,16 +970,19 @@ async def test_user_agent_non_synthetic(self):
958
970
b"curl/7.68.0" ,
959
971
]
960
972
961
- for user_agent in test_cases :
973
+ # Test each user agent case separately to avoid span accumulation
974
+ for i , user_agent in enumerate (test_cases ):
962
975
with self .subTest (user_agent = user_agent ):
963
976
# Clear headers first
964
977
self .scope ["headers" ] = []
965
978
966
- def update_expected_non_synthetic (expected , ua = user_agent ):
979
+ def update_expected_non_synthetic (expected ):
967
980
# Should only have the user agent, not synthetic type
968
981
expected [3 ]["attributes" ].update (
969
982
{
970
- SpanAttributes .HTTP_USER_AGENT : ua .decode ("utf8" ),
983
+ SpanAttributes .HTTP_USER_AGENT : user_agent .decode (
984
+ "utf8"
985
+ ),
971
986
}
972
987
)
973
988
return expected
@@ -981,6 +996,9 @@ def update_expected_non_synthetic(expected, ua=user_agent):
981
996
outputs , modifiers = [update_expected_non_synthetic ]
982
997
)
983
998
999
+ # Clear spans after each test case to prevent accumulation
1000
+ self .memory_exporter .clear ()
1001
+
984
1002
async def test_user_agent_synthetic_new_semconv (self ):
985
1003
"""Test synthetic user agent detection with new semantic conventions"""
986
1004
user_agent = b"Mozilla/5.0 (compatible; Googlebot/2.1)"
0 commit comments