@@ -269,10 +269,122 @@ 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+ path , config = self .get_rc_params (
279+ {
280+ "tracing_header_tags" : [
281+ {"header" : "X-Test-Header" , "tag_name" : "test_header_rc" },
282+ {"header" : "X-Test-Header-2" , "tag_name" : "test_header_rc2" },
283+ {"header" : "Content-Length" , "tag_name" : "" },
284+ ]
285+ },
286+ service_name = "*" ,
287+ env = "*" ,
288+ )
289+ rc .rc_state .reset ().set_config (path , config ).apply ()
290+ self .req1 = weblog .get (
291+ "/status?code=202" ,
292+ headers = {
293+ "X-Test-Header" : "1" ,
294+ "X-Test-Header-2" : "2" ,
295+ "Content-Length" : "0" ,
296+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
297+ },
298+ )
299+
300+ path , config = self .get_rc_params (
301+ {},
302+ service_name = "weblog" ,
303+ env = "system-tests" ,
304+ )
305+ rc .rc_state .reset ().set_config (path , config ).apply ()
306+ self .req2 = weblog .get (
307+ "/status?code=202" ,
308+ headers = {
309+ "X-Test-Header" : "1" ,
310+ "X-Test-Header-2" : "2" ,
311+ "Content-Length" : "0" ,
312+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
313+ },
314+ )
315+
316+ path , config = self .get_rc_params (
317+ {
318+ "tracing_header_tags" : [
319+ {"header" : "X-Test-Header" , "tag_name" : "test_header_rc" },
320+ {"header" : "X-Test-Header-2" , "tag_name" : "test_header_rc2" },
321+ {"header" : "Content-Length" , "tag_name" : "" },
322+ ]
323+ },
324+ service_name = "*" ,
325+ env = "*" ,
326+ )
327+ rc .rc_state .reset ().set_config (path , config ).apply ()
328+ self .req3 = weblog .get (
329+ "/status?code=202" ,
330+ headers = {
331+ "X-Test-Header" : "1" ,
332+ "X-Test-Header-2" : "2" ,
333+ "Content-Length" : "0" ,
334+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
335+ },
336+ )
337+
338+ @missing_feature (reason = "APM_TRACING_MULTICONFIG is not supported in any language yet" )
339+ def test_tracing_client_http_header_tags_apm_multiconfig (self ):
340+ """Ensure the tracing http header tags can be set via RC with the APM_TRACING_MULTICONFIG capability."""
341+ # Validate the spans generated by the first request
342+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req1 , full_trace = True )]
343+ for s in spans :
344+ if "/status" in s ["resource" ]:
345+ # Header tags set via remote config
346+ assert s ["meta" ].get ("test_header_rc" )
347+ assert s ["meta" ].get ("test_header_rc2" )
348+ assert s ["meta" ].get ("http.request.headers.content-length" )
349+ # Does not have headers set via Enviorment variables
350+ assert TAG_SHORT not in s ["meta" ]
351+ break
352+ else :
353+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
354+
355+ # Validate the spans generated by the second request
356+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req2 , full_trace = True )]
357+ for s in spans :
358+ if "/status" in s ["resource" ]:
359+ # Headers tags set via remote config
360+ assert s ["meta" ].get (TAG_SHORT ) == HEADER_VAL_BASIC
361+ # Does not have headers set via remote config
362+ assert "test_header_rc" not in s ["meta" ], s ["meta" ]
363+ assert "test_header_rc2" not in s ["meta" ], s ["meta" ]
364+ assert "http.request.headers.content-length" in s ["meta" ], s ["meta" ]
365+ break
366+ else :
367+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
368+
369+ # Validate the spans generated by the third request. This should be identical to the second request, because
370+ # the last RC config has the lowest priority and should be ignored.
371+ spans = [span for _ , _ , span in interfaces .library .get_spans (request = self .req3 , full_trace = True )]
372+ for s in spans :
373+ if "/status" in s ["resource" ]:
374+ # Headers tags set via remote config
375+ assert s ["meta" ].get (TAG_SHORT ) == HEADER_VAL_BASIC
376+ # Does not have headers set via remote config
377+ assert "test_header_rc" not in s ["meta" ], s ["meta" ]
378+ assert "test_header_rc2" not in s ["meta" ], s ["meta" ]
379+ assert "http.request.headers.content-length" in s ["meta" ], s ["meta" ]
380+ break
381+ else :
382+ pytest .fail (f"A span with /status in the resource name was not found { spans } " )
383+
384+ def get_rc_params (self , header_tags , service_name = "weblog" , env = "system-tests" ):
273385 config = {
274386 "action" : "enable" ,
275- "service_target" : {"service" : "weblog" , "env" : "system-tests" },
387+ "service_target" : {"service" : service_name , "env" : env },
276388 "lib_config" : header_tags ,
277389 }
278390 rc_id = hash (json .dumps (config ))
0 commit comments