@@ -153,7 +153,9 @@ def exercise_record_log_event():
153153]
154154
155155
156+ # ================================================
156157# Test Log Forwarding
158+ # ================================================
157159
158160
159161@enable_log_forwarding
@@ -193,7 +195,10 @@ def test():
193195 test ()
194196
195197
198+ # ================================================
196199# Test Message Truncation
200+ # ================================================
201+
197202
198203_test_log_event_truncation_events = [{"message" : "A" * 32768 }]
199204
@@ -220,7 +225,9 @@ def test():
220225 test ()
221226
222227
228+ # ================================================
223229# Test Log Forwarding Settings
230+ # ================================================
224231
225232
226233@disable_log_forwarding
@@ -243,7 +250,9 @@ def test():
243250 test ()
244251
245252
253+ # ================================================
246254# Test Log Attribute Settings
255+ # ================================================
247256
248257
249258@disable_log_attributes
@@ -396,3 +405,99 @@ def test():
396405 record_log_event ("A" )
397406
398407 test ()
408+
409+
410+ # ================================================
411+ # Test Log Event Labels Settings
412+ # ================================================
413+
414+
415+ # Add labels setting value in already processed format
416+ TEST_LABELS = {"testlabel1" : "A" , "testlabel2" : "B" , "testlabelexclude" : "C" }
417+ TEST_LABELS = [{"label_type" : k , "label_value" : v } for k , v in TEST_LABELS .items ()]
418+
419+ @override_application_settings ({
420+ "labels" : TEST_LABELS ,
421+ "application_logging.forwarding.labels.enabled" : True ,
422+ })
423+ @background_task ()
424+ def test_label_forwarding_enabled ():
425+ txn = current_transaction ()
426+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
427+
428+ common = session .get_log_events_common_block ()
429+ # Excluded label should not appear, and other labels should be prefixed with 'tag.'
430+ assert common == {"tags.testlabel1" : "A" , "tags.testlabel2" : "B" , "tags.testlabelexclude" : "C" }
431+
432+
433+ @override_application_settings ({
434+ "labels" : TEST_LABELS ,
435+ "application_logging.forwarding.labels.enabled" : True ,
436+ "application_logging.forwarding.labels.exclude" : {"testlabelexclude" },
437+ })
438+ @background_task ()
439+ def test_label_forwarding_enabled_exclude ():
440+ txn = current_transaction ()
441+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
442+
443+ common = session .get_log_events_common_block ()
444+ # Excluded label should not appear, and other labels should be prefixed with 'tags.'
445+ assert common == {"tags.testlabel1" : "A" , "tags.testlabel2" : "B" }
446+
447+
448+ @override_application_settings ({
449+ "labels" : TEST_LABELS ,
450+ "application_logging.forwarding.labels.enabled" : False ,
451+ })
452+ @background_task ()
453+ def test_label_forwarding_disabled ():
454+ txn = current_transaction ()
455+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
456+
457+ common = session .get_log_events_common_block ()
458+ # No labels should appear
459+ assert common == {}
460+
461+
462+ # ================================================
463+ # Test Log Event Global Custom Attributes Settings
464+ # ================================================
465+
466+
467+ @override_application_settings ({
468+ "application_logging.forwarding.custom_attributes" : [("custom_attr_1" , "value 1" ), ("custom_attr_2" , "value 2" )],
469+ })
470+ @background_task ()
471+ def test_global_custom_attribute_forwarding_enabled ():
472+ txn = current_transaction ()
473+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
474+
475+ common = session .get_log_events_common_block ()
476+ # Both attrs should appear
477+ assert common == {"custom_attr_1" : "value 1" , "custom_attr_2" : "value 2" }
478+
479+
480+ @override_application_settings ({
481+ "application_logging.forwarding.custom_attributes" : [("custom_attr_1" , "a" * 256 )],
482+ })
483+ @background_task ()
484+ def test_global_custom_attribute_forwarding_truncation ():
485+ txn = current_transaction ()
486+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
487+
488+ common = session .get_log_events_common_block ()
489+ # Attribute value should be truncated to the max user attribute length
490+ assert common == {"custom_attr_1" : "a" * 255 }
491+
492+
493+ @override_application_settings ({
494+ "application_logging.forwarding.custom_attributes" : [(f"custom_attr_{ i + 1 } " , "value" ) for i in range (129 )],
495+ })
496+ @background_task ()
497+ def test_global_custom_attribute_forwarding_max_num_attrs ():
498+ txn = current_transaction ()
499+ session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
500+
501+ common = session .get_log_events_common_block ()
502+ # Should be truncated to the max number of user attributes
503+ assert common == {f"custom_attr_{ i + 1 } " : "value" for i in range (128 )}
0 commit comments