Skip to content

Commit f86e7db

Browse files
Allow configuring different Sampler in Django App (#252)
Extended aws_xray_sdk.ext.django app to be able to select Sampler, and avoid being stuck with the DefaultSampler Co-authored-by: Prashant Srivastava <[email protected]>
1 parent f4a3fb4 commit f86e7db

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

aws_xray_sdk/ext/django/apps.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def ready(self):
3030
daemon_address=settings.AWS_XRAY_DAEMON_ADDRESS,
3131
sampling=settings.SAMPLING,
3232
sampling_rules=settings.SAMPLING_RULES,
33+
sampler=settings.SAMPLER,
3334
context_missing=settings.AWS_XRAY_CONTEXT_MISSING,
3435
plugins=settings.PLUGINS,
3536
service=settings.AWS_XRAY_TRACING_NAME,

aws_xray_sdk/ext/django/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'PLUGINS': (),
1111
'SAMPLING': True,
1212
'SAMPLING_RULES': None,
13+
'SAMPLER': None,
1314
'AWS_XRAY_TRACING_NAME': None,
1415
'DYNAMIC_NAMING': None,
1516
'STREAMING_THRESHOLD': None,

tests/ext/django/app/settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Config file for a django app used by django testing client
33
"""
44
import os
5+
from aws_xray_sdk.core.sampling.sampler import LocalSampler
56

67

78
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -60,6 +61,7 @@
6061
XRAY_RECORDER = {
6162
'AWS_XRAY_TRACING_NAME': 'django',
6263
'SAMPLING': False,
64+
'SAMPLER': LocalSampler(),
6365
}
6466

6567
LANGUAGE_CODE = 'en-us'

tests/ext/django/test_settings.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from unittest import mock
2+
3+
import django
4+
from aws_xray_sdk import global_sdk_config
5+
from django.test import TestCase, override_settings
6+
from django.conf import settings
7+
from django.apps import apps
8+
9+
from aws_xray_sdk.core import xray_recorder
10+
from aws_xray_sdk.core.sampling.sampler import LocalSampler
11+
12+
13+
class XRayConfigurationTestCase(TestCase):
14+
def test_sampler_can_be_configured(self):
15+
assert isinstance(settings.XRAY_RECORDER['SAMPLER'], LocalSampler)
16+
assert isinstance(xray_recorder.sampler, LocalSampler)

0 commit comments

Comments
 (0)