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