async def execute(self, ctx: Span, id: str, command: str, *args, tracer_config: Optional[RedisTracerConfig] = None): span = None if ctx: span = ctx.new_child() try: if span: span.kind(CLIENT) span.name("redis:%s" % id) span.metrics_tag(SPAN_TYPE, SPAN_TYPE_REDIS) span.metrics_tag(SPAN_KIND, SPAN_KIND_REDIS_QUERY) span.remote_endpoint("redis") span.tag("redis.command", command) span.annotate(repr(args)) span.start() if tracer_config: tracer_config.on_query_start(span, id, command) res = await self._conn.execute(command, *args) if span: if tracer_config: tracer_config.on_query_end(span, None, res) span.finish() except Exception as err: if span: if tracer_config: tracer_config.on_query_end(span, err, None) span.finish(exception=err) raise return res
async def health(self, ctx: Span): if self.loop is None: return coro = asyncio.open_connection(host=self.host, port=self.port, loop=self.loop) with ctx.new_child("tcp:connect", CLIENT) as span: span.tag('tcp.host', self.host) span.tag('tcp.port', str(self.port)) await asyncio.wait_for(coro, timeout=10, loop=self.loop)
async def execute( self, ctx: Span, id: str, query: str, *args: Any, timeout: float = None, tracer_config: Optional[PostgresTracerConfig] = None) -> str: with await self._lock: span = None if ctx: span = ctx.new_child() try: if span: span.kind(CLIENT) span.name("db:%s" % id) span.metrics_tag(SPAN_TYPE, SPAN_TYPE_POSTGRES) span.metrics_tag(SPAN_KIND, SPAN_KIND_POSTRGES_QUERY) span.metrics_tag('query_id', id) span.remote_endpoint("postgres") span.annotate(repr(args)) span.start() if tracer_config: tracer_config.on_query_start(span, id, query, args, timeout) res = await self._conn.execute(query, *args, timeout=timeout) if span: if tracer_config: tracer_config.on_query_end(span, None, res) span.finish() except Exception as err: if span: if tracer_config: tracer_config.on_query_end(span, err, None) span.finish(exception=err) raise return res
async def prepare( self, ctx: Span, id: str, query: str, timeout: float = None, tracer_config: Optional[PostgresTracerConfig] = None ) -> List[asyncpg.prepared_stmt.PreparedStatement]: with await self._lock: span = None if ctx: span = ctx.new_child() try: if span: span.kind(CLIENT) span.name("db:prepare:%s" % id) span.metrics_tag(SPAN_TYPE, SPAN_TYPE_POSTGRES) span.metrics_tag(SPAN_KIND, SPAN_KIND_POSTRGES_QUERY) span.metrics_tag('query_id', 'prepare:%s' % id) span.remote_endpoint("postgres") span.start() if tracer_config: tracer_config.on_query_start(span, id, query, (), timeout) res = await self._conn.prepare(query, timeout=timeout) if span: if tracer_config: tracer_config.on_query_end(span, None, res) span.finish() except Exception as err: if span: if tracer_config: tracer_config.on_query_end(span, err, None) span.finish(exception=err) raise return res