Skip to content

Commit

Permalink
Fix assertions to work with intake and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraheemA committed Sep 4, 2024
1 parent 43b657a commit d4ebaac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 4 additions & 5 deletions tests/otel_tracing_e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,16 @@ def test_main(self):
return
validate_log_trace_correlation(otel_log_trace_attrs, trace_agent)


# The 2nd account has logs and traces sent via the backend OTLP intake endpoint
try:
log_agent = interfaces.backend.get_logs(
log_intake = interfaces.backend.get_logs(
query=f"trace_id:{dd_trace_id}",
rid=rid,
dd_api_key=os.environ["DD_API_KEY_2"],
dd_app_key=os.environ["DD_APP_KEY_2"],
)
otel_log_trace_attrs = validate_log(log_agent, rid, "datadog_agent")
trace_agent = interfaces.backend.assert_otlp_trace_exist(
otel_log_trace_attrs = validate_log(log_intake, rid, "backend_endpoint")
trace_intake = interfaces.backend.assert_otlp_trace_exist(
request=self.r,
dd_trace_id=dd_trace_id,
dd_api_key=os.environ["DD_API_KEY_2"],
Expand All @@ -187,7 +186,7 @@ def test_main(self):
except ValueError:
logger.warning("Backend does not provide logs")
return
validate_log_trace_correlation(otel_log_trace_attrs, trace_agent)
validate_log_trace_correlation(otel_log_trace_attrs, trace_intake)

# The 3rd account has logs and traces sent by OTel Collector
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ private static SdkLoggerProvider setupLoggerProvider(Resource resource) {
.addHeader("dd-api-key", System.getenv("DD_API_KEY"))
.addHeader("dd-otlp-path", "intake-logs")
.build());
logRecordExporters.add(
OtlpJsonLoggingLogRecordExporter.create()
);
}
if (isCollectorEnabled()) {
logRecordExporters.add(
Expand Down
14 changes: 8 additions & 6 deletions utils/otel_validators/validator_log.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pprint

# Util functions to validate JSON logs from OTel system tests


Expand All @@ -13,11 +15,11 @@ def validate_log(log: dict, rid: str, otel_source: str) -> dict:
"source:otlp_log_ingestion",
]
assert expected_attributes_tags <= log["attributes"]["tags"]
expected_attributes_attributes = {
"http": {"request": {"headers": {"user-agent": f"system_tests rid/{rid}"}}, "method": "GET"},
"status": "info",
}
assert expected_attributes_attributes.items() <= log["attributes"]["attributes"].items()

assert log["attributes"]["attributes"]["http"]["request"]["headers"]["user-agent"] == f"system_tests rid/{rid}"
assert log["attributes"]["attributes"]["http"]["method"] == "GET"
assert log["attributes"]["attributes"].get("status") == "info" or log["attributes"].get("status") == "info"

return log["attributes"]["attributes"]["otel"]


Expand All @@ -28,4 +30,4 @@ def validate_log_trace_correlation(otel_log_trace_attrs: dict, trace: dict):
span = item[1]
assert otel_log_trace_attrs["trace_id"] == span["meta"]["otel.trace_id"]
assert int(otel_log_trace_attrs["span_id"], 16) == int(span["span_id"])
assert otel_log_trace_attrs["severity_number"] == "9"
assert str(otel_log_trace_attrs["severity_number"]) == "9"

0 comments on commit d4ebaac

Please sign in to comment.