How to use the ddtrace.Pin.override function in ddtrace

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 / contrib / pymemcache / test_client.py View on Github external
def make_client_pool(self, hostname, mock_socket_values, serializer=None, **kwargs):
        mock_client = pymemcache.client.base.Client(
            hostname, serializer=serializer, **kwargs
        )
        tracer = get_dummy_tracer()
        Pin.override(mock_client, tracer=tracer)

        mock_client.sock = MockSocket(mock_socket_values)
        client = pymemcache.client.base.PooledClient(hostname, serializer=serializer)
        client.client_pool = pymemcache.pool.ObjectPool(lambda: mock_client)
        return mock_client
github DataDog / dd-trace-py / tests / contrib / grpc / test_grpc.py View on Github external
def setUp(self):
        super(GrpcTestCase, self).setUp()
        patch()
        Pin.override(constants.GRPC_PIN_MODULE_SERVER, tracer=self.tracer)
        Pin.override(constants.GRPC_PIN_MODULE_CLIENT, tracer=self.tracer)
        self._start_server()
github DataDog / dd-trace-py / tests / contrib / vertica / test_vertica.py View on Github external
),
            },
        )

        # Make a copy of the vertica config first before we merge our settings over
        # DEV: First argument gets merged into the second
        copy = deepmerge(config.vertica, dict())
        overrides = deepmerge(routine_config, copy)
        with self.override_config('vertica', overrides):
            patch()
            import vertica_python

            test_tracer = get_dummy_tracer()

            conn = vertica_python.connect(**VERTICA_CONFIG)
            Pin.override(conn, service='mycustomservice', tracer=test_tracer)
            conn.cursor()  # should be traced now
            conn.close()
        spans = test_tracer.writer.pop()
        assert len(spans) == 1
        assert spans[0].name == 'get_cursor'
        assert spans[0].service == 'mycustomservice'
github DataDog / dd-trace-py / tests / contrib / molten / test_molten_di.py View on Github external
def setUp(self):
        patch()
        self.tracer = get_dummy_tracer()
        Pin.override(molten, tracer=self.tracer, service=self.TEST_SERVICE)
github DataDog / dd-trace-py / tests / contrib / celery / base.py View on Github external
def setUp(self):
        super(CeleryBaseTestCase, self).setUp()

        # keep track of original config
        self._config = dict(config.celery)
        # instrument Celery and create an app with Broker and Result backends
        patch()
        self.pin = Pin(service='celery-unittest', tracer=self.tracer)
        self.app = Celery('celery.test_app', broker=BROKER_URL, backend=BACKEND_URL)
        # override pins to use our Dummy Tracer
        Pin.override(self.app, tracer=self.tracer)
github DataDog / dd-trace-py / tests / contrib / flask / __init__.py View on Github external
def setUp(self):
        super(BaseFlaskTestCase, self).setUp()

        patch()

        self.app = flask.Flask(__name__, template_folder='test_templates/')
        self.client = self.app.test_client()
        Pin.override(self.app, tracer=self.tracer)
github DataDog / dd-trace-py / tests / contrib / sqlalchemy / test_patch.py View on Github external
def setUp(self):
        super(SQLAlchemyPatchTestCase, self).setUp()

        # create a traced engine with the given arguments
        # and configure the current PIN instance
        patch()
        dsn = 'postgresql://%(user)s:%(password)s@%(host)s:%(port)s/%(dbname)s' % POSTGRES_CONFIG
        self.engine = sqlalchemy.create_engine(dsn)
        Pin.override(self.engine, tracer=self.tracer)

        # prepare a connection
        self.conn = self.engine.connect()
github DataDog / dd-trace-py / tests / contrib / flask_autopatch / test_flask_autopatch.py View on Github external
def setUp(self):
        self.tracer = get_dummy_tracer()
        self.app = flask.Flask(__name__)
        Pin.override(self.app, service='test-flask', tracer=self.tracer)
        self.client = self.app.test_client()
github DataDog / dd-trace-py / tests / contrib / rq / test_trace.py View on Github external
def setUp(self):
        super(TestRqTracingSync, self).setUp()
        patch()
        self.r = redis.Redis()
        self.q = rq.Queue('queue-name', is_async=False, connection=self.r)
        Pin.override(rq, tracer=self.tracer)
        Pin.override(rq.job.Job, tracer=self.tracer)
        Pin.override(rq.Queue, tracer=self.tracer)
        Pin.override(rq.Worker, tracer=self.tracer)
github DataDog / dd-trace-py / tests / contrib / vertica / test_vertica.py View on Github external
def test_analytics_default(self):
        conn, cur = self.test_conn

        Pin.override(cur, tracer=self.test_tracer)

        with conn:
            cur.execute("INSERT INTO {} (a, b) VALUES (1, 'aa');".format(TEST_TABLE))
            cur.execute('SELECT * FROM {};'.format(TEST_TABLE))

        spans = self.test_tracer.writer.pop()
        self.assertEqual(len(spans), 2)
        self.assertIsNone(spans[0].get_metric(ANALYTICS_SAMPLE_RATE_KEY))