Skip to content

Commit 34fe114

Browse files
lrafeeiTimPansino
andauthored
Add logging supportability metrics (#554)
* Add logging supportability metrics Co-authored-by: Lalleh Rafeei [email protected] Co-authored-by: Uma Annamalai [email protected] Co-authored-by: Tim Pansino [email protected] * Unit test adjustments Co-authored-by: Tim Pansino <[email protected]>
1 parent b004ead commit 34fe114

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

newrelic/core/application.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ def connect_to_data_collector(self, activate_agent):
537537
)
538538
internal_metric("Supportability/Python/Application/Registration/Attempts", connect_attempts)
539539

540+
# Logging feature toggle supportability metrics
541+
application_logging_metrics = configuration.application_logging.enabled and configuration.application_logging.metrics.enabled
542+
application_logging_forwarding = configuration.application_logging.enabled and configuration.application_logging.forwarding.enabled
543+
application_logging_local_decorating = configuration.application_logging.enabled and configuration.application_logging.local_decorating.enabled
544+
internal_metric("Supportability/Logging/Forwarding/Python/%s" % ("enabled" if application_logging_forwarding else "disabled"), 1)
545+
internal_metric("Supportability/Logging/LocalDecorating/Python/%s" % ("enabled" if application_logging_local_decorating else "disabled"), 1)
546+
internal_metric("Supportability/Logging/Metrics/Python/%s" % ("enabled" if application_logging_metrics else "disabled"), 1)
547+
540548
self._stats_engine.merge_custom_metrics(internal_metrics.metrics())
541549

542550
# Update the active session in this object. This will the

tests/agent_unittests/test_agent_connect.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
1516
from newrelic.core.application import Application
1617
from newrelic.core.config import global_settings
1718
from newrelic.network.exceptions import ForceAgentDisconnect
1819

19-
from testing_support.fixtures import (override_generic_settings,
20-
failing_endpoint)
20+
from testing_support.fixtures import (
21+
override_generic_settings,
22+
validate_internal_metrics,
23+
failing_endpoint
24+
)
25+
2126

2227

2328
SETTINGS = global_settings()
@@ -34,3 +39,38 @@ def test_http_gone_stops_connect():
3439
# The agent must not reattempt a connection after a ForceAgentDisconnect.
3540
# If it does, we'll end up with a session here.
3641
assert not app._active_session
42+
43+
44+
_logging_settings_matrix = [
45+
(True, True),
46+
(True, False),
47+
(False, True),
48+
(False, False),
49+
]
50+
51+
52+
@override_generic_settings(SETTINGS, {
53+
'developer_mode': True,
54+
})
55+
@pytest.mark.parametrize("feature_setting,subfeature_setting", _logging_settings_matrix)
56+
def test_logging_connect_supportability_metrics(feature_setting, subfeature_setting):
57+
metric_value = "enabled" if feature_setting and subfeature_setting else "disabled"
58+
59+
@override_generic_settings(SETTINGS, {
60+
"application_logging.enabled": feature_setting,
61+
"application_logging.forwarding.enabled": subfeature_setting,
62+
"application_logging.metrics.enabled": subfeature_setting,
63+
"application_logging.local_decorating.enabled": subfeature_setting,
64+
})
65+
@validate_internal_metrics([
66+
("Supportability/Logging/Forwarding/Python/%s" % metric_value, 1),
67+
("Supportability/Logging/LocalDecorating/Python/%s" % metric_value, 1),
68+
("Supportability/Logging/Metrics/Python/%s" % metric_value, 1),
69+
])
70+
def test():
71+
app = Application('Python Agent Test (agent_unittests-connect)')
72+
app.connect_to_data_collector(None)
73+
74+
assert app._active_session
75+
76+
test()

tests/testing_support/fixtures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,14 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs):
597597
def validate_internal_metrics(metrics=None):
598598
metrics = metrics or []
599599

600+
def no_op(wrapped, instance, args, kwargs):
601+
pass
602+
600603
@function_wrapper
601604
def _validate_wrapper(wrapped, instance, args, kwargs):
605+
# Apply no-op wrappers to prevent new internal trace contexts from being started, preventing capture
606+
wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__enter__")(no_op)(wrapped)
607+
wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__exit__")(no_op)(wrapped)
602608

603609
captured_metrics = CustomMetrics()
604610
with InternalTraceContext(captured_metrics):

0 commit comments

Comments
 (0)