Skip to content

Commit

Permalink
Merge branch 'main' into feature/http-route-in-metric
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzaloGuasch authored Jul 18, 2024
2 parents d1c747e + 0507300 commit 547c99c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
span_name,
) = _build_span_meta_data_for_pipeline(instance)

exception = None

with tracer.start_as_current_span(
span_name, kind=trace.SpanKind.CLIENT
) as span:
Expand All @@ -216,13 +218,17 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
response = None
try:
response = func(*args, **kwargs)
except redis.WatchError:
except redis.WatchError as watch_exception:
span.set_status(StatusCode.UNSET)
exception = watch_exception

if callable(response_hook):
response_hook(span, instance, response)

return response
if exception:
raise exception

return response

pipeline_class = (
"BasePipeline" if redis.VERSION < (3, 0, 0) else "Pipeline"
Expand Down Expand Up @@ -279,6 +285,8 @@ async def _async_traced_execute_pipeline(func, instance, args, kwargs):
span_name,
) = _build_span_meta_data_for_pipeline(instance)

exception = None

with tracer.start_as_current_span(
span_name, kind=trace.SpanKind.CLIENT
) as span:
Expand All @@ -292,12 +300,17 @@ async def _async_traced_execute_pipeline(func, instance, args, kwargs):
response = None
try:
response = await func(*args, **kwargs)
except redis.WatchError:
except redis.WatchError as watch_exception:
span.set_status(StatusCode.UNSET)
exception = watch_exception

if callable(response_hook):
response_hook(span, instance, response)
return response

if exception:
raise exception

return response

if redis.VERSION >= _REDIS_ASYNCIO_VERSION:
wrap_function_wrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,14 @@ def test_response_error(self):

def test_watch_error_sync(self):
def redis_operations():
try:
with pytest.raises(WatchError):
redis_client = fakeredis.FakeStrictRedis()
pipe = redis_client.pipeline(transaction=True)
pipe.watch("a")
redis_client.set("a", "bad") # This will cause the WatchError
pipe.multi()
pipe.set("a", "1")
pipe.execute()
except WatchError:
pass

redis_operations()

Expand Down Expand Up @@ -400,16 +398,14 @@ def tearDown(self):
@pytest.mark.asyncio
async def test_watch_error_async(self):
async def redis_operations():
try:
with pytest.raises(WatchError):
redis_client = FakeRedis()
async with redis_client.pipeline(transaction=False) as pipe:
await pipe.watch("a")
await redis_client.set("a", "bad")
pipe.multi()
await pipe.set("a", "1")
await pipe.execute()
except WatchError:
pass

await redis_operations()

Expand Down

0 comments on commit 547c99c

Please sign in to comment.