@@ -269,10 +269,118 @@ def test_tracing_client_http_header_tags(self):
269269 else :
270270 pytest .fail (f"A span with /status in the resource name was not found { spans } " )
271271
272- def get_rc_params (self , header_tags ):
272+ def setup_tracing_client_http_header_tags_apm_multiconfig (self ):
273+ """We need to test that when the APM_TRACING_MULTICONFIG capability is enabled, it
274+ takes the lowest priority.
275+
276+ This follows the principle that the most specific config wins.
277+ """
278+
279+ # Set a config with the wildcard service and env.
280+ path , config = self .get_rc_params (
281+ {
282+ "tracing_header_tags" : [
283+ {"header" : "X-Test-Header" , "tag_name" : "test_header_rc" },
284+ {"header" : "X-Test-Header-2" , "tag_name" : "test_header_rc2" },
285+ {"header" : "Content-Length" , "tag_name" : "" },
286+ ]
287+ },
288+ service_name = "*" ,
289+ env = "*" ,
290+ )
291+ rc .rc_state .set_config (path , config ).apply ()
292+ self .req1 = weblog .get (
293+ "/status?code=202" ,
294+ headers = {
295+ "X-Test-Header" : "1" ,
296+ "X-Test-Header-2" : "2" ,
297+ "Content-Length" : "0" ,
298+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
299+ },
300+ )
301+
302+ # Set a config with the weblog service and env.
303+ path , config = self .get_rc_params (
304+ {"tracing_header_tags" : [{"header" : "X-Test-Header" , "tag_name" : "test_header_rc_override" }]},
305+ service_name = "weblog" ,
306+ env = "system-tests" ,
307+ )
308+ rc .rc_state .set_config (path , config ).apply ()
309+ self .req2 = weblog .get (
310+ "/status?code=202" ,
311+ headers = {
312+ "X-Test-Header" : "1" ,
313+ "X-Test-Header-2" : "2" ,
314+ "Content-Length" : "0" ,
315+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
316+ },
317+ )
318+
319+ # Delete the config with the weblog service and env. This should use the tracing_header_tags from the first
320+ # config.
321+ rc .rc_state .del_confg (path )
322+
323+ # Set a config with the weblog service and env.
324+ self .req3 = weblog .get (
325+ "/status?code=202" ,
326+ headers = {
327+ "X-Test-Header" : "1" ,
328+ "X-Test-Header-2" : "2" ,
329+ "Content-Length" : "0" ,
330+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
331+ },
332+ )
333+
334+ @missing_feature (reason = "APM_TRACING_MULTICONFIG is not supported in any language yet" )
335+ def test_tracing_client_http_header_tags_apm_multiconfig (self ):
336+ """Ensure the tracing http header tags can be set via RC with the APM_TRACING_MULTICONFIG capability."""
337+ # Validate the spans generated by the first request
338+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req1 , full_trace = True )]
339+ for s in spans :
340+ if "/status" in s ["resource" ]:
341+ # Header tags set via remote config
342+ assert s ["meta" ].get ("test_header_rc" )
343+ assert s ["meta" ].get ("test_header_rc2" )
344+ assert s ["meta" ].get ("http.request.headers.content-length" )
345+ # Does not have headers set via Enviorment variables
346+ assert TAG_SHORT not in s ["meta" ]
347+ break
348+ else :
349+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
350+
351+ # Validate the spans generated by the second request
352+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req2 , full_trace = True )]
353+ for s in spans :
354+ if "/status" in s ["resource" ]:
355+ # Headers tags set via remote config
356+ assert s ["meta" ].get (TAG_SHORT ) == HEADER_VAL_BASIC
357+ # Does not have headers set via remote config
358+ assert "test_header_rc" .get ("test_header_rc_override" )
359+ assert "test_header_rc2" not in s ["meta" ], s ["meta" ]
360+ assert "http.request.headers.content-length" in s ["meta" ], s ["meta" ]
361+ break
362+ else :
363+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
364+
365+ # Validate the spans generated by the third request. This should be identical to the first request, because
366+ # we deleted the config with the weblog service and env.
367+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req3 , full_trace = True )]
368+ for s in spans :
369+ if "/status" in s ["resource" ]:
370+ # Header tags set via remote config
371+ assert s ["meta" ].get ("test_header_rc" )
372+ assert s ["meta" ].get ("test_header_rc2" )
373+ assert s ["meta" ].get ("http.request.headers.content-length" )
374+ # Does not have headers set via Enviorment variables
375+ assert TAG_SHORT not in s ["meta" ]
376+ break
377+ else :
378+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
379+
380+ def get_rc_params (self , header_tags , service_name = "weblog" , env = "system-tests" ):
273381 config = {
274382 "action" : "enable" ,
275- "service_target" : {"service" : "weblog" , "env" : "system-tests" },
383+ "service_target" : {"service" : service_name , "env" : env },
276384 "lib_config" : header_tags ,
277385 }
278386 rc_id = hash (json .dumps (config ))
0 commit comments