From 7a63b75975ce0e0da3a978819b177f58c8d946f8 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 23 Nov 2026 13:49:48 +0100 Subject: [PATCH] test(parametric): read Node.js startup config from JSON logs Structured startup logs put the configuration inside the message field. The agent URL and debug tests pass the escaped text to json.loads and fail before they check the effective settings. Keep accepting plain startup lines so the tests still work with older tracers. Refs: https://github.com/DataDog/dd-trace-js/issues/10606 --- tests/parametric/conftest.py | 15 ++++++---- .../test_nodejs_startup_config.py | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/test_the_test/test_nodejs_startup_config.py diff --git a/tests/parametric/conftest.py b/tests/parametric/conftest.py index 857e5be9c17..9fee9d6d197 100644 --- a/tests/parametric/conftest.py +++ b/tests/parametric/conftest.py @@ -297,8 +297,8 @@ def restart_and_get_runtime_id(test_agent: TestAgentAPI, test_library: APMLibrar return test_agent.wait_for_telemetry_runtime_id(exclude=previous_runtime_id) -def nodejs_startup_config(test_library: APMLibrary) -> dict: - """Parse the tracer's published `DATADOG TRACER CONFIGURATION - {json}` startup line. +def nodejs_startup_config(test_library: APMLibrary) -> dict[str, object]: + """Read the tracer's startup configuration from plain text or a JSON log message. Some facts have no telemetry signal: an unreachable agent never delivers telemetry (so the resolved agent URL is unobservable that way), and OTEL_LOG_LEVEL=debug toggles debug logging @@ -307,7 +307,12 @@ def nodejs_startup_config(test_library: APMLibrary) -> dict: """ marker = "DATADOG TRACER CONFIGURATION - " for line in test_library.get_logs().splitlines(): - index = line.find(marker) - if index != -1: - return json.loads(line[index + len(marker) :]) + if marker not in line: + continue + message = json.loads(line).get("message") if line.startswith("{") else line + if not isinstance(message, str): + continue + _, separator, configuration = message.partition(marker) + if separator: + return json.loads(configuration) raise AssertionError("No 'DATADOG TRACER CONFIGURATION' line found in container logs") diff --git a/tests/test_the_test/test_nodejs_startup_config.py b/tests/test_the_test/test_nodejs_startup_config.py new file mode 100644 index 00000000000..16eb5a55ee7 --- /dev/null +++ b/tests/test_the_test/test_nodejs_startup_config.py @@ -0,0 +1,29 @@ +import json +from unittest.mock import Mock + +from tests.parametric.conftest import APMLibrary, nodejs_startup_config +from utils import pytest, scenarios + + +@scenarios.test_the_test +@pytest.mark.parametrize("structured", [False, True], ids=["plain", "json"]) +def test_nodejs_startup_config_reads_the_configuration(*, structured: bool) -> None: + configuration = {"agent_url": "http://[::1]:8126", "debug": True, "tags": {"example": 'value with "quotes"'}} + message = f"DATADOG TRACER CONFIGURATION - {json.dumps(configuration)}" + line = json.dumps({"status": "info", "message": message}) if structured else message + library = Mock(spec=APMLibrary) + library.get_logs.return_value = f"Server ready\n{line}\n" + + assert nodejs_startup_config(library) == configuration + + +@scenarios.test_the_test +def test_nodejs_startup_config_ignores_markers_outside_log_messages() -> None: + library = Mock(spec=APMLibrary) + library.get_logs.return_value = "\n".join( + json.dumps({"label": "DATADOG TRACER CONFIGURATION - {}", **fields}) + for fields in ({}, {"message": "Server ready"}) + ) + + with pytest.raises(AssertionError, match="No .*DATADOG TRACER CONFIGURATION"): + nodejs_startup_config(library)