@@ -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+ 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+ rc .rc_state .reset ().set_config (path , config ).apply ()
302+ self .req2 = weblog .get (
303+ "/status?code=202" ,
304+ headers = {
305+ "X-Test-Header" : "1" ,
306+ "X-Test-Header-2" : "2" ,
307+ "Content-Length" : "0" ,
308+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
309+ },
310+ service_name = "weblog" ,
311+ env = "system-tests" ,
312+ )
313+
314+ path , config = self .get_rc_params (
315+ {
316+ "tracing_header_tags" : [
317+ {"header" : "X-Test-Header" , "tag_name" : "test_header_rc" },
318+ {"header" : "X-Test-Header-2" , "tag_name" : "test_header_rc2" },
319+ {"header" : "Content-Length" , "tag_name" : "" },
320+ ]
321+ },
322+ service_name = "*" ,
323+ env = "*" ,
324+ )
325+ rc .rc_state .reset ().set_config (path , config ).apply ()
326+ self .req3 = weblog .get (
327+ "/status?code=202" ,
328+ headers = {
329+ "X-Test-Header" : "1" ,
330+ "X-Test-Header-2" : "2" ,
331+ "Content-Length" : "0" ,
332+ HEADER_NAME_SHORT : HEADER_VAL_BASIC ,
333+ },
334+ )
335+
336+ @missing_feature (reason = "APM_TRACING_MULTICONFIG is not supported in any language yet" )
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