|
1 | 1 | from unittest import TestCase |
2 | 2 |
|
3 | | -from nose.tools import ok_ |
| 3 | +from nose.tools import eq_, ok_ |
4 | 4 |
|
5 | 5 | from ddtrace import config |
6 | 6 | from ddtrace.pin import Pin |
@@ -47,3 +47,33 @@ def test_configuration_override_instance(self): |
47 | 47 | cfg['distributed_tracing'] = False |
48 | 48 | ok_(config.get_from(self.Klass)['distributed_tracing'] is True) |
49 | 49 | ok_(config.get_from(instance)['distributed_tracing'] is False) |
| 50 | + |
| 51 | + def test_service_name_for_pin(self): |
| 52 | + # ensure for backward compatibility that changing the service |
| 53 | + # name via the Pin object also updates integration config |
| 54 | + Pin(service='intake').onto(self.Klass) |
| 55 | + instance = self.Klass() |
| 56 | + cfg = config.get_from(instance) |
| 57 | + eq_(cfg['service_name'], 'intake') |
| 58 | + |
| 59 | + def test_service_attribute_priority(self): |
| 60 | + # ensure the `service` arg has highest priority over configuration |
| 61 | + # for backward compatibility |
| 62 | + global_config = { |
| 63 | + 'service_name': 'primary_service', |
| 64 | + } |
| 65 | + Pin(service='service', _config=global_config).onto(self.Klass) |
| 66 | + instance = self.Klass() |
| 67 | + cfg = config.get_from(instance) |
| 68 | + eq_(cfg['service_name'], 'service') |
| 69 | + |
| 70 | + def test_configuration_copy(self): |
| 71 | + # ensure when a Pin is created, it copies the given configuration |
| 72 | + global_config = { |
| 73 | + 'service_name': 'service', |
| 74 | + } |
| 75 | + Pin(service='service', _config=global_config).onto(self.Klass) |
| 76 | + instance = self.Klass() |
| 77 | + cfg = config.get_from(instance) |
| 78 | + cfg['service_name'] = 'metrics' |
| 79 | + eq_(global_config['service_name'], 'service') |
0 commit comments