Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,29 @@ def test_transaction_max_spans(elasticapm_client):
assert transaction["span_count"] == {"dropped": 10, "started": 5}


def test_transaction_max_spans_dynamic(elasticapm_client):
elasticapm_client.config.update(version=1, transaction_max_spans=1)
elasticapm_client.begin_transaction("test_type")
for i in range(5):
with elasticapm.capture_span("span"):
pass
elasticapm_client.end_transaction("test")
transaction = elasticapm_client.events[TRANSACTION][0]
spans = elasticapm_client.spans_for_transaction(transaction)
assert len(spans) == 1

elasticapm_client.config.update(version=2, transaction_max_spans=3)
elasticapm_client.begin_transaction("test_type")
for i in range(5):
with elasticapm.capture_span("span"):
pass

elasticapm_client.end_transaction("test")
transaction = elasticapm_client.events[TRANSACTION][1]
spans = elasticapm_client.spans_for_transaction(transaction)
assert len(spans) == 3


@pytest.mark.parametrize("elasticapm_client", [{"span_frames_min_duration": 20}], indirect=True)
def test_transaction_span_frames_min_duration(elasticapm_client):
elasticapm_client.begin_transaction("test_type")
Expand Down
32 changes: 32 additions & 0 deletions tests/contrib/django/django_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,38 @@ def test_capture_post_errors_dict(client, django_elasticapm_client):
assert error["context"]["request"]["body"] == "[REDACTED]"


def test_capture_body_config_is_dynamic_for_errors(client, django_elasticapm_client):
django_elasticapm_client.config.update(version="1", capture_body="all")
with pytest.raises(MyException):
client.post(reverse("elasticapm-raise-exc"), {"username": "john", "password": "smith"})
error = django_elasticapm_client.events[ERROR][0]
assert error["context"]["request"]["body"] == {"username": "john", "password": "smith"}

django_elasticapm_client.config.update(version="1", capture_body="off")
with pytest.raises(MyException):
client.post(reverse("elasticapm-raise-exc"), {"username": "john", "password": "smith"})
error = django_elasticapm_client.events[ERROR][1]
assert error["context"]["request"]["body"] == "[REDACTED]"


def test_capture_body_config_is_dynamic_for_transactions(client, django_elasticapm_client):
django_elasticapm_client.config.update(version="1", capture_body="all")
with override_settings(
**middleware_setting(django.VERSION, ["elasticapm.contrib.django.middleware.TracingMiddleware"])
):
client.post(reverse("elasticapm-no-error"), {"username": "john", "password": "smith"})
transaction = django_elasticapm_client.events[TRANSACTION][0]
assert transaction["context"]["request"]["body"] == {"username": "john", "password": "smith"}

django_elasticapm_client.config.update(version="1", capture_body="off")
with override_settings(
**middleware_setting(django.VERSION, ["elasticapm.contrib.django.middleware.TracingMiddleware"])
):
client.post(reverse("elasticapm-no-error"), {"username": "john", "password": "smith"})
transaction = django_elasticapm_client.events[TRANSACTION][1]
assert transaction["context"]["request"]["body"] == "[REDACTED]"


@pytest.mark.parametrize(
"django_elasticapm_client",
[{"capture_body": "errors"}, {"capture_body": "transactions"}, {"capture_body": "all"}, {"capture_body": "off"}],
Expand Down
28 changes: 28 additions & 0 deletions tests/contrib/flask/flask_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,34 @@ def test_post_files(flask_apm_client):
assert event["context"]["request"]["body"] == "[REDACTED]"


def test_capture_body_config_is_dynamic_for_errors(flask_apm_client):
flask_apm_client.client.config.update(version="1", capture_body="all")
resp = flask_apm_client.app.test_client().post("/an-error/", data={"foo": "bar"})
resp.close()
error = flask_apm_client.client.events[ERROR][0]
assert error["context"]["request"]["body"] == {"foo": "bar"}

flask_apm_client.client.config.update(version="2", capture_body="off")
resp = flask_apm_client.app.test_client().post("/an-error/", data={"foo": "bar"})
resp.close()
error = flask_apm_client.client.events[ERROR][1]
assert error["context"]["request"]["body"] == "[REDACTED]"


def test_capture_body_config_is_dynamic_for_transactions(flask_apm_client):
flask_apm_client.client.config.update(version="1", capture_body="all")
resp = flask_apm_client.app.test_client().post("/users/", data={"foo": "bar"})
resp.close()
error = flask_apm_client.client.events[TRANSACTION][0]
assert error["context"]["request"]["body"] == {"foo": "bar"}

flask_apm_client.client.config.update(version="2", capture_body="off")
resp = flask_apm_client.app.test_client().post("/users/", data={"foo": "bar"})
resp.close()
error = flask_apm_client.client.events[TRANSACTION][1]
assert error["context"]["request"]["body"] == "[REDACTED]"


@pytest.mark.parametrize("elasticapm_client", [{"capture_body": "transactions"}], indirect=True)
def test_options_request(flask_apm_client):
resp = flask_apm_client.app.test_client().options("/")
Expand Down