Skip to content

Commit 547c99c

Browse files
Merge branch 'main' into feature/http-route-in-metric
2 parents d1c747e + 0507300 commit 547c99c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
203203
span_name,
204204
) = _build_span_meta_data_for_pipeline(instance)
205205

206+
exception = None
207+
206208
with tracer.start_as_current_span(
207209
span_name, kind=trace.SpanKind.CLIENT
208210
) as span:
@@ -216,13 +218,17 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
216218
response = None
217219
try:
218220
response = func(*args, **kwargs)
219-
except redis.WatchError:
221+
except redis.WatchError as watch_exception:
220222
span.set_status(StatusCode.UNSET)
223+
exception = watch_exception
221224

222225
if callable(response_hook):
223226
response_hook(span, instance, response)
224227

225-
return response
228+
if exception:
229+
raise exception
230+
231+
return response
226232

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

288+
exception = None
289+
282290
with tracer.start_as_current_span(
283291
span_name, kind=trace.SpanKind.CLIENT
284292
) as span:
@@ -292,12 +300,17 @@ async def _async_traced_execute_pipeline(func, instance, args, kwargs):
292300
response = None
293301
try:
294302
response = await func(*args, **kwargs)
295-
except redis.WatchError:
303+
except redis.WatchError as watch_exception:
296304
span.set_status(StatusCode.UNSET)
305+
exception = watch_exception
297306

298307
if callable(response_hook):
299308
response_hook(span, instance, response)
300-
return response
309+
310+
if exception:
311+
raise exception
312+
313+
return response
301314

302315
if redis.VERSION >= _REDIS_ASYNCIO_VERSION:
303316
wrap_function_wrapper(

Diff for: instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,14 @@ def test_response_error(self):
359359

360360
def test_watch_error_sync(self):
361361
def redis_operations():
362-
try:
362+
with pytest.raises(WatchError):
363363
redis_client = fakeredis.FakeStrictRedis()
364364
pipe = redis_client.pipeline(transaction=True)
365365
pipe.watch("a")
366366
redis_client.set("a", "bad") # This will cause the WatchError
367367
pipe.multi()
368368
pipe.set("a", "1")
369369
pipe.execute()
370-
except WatchError:
371-
pass
372370

373371
redis_operations()
374372

@@ -400,16 +398,14 @@ def tearDown(self):
400398
@pytest.mark.asyncio
401399
async def test_watch_error_async(self):
402400
async def redis_operations():
403-
try:
401+
with pytest.raises(WatchError):
404402
redis_client = FakeRedis()
405403
async with redis_client.pipeline(transaction=False) as pipe:
406404
await pipe.watch("a")
407405
await redis_client.set("a", "bad")
408406
pipe.multi()
409407
await pipe.set("a", "1")
410408
await pipe.execute()
411-
except WatchError:
412-
pass
413409

414410
await redis_operations()
415411

0 commit comments

Comments
 (0)