Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring different Sampler in Django App #252

Merged
merged 3 commits into from
Dec 7, 2020

Conversation

lalvarezguillen
Copy link
Contributor

This patch adapts aws_xray_sdk.ext.django to be able to configure Sampler type.

Because right now it uses aws_xray_sdk.core.sampling.sampler.DefaultSampler, and doesn't allow configuring an alternative. Which means that it's impossible to use local sampling rules with Django

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Extended aws_xray_sdk.ext.django app to be able to select Sampler, and avoid being stuck with the DefaultSampler

class XRayConfigurationTestCase(TestCase):
def test_sampler_can_be_configured(self):
assert isinstance(settings.XRAY_RECORDER['SAMPLER'], LocalSampler)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have loved to overwrite settings.XRAY_RECORDER['SAMPLER'] here, to show the recorder working with different samplers.

But because xray_recorder is configured in the ready method of the app, and the ready method is only called once when the test suite is run, that's not easy to implement (cleanly) currently. (you can read more about it here, or verify with a pdb.set_trace() on the ready method)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is way to test different samplers by having different django settings and have it loaded using settings.configure(default_settings=settings_with_LocalSampler) and then calling django.setup() for each test case. More info here. But I agree with you that it may not be clean. I think this is good for now since it tests what we want at this point.

@srprash srprash self-assigned this Dec 2, 2020
Copy link
Contributor

@srprash srprash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lalvarezguillen
Thanks for filling in this gap for the SDK. I'll update the docs to reflect the new settings parameter.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is way to test different samplers by having different django settings and have it loaded using settings.configure(default_settings=settings_with_LocalSampler) and then calling django.setup() for each test case. More info here. But I agree with you that it may not be clean. I think this is good for now since it tests what we want at this point.

@codecov-io
Copy link

codecov-io commented Dec 7, 2020

Codecov Report

Merging #252 (04494e5) into master (f4a3fb4) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #252   +/-   ##
=======================================
  Coverage   79.36%   79.36%           
=======================================
  Files          80       80           
  Lines        3159     3159           
=======================================
  Hits         2507     2507           
  Misses        652      652           
Impacted Files Coverage Δ
aws_xray_sdk/ext/django/apps.py 0.00% <ø> (ø)
aws_xray_sdk/ext/django/conf.py 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4a3fb4...04494e5. Read the comment docs.

@srprash srprash merged commit f86e7db into aws:master Dec 7, 2020
Hargrav3s pushed a commit to Gavant/aws-xray-sdk-python that referenced this pull request Mar 22, 2022
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants