How to use ddtrace - 10 common examples

To help you get started, we’ve selected a few ddtrace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / dd-trace-py / tests / commands / ddtrace_run_enabled.py View on Github external
from ddtrace import tracer

if __name__ == '__main__':
    assert tracer.enabled
    print('Test success')
github DataDog / dd-trace-py / tests / commands / ddtrace_run_hostname.py View on Github external
from ddtrace import tracer

if __name__ == '__main__':
    assert tracer.writer.api.hostname == '172.10.0.1'
    assert tracer.writer.api.port == 8120
    print('Test success')
github DataDog / dd-trace-py / tests / contrib / molten / test_molten.py View on Github external
def test_unpatch_patch(self):
        """ Tests unpatch-patch cycle """
        unpatch()
        self.assertIsNone(Pin.get_from(molten))
        molten_client()
        spans = self.tracer.writer.pop()
        self.assertEqual(len(spans), 0)

        patch()
        # Need to override Pin here as we do in setUp
        Pin.override(molten, tracer=self.tracer)
        self.assertTrue(Pin.get_from(molten) is not None)
        molten_client()
        spans = self.tracer.writer.pop()
        self.assertTrue(len(spans) > 0)
github DataDog / dd-trace-py / tests / test_pin.py View on Github external
def test_pin_does_not_override_global(self):
        # ensure that when a `Pin` is created from a class, the specific
        # instance doesn't override the global one
        class A(object):
            pass

        Pin.override(A, service='metrics')
        global_pin = Pin.get_from(A)
        global_pin._config['distributed_tracing'] = True

        a = A()
        pin = Pin.get_from(a)
        assert pin is not None
        assert pin._config['distributed_tracing'] is True
        pin._config['distributed_tracing'] = False

        assert global_pin._config['distributed_tracing'] is True
        assert pin._config['distributed_tracing'] is False
github DataDog / dd-trace-py / tests / test_pin.py View on Github external
def test_pin_does_not_override_global_with_new_instance(self):
        # ensure that when a `Pin` is created from a class, the specific
        # instance doesn't override the global one, even if only the
        # `onto()` API has been used
        class A(object):
            pass

        pin = Pin(service='metrics')
        pin.onto(A)
        global_pin = Pin.get_from(A)
        global_pin._config['distributed_tracing'] = True

        a = A()
        pin = Pin.get_from(a)
        assert pin is not None
        assert pin._config['distributed_tracing'] is True
        pin._config['distributed_tracing'] = False

        assert global_pin._config['distributed_tracing'] is True
        assert pin._config['distributed_tracing'] is False
github DataDog / dd-trace-py / tests / contrib / celery / test_app.py View on Github external
def test_patch_app(self):
        # When celery.App is patched it must include a `Pin` instance
        app = celery.Celery()
        assert Pin.get_from(app) is not None
github DataDog / dd-trace-py / tests / contrib / aiopg / test_aiopg.py View on Github external
def _get_conn_and_tracer(self):
        conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
        Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)

        return conn, self.tracer
github DataDog / dd-trace-py / tests / contrib / celery / test_patch.py View on Github external
def test_patch_before_import(self):
        from ddtrace import patch
        patch(celery=True)
        import celery

        app = celery.Celery()
        assert Pin.get_from(app) is not None