Beispiel #1
0
def nop_tracer():
    from ddtrace.opentracer import Tracer

    tracer = Tracer(service_name="mysvc", config={})
    # use the same test tracer used by the primary tests
    tracer._tracer = DummyTracer()
    return tracer
Beispiel #2
0
 def test_required_dd_fields(self):
     """Ensure required fields needed for successful tracing are possessed
     by the underlying datadog tracer.
     """
     # a service name is required
     tracer = Tracer("service")
     with tracer.start_span("my_span") as span:
         assert span._dd_span.service
Beispiel #3
0
    def make_ot_tracer(service_name="my_svc", config=None, scope_manager=None, context_provider=None):
        config = config or {}
        tracer = Tracer(service_name=service_name, config=config, scope_manager=scope_manager)

        # similar to how we test the ddtracer, use a dummy tracer
        dd_tracer = get_dummy_tracer()
        if context_provider:
            dd_tracer.configure(context_provider=context_provider)

        # attach the dummy tracer to the opentracer
        tracer._dd_tracer = dd_tracer
        return tracer
Beispiel #4
0
    def test_multiple_tracer_configs(self):
        """Ensure that a tracer config is a copy of the passed config."""
        config = {"enabled": True}

        tracer1 = Tracer(service_name="serv1", config=config)
        assert tracer1._service_name == "serv1"

        config["enabled"] = False
        tracer2 = Tracer(service_name="serv2", config=config)

        # Ensure tracer1's config was not mutated
        assert tracer1._service_name == "serv1"
        assert tracer2._service_name == "serv2"
Beispiel #5
0
def init_tracer(service_name, dd_tracer, scope_manager=None):
    """A method that emulates what a user of OpenTracing would call to
    initialize a Datadog opentracer.

    It accepts a Datadog tracer that should be the same one used for testing.
    """
    writer = dd_tracer.writer
    ot_tracer = Tracer(service_name,
                       dd_tracer=dd_tracer,
                       scope_manager=scope_manager)
    dd_tracer.writer = writer
    ot_tracer._dd_tracer = dd_tracer
    return ot_tracer
Beispiel #6
0
    def test_global_tags(self):
        """Global tags should be passed from the opentracer to the tracer."""
        config = {
            "global_tags": {"tag1": "value1", "tag2": 2,},
        }

        tracer = Tracer(service_name="mysvc", config=config)
        with tracer.start_span("myop") as span:
            # global tags should be attached to generated all datadog spans
            assert span._dd_span.get_tag("tag1") == "value1"
            assert span._dd_span.get_metric("tag2") == 2

            with tracer.start_span("myop2") as span2:
                assert span2._dd_span.get_tag("tag1") == "value1"
                assert span2._dd_span.get_metric("tag2") == 2
Beispiel #7
0
    def test_config(self):
        """Test the configuration of the tracer"""
        config = {"enabled": True}
        tracer = Tracer(service_name="myservice", config=config)

        assert tracer._service_name == "myservice"
        assert tracer._dd_tracer.enabled is True
Beispiel #8
0
    def test_multiple_tracer_configs(self):
        """Ensure that a tracer config is a copy of the passed config."""
        config = {'enabled': True}

        tracer1 = Tracer(service_name='serv1', config=config)
        assert tracer1._service_name == 'serv1'

        config['enabled'] = False
        tracer2 = Tracer(service_name='serv2', config=config)

        # Ensure tracer1's config was not mutated
        assert tracer1._service_name == 'serv1'
        assert tracer1._enabled is True

        assert tracer2._service_name == 'serv2'
        assert tracer2._enabled is False
Beispiel #9
0
    def test_config(self):
        """Test the configuration of the tracer"""
        config = {'enabled': True}
        tracer = Tracer(service_name='myservice', config=config)

        assert tracer._service_name == 'myservice'
        assert tracer._enabled is True
