Skip to content

Commit

Permalink
Allow configuring different Sampler in Django App (#252)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lalvarezguillen and srprash authored Dec 7, 2020
1 parent f4a3fb4 commit f86e7db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws_xray_sdk/ext/django/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def ready(self):
daemon_address=settings.AWS_XRAY_DAEMON_ADDRESS,
sampling=settings.SAMPLING,
sampling_rules=settings.SAMPLING_RULES,
sampler=settings.SAMPLER,
context_missing=settings.AWS_XRAY_CONTEXT_MISSING,
plugins=settings.PLUGINS,
service=settings.AWS_XRAY_TRACING_NAME,
Expand Down
1 change: 1 addition & 0 deletions aws_xray_sdk/ext/django/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'PLUGINS': (),
'SAMPLING': True,
'SAMPLING_RULES': None,
'SAMPLER': None,
'AWS_XRAY_TRACING_NAME': None,
'DYNAMIC_NAMING': None,
'STREAMING_THRESHOLD': None,
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/django/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Config file for a django app used by django testing client
"""
import os
from aws_xray_sdk.core.sampling.sampler import LocalSampler


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -60,6 +61,7 @@
XRAY_RECORDER = {
'AWS_XRAY_TRACING_NAME': 'django',
'SAMPLING': False,
'SAMPLER': LocalSampler(),
}

LANGUAGE_CODE = 'en-us'
Expand Down
16 changes: 16 additions & 0 deletions tests/ext/django/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest import mock

import django
from aws_xray_sdk import global_sdk_config
from django.test import TestCase, override_settings
from django.conf import settings
from django.apps import apps

from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.sampling.sampler import LocalSampler


class XRayConfigurationTestCase(TestCase):
def test_sampler_can_be_configured(self):
assert isinstance(settings.XRAY_RECORDER['SAMPLER'], LocalSampler)
assert isinstance(xray_recorder.sampler, LocalSampler)

0 comments on commit f86e7db

Please sign in to comment.