def setup_tracer(service_name): jaeger_exporter = jaeger.JaegerSpanExporter( service_name=service_name, # configure agent agent_host_name='jaeger', agent_port=6831, ) span_processor = BatchExportSpanProcessor(jaeger_exporter) trace.set_preferred_tracer_source_implementation(lambda T: TracerSource()) trace.tracer_source().add_span_processor(span_processor) postgres_tracer = trace.tracer_source().get_tracer('postgres') trace_integration(postgres_tracer)
def setUpClass(cls): super().setUpClass() cls._connection = None cls._cursor = None cls._tracer = cls.tracer_provider.get_tracer(__name__) trace_integration(cls.tracer_provider) cls._connection = psycopg2.connect( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, password=POSTGRES_PASSWORD, host=POSTGRES_HOST, port=POSTGRES_PORT, ) cls._connection.set_session(autocommit=True) cls._cursor = cls._connection.cursor()
def setUpClass(cls): cls._connection = None cls._cursor = None cls._tracer_provider = TracerProvider() cls._tracer = Tracer(cls._tracer_provider, None) cls._span_exporter = InMemorySpanExporter() cls._span_processor = SimpleExportSpanProcessor(cls._span_exporter) cls._tracer_provider.add_span_processor(cls._span_processor) trace_integration(cls._tracer) cls._connection = psycopg2.connect( dbname=POSTGRES_DB_NAME, user=POSTGRES_USER, password=POSTGRES_PASSWORD, host=POSTGRES_HOST, port=POSTGRES_PORT, ) cls._connection.set_session(autocommit=True) cls._cursor = cls._connection.cursor()
def test_trace_integration(self): tracer = trace_api.DefaultTracer() with mock.patch("psycopg2.connect"): trace_integration(tracer) cnx = psycopg2.connect(database="test") self.assertIsNotNone(cnx.cursor_factory)