Beispiel #10
0
def test_set_global_tracer():
    """Sanity check for set_global_tracer"""
    my_tracer = Tracer("service")
    set_global_tracer(my_tracer)

    assert opentracing.tracer is my_tracer
    assert ddtrace.tracer is my_tracer._dd_tracer
Beispiel #11
0
    def test_global_tags(self):
        """Global tags should be passed from the opentracer to the tracer."""
        config = {
            'global_tags': {
                'tag1': 'value1',
                'tag2': 2,
            },
        }

        tracer = Tracer(service_name='mysvc', config=config)
        with tracer.start_span('myop') as span:
            # global tags should be attached to generated all datadog spans
            assert span._dd_span.get_tag('tag1') == 'value1'
            assert span._dd_span.get_tag('tag2') == '2'

            with tracer.start_span('myop2') as span2:
                assert span2._dd_span.get_tag('tag1') == 'value1'
                assert span2._dd_span.get_tag('tag2') == '2'
Beispiel #12
0
def init_tracer(app_name, agent_hostname, agent_port):
    tracer = Tracer(
        app_name,
        config={
            "agent_hostname": agent_hostname,
            "agent_port": agent_port
        },
        scope_manager=ContextVarsScopeManager(),
    )
    set_global_tracer(tracer)
    return tracer
Beispiel #13
0
    def test_invalid_config_key(self):
        """A config with an invalid key should raise a ConfigException."""

        config = {'enabeld': False}

        # No debug flag should not raise an error
        tracer = Tracer(service_name='mysvc', config=config)

        # With debug flag should raise an error
        config['debug'] = True
        with pytest.raises(ConfigException) as ce_info:
            tracer = Tracer(config=config)
            assert 'enabeld' in str(ce_info)
            assert tracer is not None

        # Test with multiple incorrect keys
        config['setttings'] = {}
        with pytest.raises(ConfigException) as ce_info:
            tracer = Tracer(service_name='mysvc', config=config)
            assert ['enabeld', 'setttings'] in str(ce_info)
            assert tracer is not None
Beispiel #14
0
    def test_invalid_config_key(self):
        """A config with an invalid key should raise a ConfigException."""

        config = {"enabeld": False}

        # No debug flag should not raise an error
        tracer = Tracer(service_name="mysvc", config=config)

        # With debug flag should raise an error
        config["debug"] = True
        with pytest.raises(ConfigException) as ce_info:
            tracer = Tracer(config=config)
            assert "enabeld" in str(ce_info)
            assert tracer is not None

        # Test with multiple incorrect keys
        config["setttings"] = {}
        with pytest.raises(ConfigException) as ce_info:
            tracer = Tracer(service_name="mysvc", config=config)
            assert ["enabeld", "setttings"] in str(ce_info)
            assert tracer is not None
Beispiel #15
0
 def test_ddtrace_fallback_config(self, monkeypatch):
     """Ensure datadog configuration is used by default."""
     monkeypatch.setenv("DD_TRACE_ENABLED", "false")
     tracer = Tracer(dd_tracer=DDTracer())
     assert tracer._dd_tracer.enabled is False
Beispiel #16
0
TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

# OpenTracing settings

# default tracer is opentracing.Tracer(), which does nothing
OPENTRACING_TRACER = django_opentracing.DjangoTracer(Tracer("django_app", config={}))

# default is False
OPENTRACING_TRACE_ALL = False 

# default is []
OPENTRACING_TRACED_ATTRIBUTES = ['META']


DATADOG_TRACE = {
    'ENABLED': True,
}
Beispiel #17
0
def init_dd_tracer():
    tracer = Tracer('laundry', config={})
    set_global_tracer(tracer)
from ddtrace.opentracer import Tracer

if __name__ == "__main__":
    tracer = Tracer()
    print(tracer._service_name)
Beispiel #19
0
 def test_no_service_name(self):
     """A service_name should be generated if one is not provided."""
     tracer = Tracer()
     assert tracer._service_name == "pytest"
Beispiel #20
0
def init_dd_tracer():
    tracer = Tracer()
    set_global_tracer(tracer)