Skip to content

Commit 2bea23e

Browse files
committed
auto-fix import order and formatting via pre-commit (ruff) (#3826)
1 parent 70bf3d6 commit 2bea23e

File tree

1 file changed

+40
-16
lines changed
  • instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis

1 file changed

+40
-16
lines changed

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ def response_hook(span, instance, response):
123123
from wrapt import wrap_function_wrapper
124124

125125
from opentelemetry import trace
126+
from opentelemetry.instrumentation._semconv import (
127+
_OpenTelemetrySemanticConventionStability,
128+
_OpenTelemetryStabilitySignalType,
129+
_report_new,
130+
_report_old,
131+
)
126132
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
127133
from opentelemetry.instrumentation.redis.package import _instruments
128134
from opentelemetry.instrumentation.redis.util import (
@@ -138,12 +144,6 @@ def response_hook(span, instance, response):
138144
from opentelemetry.semconv._incubating.attributes.db_attributes import (
139145
DB_STATEMENT,
140146
)
141-
from opentelemetry.instrumentation._semconv import (
142-
_OpenTelemetrySemanticConventionStability,
143-
_OpenTelemetryStabilitySignalType,
144-
_report_new,
145-
_report_old,
146-
)
147147
from opentelemetry.trace import (
148148
StatusCode,
149149
Tracer,
@@ -190,6 +190,7 @@ def response_hook(span, instance, response):
190190

191191
_INSTRUMENTATION_ATTR = "_is_instrumented_by_opentelemetry"
192192

193+
193194
def _get_redis_conn_info(instance):
194195
host, port, db, unix_sock = None, None, None, None
195196
pool = getattr(instance, "connection_pool", None)
@@ -201,6 +202,7 @@ def _get_redis_conn_info(instance):
201202
unix_sock = conn_kwargs.get("path")
202203
return host, port, db, unix_sock
203204

205+
204206
def _traced_execute_factory(
205207
tracer: Tracer,
206208
request_hook: RequestHook | None = None,
@@ -244,7 +246,11 @@ def _traced_execute_command(
244246
if unix_sock:
245247
span.set_attribute("network.peer.address", unix_sock)
246248
span.set_attribute("network.transport", "unix")
247-
if args and args[0] in ("EVALSHA", "EVAL") and len(args) > 1:
249+
if (
250+
args
251+
and args[0] in ("EVALSHA", "EVAL")
252+
and len(args) > 1
253+
):
248254
span.set_attribute("db.stored_procedure.name", args[1])
249255
if span.name == "redis.create_index":
250256
_add_create_attributes(span, args)
@@ -260,7 +266,9 @@ def _traced_execute_command(
260266
span.set_attribute("db.response.status_code", prefix)
261267
span.set_attribute("error.type", prefix)
262268
else:
263-
span.set_attribute("error.type", type(exc).__qualname__)
269+
span.set_attribute(
270+
"error.type", type(exc).__qualname__
271+
)
264272
if span.is_recording():
265273
span.set_status(StatusCode.ERROR)
266274
raise
@@ -300,7 +308,9 @@ def _traced_execute_pipeline(
300308
if _report_old(semconv_opt_in_mode):
301309
span.set_attribute(DB_STATEMENT, resource)
302310
_set_connection_attributes(span, instance)
303-
span.set_attribute("db.redis.pipeline_length", len(command_stack))
311+
span.set_attribute(
312+
"db.redis.pipeline_length", len(command_stack)
313+
)
304314
if _report_new(semconv_opt_in_mode):
305315
span.set_attribute("db.system.name", "redis")
306316
span.set_attribute("db.operation.name", "PIPELINE")
@@ -309,7 +319,9 @@ def _traced_execute_pipeline(
309319
span.set_attribute("db.namespace", str(db))
310320
span.set_attribute("db.query.text", resource)
311321
if len(command_stack) > 1:
312-
span.set_attribute("db.operation.batch.size", len(command_stack))
322+
span.set_attribute(
323+
"db.operation.batch.size", len(command_stack)
324+
)
313325
if host:
314326
span.set_attribute("server.address", host)
315327
span.set_attribute("network.peer.address", host)
@@ -378,7 +390,11 @@ async def _async_traced_execute_command(
378390
if unix_sock:
379391
span.set_attribute("network.peer.address", unix_sock)
380392
span.set_attribute("network.transport", "unix")
381-
if args and args[0] in ("EVALSHA", "EVAL") and len(args) > 1:
393+
if (
394+
args
395+
and args[0] in ("EVALSHA", "EVAL")
396+
and len(args) > 1
397+
):
382398
span.set_attribute("db.stored_procedure.name", args[1])
383399
if callable(request_hook):
384400
request_hook(span, instance, args, kwargs)
@@ -392,7 +408,9 @@ async def _async_traced_execute_command(
392408
span.set_attribute("db.response.status_code", prefix)
393409
span.set_attribute("error.type", prefix)
394410
else:
395-
span.set_attribute("error.type", type(exc).__qualname__)
411+
span.set_attribute(
412+
"error.type", type(exc).__qualname__
413+
)
396414
if span.is_recording():
397415
span.set_status(StatusCode.ERROR)
398416
raise
@@ -433,7 +451,9 @@ async def _async_traced_execute_pipeline(
433451
if _report_old(semconv_opt_in_mode):
434452
span.set_attribute(DB_STATEMENT, resource)
435453
_set_connection_attributes(span, instance)
436-
span.set_attribute("db.redis.pipeline_length", len(command_stack))
454+
span.set_attribute(
455+
"db.redis.pipeline_length", len(command_stack)
456+
)
437457
if _report_new(semconv_opt_in_mode):
438458
span.set_attribute("db.system.name", "redis")
439459
span.set_attribute("db.operation.name", "PIPELINE")
@@ -442,7 +462,9 @@ async def _async_traced_execute_pipeline(
442462
span.set_attribute("db.namespace", str(db))
443463
span.set_attribute("db.query.text", resource)
444464
if len(command_stack) > 1:
445-
span.set_attribute("db.operation.batch.size", len(command_stack))
465+
span.set_attribute(
466+
"db.operation.batch.size", len(command_stack)
467+
)
446468
if host:
447469
span.set_attribute("server.address", host)
448470
span.set_attribute("network.peer.address", host)
@@ -463,14 +485,16 @@ async def _async_traced_execute_pipeline(
463485
span.set_attribute("db.response.status_code", prefix)
464486
span.set_attribute("error.type", prefix)
465487
else:
466-
span.set_attribute("error.type", type(exc).__qualname__)
488+
span.set_attribute(
489+
"error.type", type(exc).__qualname__
490+
)
467491
if span.is_recording():
468492
span.set_status(StatusCode.ERROR)
469493
raise
470494
if callable(response_hook):
471495
response_hook(span, instance, response)
472496

473-
if exception:
497+
if exception is not None:
474498
raise exception
475499

476500
return response

0 commit comments

Comments
 (0)