@@ -32,20 +32,28 @@ def enable_tracestats(sample_rate: float | None = None) -> pytest.MarkDecorator:
3232 if sample_rate is not None :
3333 assert 0 <= sample_rate <= 1.0
3434 env .update ({"DD_TRACE_SAMPLE_RATE" : str (sample_rate )})
35+
3536 return parametrize ("library_env" , [env ])
3637
3738
39+ def enable_agent_version (version : str = "7.65.0" ) -> pytest .MarkDecorator :
40+ """Set the test agent version. Java tracer requires agent version >= 7.65.0 for client-side stats."""
41+ agent_env_config = {"TEST_AGENT_VERSION" : version }
42+ return parametrize ("agent_env" , [agent_env_config ])
43+
44+
3845@scenarios .parametric
3946@features .client_side_stats_supported
4047class Test_Library_Tracestats :
4148 @enable_tracestats ()
49+ @enable_agent_version ()
4250 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
4351 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
4452 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
4553 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
4654 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 4755 def test_metrics_msgpack_serialization_TS001 (
48- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
56+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
4957 ):
5058 """When spans are finished
5159 Each trace has stats metrics computed for it serialized properly in msgpack format with required fields
@@ -95,13 +103,14 @@ def test_metrics_msgpack_serialization_TS001(
95103 assert key in decoded_request_body , f"{ key } should be in stats request"
96104
97105 @enable_tracestats ()
106+ @enable_agent_version ()
98107 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
99108 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
100109 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
101110 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
102111 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 103112 def test_distinct_aggregationkeys_TS003 (
104- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
113+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
105114 ):
106115 """When spans are created with a unique set of dimensions
107116 Each span has stats computed for it and is in its own bucket
@@ -182,14 +191,15 @@ def test_distinct_aggregationkeys_TS003(
182191 "There should be seven stats entries in the bucket. There is one baseline entry and 6 that are unique along each of 6 dimensions."
183192 )
184193
194+ @enable_tracestats ()
195+ @enable_agent_version ()
185196 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
186197 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
187198 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
188199 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
189- @enable_tracestats ()
190200 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 191201 def test_measured_spans_TS004 (
192- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
202+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
193203 ):
194204 """When spans are marked as measured
195205 Each has stats computed for it
@@ -227,13 +237,16 @@ def test_measured_spans_TS004(
227237 assert op2_stats ["Hits" ] == 1
228238 assert op2_stats ["TopLevelHits" ] == 0
229239
240+ @enable_tracestats ()
241+ @enable_agent_version ()
230242 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
231243 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
232244 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
233245 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
234- @enable_tracestats ()
235246 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 236- def test_top_level_TS005 (self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary ):
247+ def test_top_level_TS005 (
248+ self , library_env : dict [str , str ], agent_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
249+ ):
237250 """When top level (service entry) spans are created
238251 Each top level span has trace stats computed for it.
239252 """
@@ -279,14 +292,15 @@ def test_top_level_TS005(self, library_env: dict[str, str], test_agent: TestAgen
279292 assert web_stats ["TopLevelHits" ] == 1
280293 assert web_stats ["Duration" ] > 0
281294
295+ @enable_tracestats ()
296+ @enable_agent_version ()
282297 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
283298 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
284299 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
285300 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
286- @enable_tracestats ()
287301 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 288302 def test_successes_errors_recorded_separately_TS006 (
289- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
303+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
290304 ):
291305 """When spans are marked as errors
292306 The errors count is incremented appropriately and the stats are aggregated into the ErrorSummary
@@ -336,14 +350,17 @@ def test_successes_errors_recorded_separately_TS006(
336350 assert stat ["OkSummary" ] is not None
337351 assert stat ["ErrorSummary" ] is not None
338352
353+ @enable_tracestats (sample_rate = 0.0 )
354+ @enable_agent_version ()
339355 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
340356 @missing_feature (context .library == "java" , reason = "FIXME: Undefined behavior according the java tracer core team" )
341357 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
342358 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
343359 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
344- @enable_tracestats (sample_rate = 0.0 )
345360 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 346- def test_sample_rate_0_TS007 (self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary ):
361+ def test_sample_rate_0_TS007 (
362+ self , library_env : dict [str , str ], agent_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
363+ ):
347364 """When the sample rate is 0 and trace stats is enabled
348365 non-P0 traces should be dropped
349366 trace stats should be produced
@@ -363,10 +380,11 @@ def test_sample_rate_0_TS007(self, library_env: dict[str, str], test_agent: Test
363380 assert web_stats ["TopLevelHits" ] == 1
364381 assert web_stats ["Hits" ] == 1
365382
366- @missing_feature (reason = "relative error test is broken" )
367383 @enable_tracestats ()
384+ @enable_agent_version ()
385+ @missing_feature (reason = "relative error test is broken" )
368386 def test_relative_error_TS008 (
369- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
387+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
370388 ):
371389 """When trace stats are computed for traces
372390 The stats should be accurate to within 1% of the real values
@@ -410,14 +428,15 @@ def test_relative_error_TS008(
410428 rel = 0.01 ,
411429 ), f"Quantile mismatch for quantile { quantile !r} "
412430
431+ @enable_tracestats ()
432+ @enable_agent_version ()
413433 @missing_feature (context .library == "cpp" , reason = "cpp has not implemented stats computation yet" )
414434 @missing_feature (context .library == "nodejs" , reason = "nodejs has not implemented stats computation yet" )
415435 @missing_feature (context .library == "php" , reason = "php has not implemented stats computation yet" )
416436 @missing_feature (context .library == "ruby" , reason = "ruby has not implemented stats computation yet" )
417- @enable_tracestats ()
418437 @bug (context .library >= "[email protected] " , reason = "APMSP-2074" ) 419438 def test_metrics_computed_after_span_finsh_TS009 (
420- self , library_env : dict [str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
439+ self , library_env : dict [str , str ], agent_env : dict [ str , str ], test_agent : TestAgentAPI , test_library : APMLibrary
421440 ):
422441 """When trace stats are computed for traces
423442 Metrics must be computed after spans are finished, otherwise components of the aggregation key may change after
0 commit comments