Skip to content
Merged
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
112 changes: 110 additions & 2 deletions tests/test_library_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,118 @@ def test_tracing_client_http_header_tags(self):
else:
pytest.fail(f"A span with /status in the resource name was not found {spans}")

def get_rc_params(self, header_tags):
def setup_tracing_client_http_header_tags_apm_multiconfig(self):
"""We need to test that when the APM_TRACING_MULTICONFIG capability is enabled, it
takes the lowest priority.

This follows the principle that the most specific config wins.
"""

# Set a config with the wildcard service and env.
path, config = self.get_rc_params(
{
"tracing_header_tags": [
{"header": "X-Test-Header", "tag_name": "test_header_rc"},
{"header": "X-Test-Header-2", "tag_name": "test_header_rc2"},
{"header": "Content-Length", "tag_name": ""},
]
},
service_name="*",
env="*",
)
rc.rc_state.set_config(path, config).apply()
self.req1 = weblog.get(
"/status?code=202",
headers={
"X-Test-Header": "1",
"X-Test-Header-2": "2",
"Content-Length": "0",
HEADER_NAME_SHORT: HEADER_VAL_BASIC,
},
)

# Set a config with the weblog service and env.
path, config = self.get_rc_params(
{"tracing_header_tags": [{"header": "X-Test-Header", "tag_name": "test_header_rc_override"}]},
service_name="weblog",
env="system-tests",
)
rc.rc_state.set_config(path, config).apply()
self.req2 = weblog.get(
"/status?code=202",
headers={
"X-Test-Header": "1",
"X-Test-Header-2": "2",
"Content-Length": "0",
HEADER_NAME_SHORT: HEADER_VAL_BASIC,
},
)

# Delete the config with the weblog service and env. This should use the tracing_header_tags from the first
# config.
rc.rc_state.del_config(path)

# Set a config with the weblog service and env.
self.req3 = weblog.get(
"/status?code=202",
headers={
"X-Test-Header": "1",
"X-Test-Header-2": "2",
"Content-Length": "0",
HEADER_NAME_SHORT: HEADER_VAL_BASIC,
},
)

@missing_feature(reason="APM_TRACING_MULTICONFIG is not supported in any language yet")
def test_tracing_client_http_header_tags_apm_multiconfig(self):
"""Ensure the tracing http header tags can be set via RC with the APM_TRACING_MULTICONFIG capability."""
# Validate the spans generated by the first request
spans = [span for _, _, span in interfaces.library.get_spans(request=self.req1, full_trace=True)]
for s in spans:
if "/status" in s["resource"]:
# Header tags set via remote config
assert s["meta"].get("test_header_rc")
assert s["meta"].get("test_header_rc2")
assert s["meta"].get("http.request.headers.content-length")
# Does not have headers set via Enviorment variables
assert TAG_SHORT not in s["meta"]
break
else:
pytest.fail(f"A span with /status in the resource name was not found {spans}")

# Validate the spans generated by the second request
spans = [span for _, _, span in interfaces.library.get_spans(request=self.req2, full_trace=True)]
for s in spans:
if "/status" in s["resource"]:
# Headers tags set via remote config
assert s["meta"].get(TAG_SHORT) == HEADER_VAL_BASIC
assert s["meta"].get("test_header_rc_override")
# Does not have headers set via remote config
assert "test_header_rc2" not in s["meta"], s["meta"]
assert "http.request.headers.content-length" in s["meta"], s["meta"]
break
else:
pytest.fail(f"A span with /status in the resource name was not found {spans}")

# Validate the spans generated by the third request. This should be identical to the first request, because
# we deleted the config with the weblog service and env.
spans = [span for _, _, span in interfaces.library.get_spans(request=self.req3, full_trace=True)]
for s in spans:
if "/status" in s["resource"]:
# Header tags set via remote config
assert s["meta"].get("test_header_rc")
assert s["meta"].get("test_header_rc2")
assert s["meta"].get("http.request.headers.content-length")
# Does not have headers set via Enviorment variables
assert TAG_SHORT not in s["meta"]
break
else:
pytest.fail(f"A span with /status in the resource name was not found {spans}")

def get_rc_params(self, header_tags, service_name="weblog", env="system-tests"):
config = {
"action": "enable",
"service_target": {"service": "weblog", "env": "system-tests"},
"service_target": {"service": service_name, "env": env},
"lib_config": header_tags,
}
rc_id = hash(json.dumps(config))
Expand Down