@@ -1349,6 +1349,38 @@ def test_capture_post_errors_dict(client, django_elasticapm_client):
13491349 assert error ["context" ]["request" ]["body" ] == "[REDACTED]"
13501350
13511351
1352+ def test_capture_body_config_is_dynamic_for_errors (client , django_elasticapm_client ):
1353+ django_elasticapm_client .config .update (version = "1" , capture_body = "all" )
1354+ with pytest .raises (MyException ):
1355+ client .post (reverse ("elasticapm-raise-exc" ), {"username" : "john" , "password" : "smith" })
1356+ error = django_elasticapm_client .events [ERROR ][0 ]
1357+ assert error ["context" ]["request" ]["body" ] == {"username" : "john" , "password" : "smith" }
1358+
1359+ django_elasticapm_client .config .update (version = "1" , capture_body = "off" )
1360+ with pytest .raises (MyException ):
1361+ client .post (reverse ("elasticapm-raise-exc" ), {"username" : "john" , "password" : "smith" })
1362+ error = django_elasticapm_client .events [ERROR ][1 ]
1363+ assert error ["context" ]["request" ]["body" ] == "[REDACTED]"
1364+
1365+
1366+ def test_capture_body_config_is_dynamic_for_transactions (client , django_elasticapm_client ):
1367+ django_elasticapm_client .config .update (version = "1" , capture_body = "all" )
1368+ with override_settings (
1369+ ** middleware_setting (django .VERSION , ["elasticapm.contrib.django.middleware.TracingMiddleware" ])
1370+ ):
1371+ client .post (reverse ("elasticapm-no-error" ), {"username" : "john" , "password" : "smith" })
1372+ transaction = django_elasticapm_client .events [TRANSACTION ][0 ]
1373+ assert transaction ["context" ]["request" ]["body" ] == {"username" : "john" , "password" : "smith" }
1374+
1375+ django_elasticapm_client .config .update (version = "1" , capture_body = "off" )
1376+ with override_settings (
1377+ ** middleware_setting (django .VERSION , ["elasticapm.contrib.django.middleware.TracingMiddleware" ])
1378+ ):
1379+ client .post (reverse ("elasticapm-no-error" ), {"username" : "john" , "password" : "smith" })
1380+ transaction = django_elasticapm_client .events [TRANSACTION ][1 ]
1381+ assert transaction ["context" ]["request" ]["body" ] == "[REDACTED]"
1382+
1383+
13521384@pytest .mark .parametrize (
13531385 "django_elasticapm_client" ,
13541386 [{"capture_body" : "errors" }, {"capture_body" : "transactions" }, {"capture_body" : "all" }, {"capture_body" : "off" }],
0 commit comments