Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(telemetry): fix flaky tests #10721

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
19 changes: 11 additions & 8 deletions tests/telemetry/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def test_app_started_event(telemetry_writer, test_agent_session, mock_time):
("DD_APPSEC_SCA_ENABLED", "0", "false"),
],
)
@pytest.mark.skip(reason="FIXME: This test needs to be updated.")
def test_app_started_event_configuration_override(
test_agent_session, run_python_code_in_subprocess, tmpdir, env_var, value, expected_value
):
Expand All @@ -196,6 +195,12 @@ def test_app_started_event_configuration_override(
logging.basicConfig()

import ddtrace.auto

# By default telemetry collection is enabled after 10 seconds, so we either need to
# to sleep for 10 seconds or manually call _app_started() to generate the app started event.
# This delay allows us to collect start up erorrs and dynamic configurations
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
import ddtrace
ddtrace.internal.telemetry.telemetry_writer._app_started()
"""

env = os.environ.copy()
Expand Down Expand Up @@ -253,10 +258,8 @@ def test_app_started_event_configuration_override(
env["DD_SPAN_SAMPLING_RULES_FILE"] = str(file)
env["DD_TRACE_PARTIAL_FLUSH_ENABLED"] = "false"
env["DD_TRACE_PARTIAL_FLUSH_MIN_SPANS"] = "3"
env["_DD_INSTRUMENTATION_TELEMETRY_TESTS_FORCE_APP_STARTED"] = "true"

_, stderr, status, _ = run_python_code_in_subprocess(code, env=env)

assert status == 0, stderr

app_started_events = test_agent_session.get_events("app-started")
Expand Down Expand Up @@ -380,19 +383,19 @@ def test_update_dependencies_event_when_disabled(telemetry_writer, test_agent_se
assert event["request_type"] != "app-dependencies-loaded"


@pytest.mark.skip(reason="FIXME: This test does not generate a dependencies event")
def test_update_dependencies_event_not_stdlib(telemetry_writer, test_agent_session, mock_time):
# Fetch modules to reset the state of seen modules
modules.get_newly_imported_modules()
telemetry_writer.reset_queues()
assert telemetry_writer._imported_dependencies == {}
del sys.modules["httpretty"]
import httpretty # noqa F401

import string

new_deps = [string.__name__]
telemetry_writer._app_dependencies_loaded_event(new_deps)
Comment on lines -388 to -391
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the fix for this test is to make the app-dependencies-loaded event get triggered indirectly via an actual import statement instead of explicitly like this?

# force a flush
telemetry_writer.periodic(force_flush=True)
events = test_agent_session.get_events("app-dependencies-loaded")
assert len(events) == 1
assert events[0]["payload"]["dependencies"] == [{"name": "httpretty", "version": "1.0.5"}]


def test_update_dependencies_event_not_duplicated(telemetry_writer, test_agent_session, mock_time):
Expand Down
Loading