Skip to content
Draft
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
15 changes: 10 additions & 5 deletions tests/parametric/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
29 changes: 29 additions & 0 deletions tests/test_the_test/test_nodejs_startup_config.py
Original file line number Diff line number Diff line change
@@ -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)
Loading