Skip to content

Commit

Permalink
Reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
mpozniak95 committed Aug 28, 2024
1 parent 59b7c91 commit 748022a
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def response_hook(span, instance, response):
)
from opentelemetry.instrumentation.redis.version import __version__
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.semconv.trace import SpanAttributes, DbSystemValues
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import Span, StatusCode

_DEFAULT_SERVICE = "redis"
Expand Down Expand Up @@ -240,9 +240,7 @@ def _traced_execute_pipeline(func, instance, args, kwargs):

def _add_create_attributes(span, args):
_set_span_attribute(
span,
"redis.create_index.index",
_value_or_none(args, 1)
span, "redis.create_index.index", _value_or_none(args, 1)
)
# According to: https://github.com/redis/redis-py/blob/master/redis/commands/search/commands.py#L155 schema is last argument for execute command
try:
Expand All @@ -253,10 +251,12 @@ def _add_create_attributes(span, args):
field_attribute = ""
# Schema in format:
# [first_field_name, first_field_type, first_field_some_attribute1, first_field_some_attribute2, second_field_name, ...]
field_types = ["NUMERIC", "TEXT" ,"GEO", "TAG", "VECTOR"]
field_types = ["NUMERIC", "TEXT", "GEO", "TAG", "VECTOR"]
for index in range(len(schema)):
if schema[index] in field_types:
field_attribute += f"Field(name: {schema[index-1]}, type: {schema[index]});"
field_attribute += (
f"Field(name: {schema[index-1]}, type: {schema[index]});"
)
_set_span_attribute(
span,
"redis.create_index.fields",
Expand All @@ -265,14 +265,10 @@ def _add_create_attributes(span, args):

def _add_search_attributes(span, response, args):
_set_span_attribute(
span,
"redis.search.index",
_value_or_none(args, 1)
span, "redis.search.index", _value_or_none(args, 1)
)
_set_span_attribute(
span,
"redis.search.query",
_value_or_none(args, 2)
span, "redis.search.query", _value_or_none(args, 2)
)
# Parse response from search
# https://redis.io/docs/latest/commands/ft.search/
Expand All @@ -288,12 +284,16 @@ def _add_search_attributes(span, response, args):
return
if number_of_returned_documents:
for document_number in range(number_of_returned_documents):
document_index = _value_or_none(response, 1+2*document_number)
document_index = _value_or_none(
response, 1 + 2 * document_number
)
if document_index:
document = response[2+2*document_number]
document = response[2 + 2 * document_number]
for attribute_name_index in range(0, len(document), 2):
_set_span_attribute(
span, f"redis.search.xdoc_{document_index}.{document[attribute_name_index]}", document[attribute_name_index+1]
span,
f"redis.search.xdoc_{document_index}.{document[attribute_name_index]}",
document[attribute_name_index + 1],
)

pipeline_class = (
Expand Down

0 comments on commit 748022a

Please sign in to comment.