Skip to content

Commit 7548f17

Browse files
authored
Merge pull request #13 from nameko/truncate-data-params
Truncate request.data payload as it can get big
2 parents 8789159 + e84939a commit 7548f17

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

nameko_opentelemetry/http.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ def get_attributes(self, worker_ctx):
7474
)
7575

7676
if self.config.get("send_request_payloads"):
77+
response, truncated = utils.truncate(
78+
utils.serialise_to_string(scrub(data, self.config)),
79+
max_len=self.config.get("truncate_max_length"),
80+
)
7781
attributes.update(
78-
{"request.data": utils.serialise_to_string(scrub(data, self.config))}
82+
{
83+
"request.data": response,
84+
"request.data_truncated": str(truncated),
85+
}
7986
)
8087

8188
return attributes

nameko_opentelemetry/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "0.5.0"
2+
__version__ = "0.5.1"

tests/test_http.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def config(self, config, send_headers, send_request_payloads):
195195
config["send_headers"] = send_headers
196196
# disable request payload based on param
197197
config["send_request_payloads"] = send_request_payloads
198+
# override default truncation length
199+
config["truncate_max_length"] = 100
198200
return config
199201

200202
@pytest.fixture
@@ -244,6 +246,24 @@ def test_request_data(
244246
else:
245247
assert "request.data" not in attributes
246248

249+
def test_request_data_truncated(
250+
self, container, web_session, memory_exporter, send_request_payloads
251+
):
252+
with entrypoint_waiter(container, "get_resource"):
253+
resp = web_session.get("/resource", data="A" * 200)
254+
255+
assert resp.status_code == 200
256+
257+
spans = memory_exporter.get_finished_spans()
258+
assert len(spans) == 1
259+
260+
attributes = spans[0].attributes
261+
262+
if send_request_payloads:
263+
assert attributes["request.data"] == "A" * 100
264+
else:
265+
assert "request.data" not in attributes
266+
247267
def test_request_headers(
248268
self, container, web_session, memory_exporter, send_headers
249269
):

0 commit comments

Comments
 (0)