|
24 | 24 |
|
25 | 25 | import mock |
26 | 26 |
|
| 27 | +from conftest import BASE_TEMPLATE_DIR |
27 | 28 | from elasticapm.base import Client |
28 | 29 | from elasticapm.conf import constants |
29 | 30 | from elasticapm.conf.constants import ERROR, SPAN, TRANSACTION |
@@ -1351,3 +1352,29 @@ def test_options_request(client, django_elasticapm_client): |
1351 | 1352 | client.options("/") |
1352 | 1353 | transactions = django_elasticapm_client.events[TRANSACTION] |
1353 | 1354 | assert transactions[0]["context"]["request"]["method"] == "OPTIONS" |
| 1355 | + |
| 1356 | + |
| 1357 | +def test_rum_tracing_context_processor(client, django_elasticapm_client): |
| 1358 | + with override_settings( |
| 1359 | + TEMPLATES=[ |
| 1360 | + { |
| 1361 | + "BACKEND": "django.template.backends.django.DjangoTemplates", |
| 1362 | + "DIRS": [BASE_TEMPLATE_DIR], |
| 1363 | + "OPTIONS": { |
| 1364 | + "context_processors": [ |
| 1365 | + "django.contrib.auth.context_processors.auth", |
| 1366 | + "elasticapm.contrib.django.context_processors.rum_tracing", |
| 1367 | + ], |
| 1368 | + "loaders": ["django.template.loaders.filesystem.Loader"], |
| 1369 | + "debug": False, |
| 1370 | + }, |
| 1371 | + } |
| 1372 | + ], |
| 1373 | + **middleware_setting(django.VERSION, ["elasticapm.contrib.django.middleware.TracingMiddleware"]) |
| 1374 | + ): |
| 1375 | + response = client.get(reverse("render-heavy-template")) |
| 1376 | + transactions = django_elasticapm_client.events[TRANSACTION] |
| 1377 | + assert response.context["apm"]["trace_id"] == transactions[0]["trace_id"] |
| 1378 | + assert response.context["apm"]["is_sampled"] |
| 1379 | + assert response.context["apm"]["is_sampled_js"] == "true" |
| 1380 | + assert callable(response.context["apm"]["span_id"]) |
0 commit comments