Skip to content

Commit

Permalink
Merge branch 'main' into APMAPI-351/munir-test-ip-header-consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Sep 18, 2024
2 parents 652035a + d6a14eb commit f3abf75
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 10 deletions.
2 changes: 2 additions & 0 deletions manifests/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: missing_feature (DD_TRACE_CLIENT_IP_HEADER not implemented)
Test_Config_ClientTagQueryString_Configured: missing_feature
Test_Config_ClientTagQueryString_Empty: missing_feature (test can not capture span with the expected http.url tag)
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v2.48.0
Test_Config_ClientTagQueryString_Configured: missing_feature (configuration DNE)
Test_Config_ClientTagQueryString_Empty: v2.53.0
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v1.60.0
Test_Config_ClientTagQueryString_Configured: missing_feature (supports DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED)
Test_Config_ClientTagQueryString_Empty: v1.60.0
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v1.38.0
Test_Config_ClientTagQueryString_Configured: missing_feature (endpoints return 404, but in theory should work)
Test_Config_ClientTagQueryString_Empty: missing_feature (incorrect default value)
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: *ref_5_15_0
Test_Config_ClientTagQueryString_Configured: missing_feature (adding query string to http.url is not supported)
Test_Config_ClientTagQueryString_Empty: missing_feature (removes query strings by default)
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v1.3,0
Test_Config_ClientTagQueryString_Configured: missing_feature (supports dd_trace_http_url_query_param_allowed instead)
Test_Config_ClientTagQueryString_Empty: v1.2.0
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: v1.3.0 # Unknown initial version
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v2.12.0
Test_Config_ClientTagQueryString_Configured: missing_feature (supports DD_HTPP_CLIENT_TAGS_QUERY_STRING instead)
Test_Config_ClientTagQueryString_Empty: v2.12.0
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
2 changes: 2 additions & 0 deletions manifests/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ tests/:
Test_Config_ClientIPHeader_Configured: v2.3.0
Test_Config_ClientTagQueryString_Configured: missing_feature
Test_Config_ClientTagQueryString_Empty: missing_feature (removes query string by default)
Test_Config_HttpClientErrorStatuses_Default: missing_feature
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: missing_feature
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
96 changes: 86 additions & 10 deletions tests/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2022 Datadog, Inc.

import json
from utils import weblog, interfaces, scenarios, features


Expand Down Expand Up @@ -73,6 +74,82 @@ def test_status_code_202(self):
assert spans[0]["error"] == 1


@scenarios.default
@features.tracing_configuration_consistency
class Test_Config_HttpClientErrorStatuses_Default:
""" Verify behavior of http clients """

def setup_status_code_400(self):
self.r = weblog.get("/make_distant_call", params={"url": "http://weblog:7777/status?code=400"})

def test_status_code_400(self):
assert self.r.status_code == 200
content = json.loads(self.r.text)
assert content["status_code"] == 400

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]

client_span = _get_span(spans, tags={"span.kind": "client"})

assert client_span.get("meta").get("http.status_code") == "400"
assert client_span.get("error") == 1

def setup_status_code_500(self):
self.r = weblog.get("/make_distant_call", params={"url": "http://weblog:7777/status?code=500"})

def test_status_code_500(self):
assert self.r.status_code == 200
content = json.loads(self.r.text)
assert content["status_code"] == 500

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]

client_span = _get_span(spans, tags={"span.kind": "client"})

assert client_span.get("meta").get("http.status_code") == "500"
assert client_span.get("error") == None or client_span.get("error") == 0


@scenarios.tracing_config_nondefault
@features.tracing_configuration_consistency
class Test_Config_HttpClientErrorStatuses_FeatureFlagCustom:
""" Verify behavior of http clients """

def setup_status_code_200(self):
self.r = weblog.get("/make_distant_call", params={"url": "http://weblog:7777/status?code=200"})

def test_status_code_200(self):
assert self.r.status_code == 200
content = json.loads(self.r.text)
assert content["status_code"] == 200

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]

client_span = _get_span(spans, tags={"span.kind": "client"})

assert client_span.get("meta").get("http.status_code") == "200"
assert client_span.get("error") == 1

def setup_status_code_202(self):
self.r = weblog.get("/make_distant_call", params={"url": "http://weblog:7777/status?code=202"})

def test_status_code_202(self):
assert self.r.status_code == 200
content = json.loads(self.r.text)
assert content["status_code"] == 202

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]

client_span = _get_span(spans, tags={"span.kind": "client"})

assert client_span.get("meta").get("http.status_code") == "202"
assert client_span.get("error") == 1


@scenarios.default
@features.tracing_configuration_consistency
class Test_Config_ClientTagQueryString_Empty:
Expand All @@ -84,7 +161,7 @@ def setup_query_string_redaction_unset(self):
def test_query_string_redaction_unset(self):
trace = [span for _, _, span in interfaces.library.get_spans(self.r, full_trace=True)]
expected_tags = {"http.url": "http://weblog:7777/?hi=monkey"}
assert _get_span_by_tags(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"
assert _get_span(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"


@scenarios.tracing_config_nondefault_3
Expand All @@ -98,7 +175,7 @@ def setup_query_string_redaction(self):
def test_query_string_redaction(self):
trace = [span for _, _, span in interfaces.library.get_spans(self.r, full_trace=True)]
expected_tags = {"http.url": "http://weblog:7777/"}
assert _get_span_by_tags(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"
assert _get_span(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"


@scenarios.tracing_config_nondefault
Expand Down Expand Up @@ -128,18 +205,17 @@ def test_ip_headers_sent_in_one_client_requests(self):
# Ensures the header set in DD_TRACE_CLIENT_IP_HEADER takes precedence over all supported ip headers
trace = [span for _, _, span in interfaces.library.get_spans(self.req2, full_trace=True)]
expected_tags = {"http.client_ip": "5.6.7.8"}
assert _get_span_by_tags(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"
assert _get_span(trace, expected_tags), f"Span with tags {expected_tags} not found in {trace}"


def _get_span_by_tags(trace, tags):
for span in trace:
# Avoids retrieving the client span by the operation/resource name, this value varies between languages
# Use the expected tags to identify the span
for k, v in tags.items():
if span["meta"].get(k) != v:
def _get_span(spans, tags):
for s in spans:
for tagKey in tags:
if tags[tagKey] != s["meta"].get(tagKey):
break
else:
return span
return s
return {}


@scenarios.tracing_config_nondefault
Expand Down
1 change: 1 addition & 0 deletions utils/_context/_scenarios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def all_endtoend_scenarios(test_object):
"DD_TRACE_CLIENT_IP_HEADER": "custom-ip-header",
# disable ASM to test non asm client ip tagging
"DD_APPSEC_ENABLED": "false",
"DD_TRACE_HTTP_CLIENT_ERROR_STATUSES": "200-201,202",
"DD_SERVICE": "service_test",
},
doc="",
Expand Down

0 comments on commit f3abf75

Please sign in to comment.