Skip to content

Commit

Permalink
Add truncation support for ML events recorded outside txns. (#949)
Browse files Browse the repository at this point in the history
* Add ml tests for outside transaction.

* Update validator.

* Add ML flag to application code path for record_ml_event.
  • Loading branch information
umaannamalai authored Oct 24, 2023
1 parent aaedae6 commit 7b3fe08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion newrelic/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def record_ml_event(self, event_type, params):
if settings is None or not settings.ml_insights_events.enabled:
return

event = create_custom_event(event_type, params)
event = create_custom_event(event_type, params, is_ml_event=True)

if event:
with self._stats_custom_lock:
Expand Down
31 changes: 30 additions & 1 deletion tests/agent_features/test_ml_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _test():


@reset_core_stats_engine()
def test_record_ml_event_truncation():
def test_record_ml_event_truncation_inside_transaction():
@validate_ml_events([(_intrinsics, {"a": "a" * 4095})])
@background_task()
def _test():
Expand All @@ -236,6 +236,16 @@ def _test():
_test()


@reset_core_stats_engine()
def test_record_ml_event_truncation_outside_transaction():
@validate_ml_events_outside_transaction([(_intrinsics, {"a": "a" * 4095})])
def _test():
app = application()
record_ml_event("LabelEvent", {"a": "a" * 4100}, application=app)

_test()


@reset_core_stats_engine()
def test_record_ml_event_max_num_attrs():
too_many_attrs_event = {}
Expand All @@ -253,6 +263,25 @@ def _test():

_test()


@reset_core_stats_engine()
def test_record_ml_event_max_num_attrs_outside_transaction():
too_many_attrs_event = {}
for i in range(65):
too_many_attrs_event[str(i)] = str(i)

max_attrs_event = {}
for i in range(64):
max_attrs_event[str(i)] = str(i)

@validate_ml_events_outside_transaction([(_intrinsics, max_attrs_event)])
def _test():
app = application()
record_ml_event("LabelEvent", too_many_attrs_event, application=app)

_test()


@pytest.mark.parametrize(
"params,expected",
[
Expand Down

0 comments on commit 7b3fe08

Please sign in to comment.