Skip to content

Commit 8a87d83

Browse files
authored
chore(iast): improve iast report performance (#13300)
## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent c6833f9 commit 8a87d83

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

ddtrace/appsec/_iast/_iast_request_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def _create_and_attach_iast_report_to_span(req_span: "Span", existing_data: Opti
4646
report_data._merge(previous_data)
4747

4848
if report_data is not None:
49-
report_data.build_and_scrub_value_parts()
50-
req_span.set_tag_str(IAST.JSON, report_data._to_str())
49+
data = report_data.build_and_scrub_value_parts()
50+
req_span.set_tag_str(IAST.JSON, report_data._to_str(data))
5151
_set_metric_iast_request_tainted()
5252
base._set_span_tag_iast_request_tainted(req_span)
5353
_set_span_tag_iast_executed_sink(req_span)

ddtrace/appsec/_iast/reporter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def get_unredacted_value_parts(self, evidence_value: str, ranges: List[dict], so
342342

343343
return value_parts
344344

345-
def _to_str(self) -> str:
345+
def _to_str(self, dict_data=None) -> str:
346346
"""
347347
Converts the IAST span reporter to a JSON string.
348348
@@ -359,4 +359,6 @@ def default(self, obj):
359359
return origin_to_str(obj)
360360
return json.JSONEncoder.default(self, obj)
361361

362+
if dict_data:
363+
return json.dumps(dict_data, cls=OriginTypeEncoder)
362364
return json.dumps(self._to_dict(), cls=OriginTypeEncoder)

0 commit comments

Comments
 (0)