Skip to content

Commit c9004bd

Browse files
nemoshlagshalevr
andauthoredJun 25, 2023
Fix elastic-search sanitization for bulk queries (#1870)
* support sanitization for str body response * add CHANGELOG entry --------- Co-authored-by: Shalev Roda <[email protected]>
1 parent 256d8ce commit c9004bd

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313

14+
- Fix elastic-search instrumentation sanitization to support bulk queries
15+
([#1870](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1870))
1416
- Update falcon instrumentation to follow semantic conventions
1517
([#1824](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1824))
1618

‎instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/utils.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import json
1415

1516
sanitized_keys = (
1617
"message",
@@ -51,6 +52,9 @@ def _unflatten_dict(d):
5152

5253

5354
def sanitize_body(body) -> str:
55+
if isinstance(body, str):
56+
body = json.loads(body)
57+
5458
flatten_body = _flatten_dict(body)
5559

5660
for key in flatten_body:

‎instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py

+4
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,7 @@ def test_body_sanitization(self, _):
479479
sanitize_body(sanitization_queries.filter_query),
480480
str(sanitization_queries.filter_query_sanitized),
481481
)
482+
self.assertEqual(
483+
sanitize_body(json.dumps(sanitization_queries.interval_query)),
484+
str(sanitization_queries.interval_query_sanitized),
485+
)

0 commit comments

Comments
 (0)
Please sign in to comment.