@@ -56,6 +56,11 @@ def set_trace_ids():
56
56
trace .guid = "abcdefgh"
57
57
58
58
59
+ def active_session ():
60
+ txn = current_transaction ()
61
+ return list (txn .application ._agent ._applications .values ())[0 ]._active_session
62
+
63
+
59
64
def exercise_record_log_event ():
60
65
set_trace_ids ()
61
66
@@ -407,9 +412,7 @@ def test():
407
412
@override_application_settings ({"labels" : TEST_LABELS , "application_logging.forwarding.labels.enabled" : True })
408
413
@background_task ()
409
414
def test_label_forwarding_enabled ():
410
- txn = current_transaction ()
411
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
412
-
415
+ session = active_session ()
413
416
common = session .get_log_events_common_block ()
414
417
# Excluded label should not appear, and other labels should be prefixed with 'tag.'
415
418
assert common == {"tags.testlabel1" : "A" , "tags.testlabel2" : "B" , "tags.testlabelexclude" : "C" }
@@ -424,9 +427,7 @@ def test_label_forwarding_enabled():
424
427
)
425
428
@background_task ()
426
429
def test_label_forwarding_enabled_exclude ():
427
- txn = current_transaction ()
428
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
429
-
430
+ session = active_session ()
430
431
common = session .get_log_events_common_block ()
431
432
# Excluded label should not appear, and other labels should be prefixed with 'tags.'
432
433
assert common == {"tags.testlabel1" : "A" , "tags.testlabel2" : "B" }
@@ -435,9 +436,7 @@ def test_label_forwarding_enabled_exclude():
435
436
@override_application_settings ({"labels" : TEST_LABELS , "application_logging.forwarding.labels.enabled" : False })
436
437
@background_task ()
437
438
def test_label_forwarding_disabled ():
438
- txn = current_transaction ()
439
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
440
-
439
+ session = active_session ()
441
440
common = session .get_log_events_common_block ()
442
441
# No labels should appear
443
442
assert common == {}
@@ -453,9 +452,7 @@ def test_label_forwarding_disabled():
453
452
)
454
453
@background_task ()
455
454
def test_global_custom_attribute_forwarding_enabled ():
456
- txn = current_transaction ()
457
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
458
-
455
+ session = active_session ()
459
456
common = session .get_log_events_common_block ()
460
457
# Both attrs should appear
461
458
assert common == {"custom_attr_1" : "value 1" , "custom_attr_2" : "value 2" }
@@ -464,9 +461,7 @@ def test_global_custom_attribute_forwarding_enabled():
464
461
@override_application_settings ({"application_logging.forwarding.custom_attributes" : [("custom_attr_1" , "a" * 256 )]})
465
462
@background_task ()
466
463
def test_global_custom_attribute_forwarding_truncation ():
467
- txn = current_transaction ()
468
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
469
-
464
+ session = active_session ()
470
465
common = session .get_log_events_common_block ()
471
466
# Attribute value should be truncated to the max user attribute length
472
467
assert common == {"custom_attr_1" : "a" * 255 }
@@ -477,9 +472,7 @@ def test_global_custom_attribute_forwarding_truncation():
477
472
)
478
473
@background_task ()
479
474
def test_global_custom_attribute_forwarding_max_num_attrs ():
480
- txn = current_transaction ()
481
- session = list (txn .application ._agent ._applications .values ())[0 ]._active_session
482
-
475
+ session = active_session ()
483
476
common = session .get_log_events_common_block ()
484
477
# Should be truncated to the max number of user attributes
485
478
assert common == {f"custom_attr_{ i + 1 } " : "value" for i in range (128 )}
0 commit comments