Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions tests/parametric/test_library_tracestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,28 @@ def enable_tracestats(sample_rate: float | None = None) -> pytest.MarkDecorator:
if sample_rate is not None:
assert 0 <= sample_rate <= 1.0
env.update({"DD_TRACE_SAMPLE_RATE": str(sample_rate)})

return parametrize("library_env", [env])


def enable_agent_version(version: str = "7.65.0") -> pytest.MarkDecorator:
"""Set the test agent version. Java tracer requires agent version >= 7.65.0 for client-side stats."""
agent_env_config = {"TEST_AGENT_VERSION": version}
return parametrize("agent_env", [agent_env_config])


@scenarios.parametric
@features.client_side_stats_supported
class Test_Library_Tracestats:
@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_metrics_msgpack_serialization_TS001(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When spans are finished
Each trace has stats metrics computed for it serialized properly in msgpack format with required fields
Expand Down Expand Up @@ -95,13 +103,14 @@ def test_metrics_msgpack_serialization_TS001(
assert key in decoded_request_body, f"{key} should be in stats request"

@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_distinct_aggregationkeys_TS003(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When spans are created with a unique set of dimensions
Each span has stats computed for it and is in its own bucket
Expand Down Expand Up @@ -182,14 +191,15 @@ def test_distinct_aggregationkeys_TS003(
"There should be seven stats entries in the bucket. There is one baseline entry and 6 that are unique along each of 6 dimensions."
)

@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@enable_tracestats()
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_measured_spans_TS004(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When spans are marked as measured
Each has stats computed for it
Expand Down Expand Up @@ -227,13 +237,16 @@ def test_measured_spans_TS004(
assert op2_stats["Hits"] == 1
assert op2_stats["TopLevelHits"] == 0

@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@enable_tracestats()
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_top_level_TS005(self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary):
def test_top_level_TS005(
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When top level (service entry) spans are created
Each top level span has trace stats computed for it.
"""
Expand Down Expand Up @@ -279,14 +292,15 @@ def test_top_level_TS005(self, library_env: dict[str, str], test_agent: TestAgen
assert web_stats["TopLevelHits"] == 1
assert web_stats["Duration"] > 0

@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@enable_tracestats()
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_successes_errors_recorded_separately_TS006(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When spans are marked as errors
The errors count is incremented appropriately and the stats are aggregated into the ErrorSummary
Expand Down Expand Up @@ -336,14 +350,17 @@ def test_successes_errors_recorded_separately_TS006(
assert stat["OkSummary"] is not None
assert stat["ErrorSummary"] is not None

@enable_tracestats(sample_rate=0.0)
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "java", reason="FIXME: Undefined behavior according the java tracer core team")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@enable_tracestats(sample_rate=0.0)
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_sample_rate_0_TS007(self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary):
def test_sample_rate_0_TS007(
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When the sample rate is 0 and trace stats is enabled
non-P0 traces should be dropped
trace stats should be produced
Expand All @@ -363,10 +380,11 @@ def test_sample_rate_0_TS007(self, library_env: dict[str, str], test_agent: Test
assert web_stats["TopLevelHits"] == 1
assert web_stats["Hits"] == 1

@missing_feature(reason="relative error test is broken")
@enable_tracestats()
@enable_agent_version()
@missing_feature(reason="relative error test is broken")
def test_relative_error_TS008(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When trace stats are computed for traces
The stats should be accurate to within 1% of the real values
Expand Down Expand Up @@ -410,14 +428,15 @@ def test_relative_error_TS008(
rel=0.01,
), f"Quantile mismatch for quantile {quantile!r}"

@enable_tracestats()
@enable_agent_version()
@missing_feature(context.library == "cpp", reason="cpp has not implemented stats computation yet")
@missing_feature(context.library == "nodejs", reason="nodejs has not implemented stats computation yet")
@missing_feature(context.library == "php", reason="php has not implemented stats computation yet")
@missing_feature(context.library == "ruby", reason="ruby has not implemented stats computation yet")
@enable_tracestats()
@bug(context.library >= "[email protected]", reason="APMSP-2074")
def test_metrics_computed_after_span_finsh_TS009(
self, library_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""When trace stats are computed for traces
Metrics must be computed after spans are finished, otherwise components of the aggregation key may change after
Expand Down
9 changes: 6 additions & 3 deletions tests/parametric/test_span_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,9 @@ def test_child_span_selected_by_sss015(self, test_agent: TestAgentAPI, test_libr
}
],
)
@pytest.mark.parametrize("agent_env", [{"TEST_AGENT_VERSION": "7.65.0"}])
def test_root_span_selected_and_child_dropped_by_sss_when_dropping_policy_is_active016(
self, test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""Single spans selected by SSS must be kept and other spans expected to be dropped on the tracer side when
dropping policy is active when tracer metrics enabled.
Expand Down Expand Up @@ -768,8 +769,9 @@ def test_root_span_selected_and_child_dropped_by_sss_when_dropping_policy_is_act
}
],
)
@pytest.mark.parametrize("agent_env", [{"TEST_AGENT_VERSION": "7.65.0"}])
def test_child_span_selected_and_root_dropped_by_sss_when_dropping_policy_is_active017(
self, test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""Single spans selected by SSS must be kept and other spans expected to be dropped on the tracer side when
dropping policy is active when tracer metrics enabled.
Expand Down Expand Up @@ -835,8 +837,9 @@ def test_child_span_selected_and_root_dropped_by_sss_when_dropping_policy_is_act
}
],
)
@pytest.mark.parametrize("agent_env", [{"TEST_AGENT_VERSION": "7.65.0"}])
def test_entire_trace_dropped_when_dropping_policy_is_active018(
self, test_agent: TestAgentAPI, test_library: APMLibrary
self, library_env: dict[str, str], agent_env: dict[str, str], test_agent: TestAgentAPI, test_library: APMLibrary
):
"""The entire dropped span expected to be dropped on the tracer side when
dropping policy is active, which is the case when tracer metrics enabled.
Expand Down
Loading