diff --git a/instrumentation/opentelemetry-instrumentation-redis/.python-version b/instrumentation/opentelemetry-instrumentation-redis/.python-version new file mode 100644 index 0000000000..8f7569d064 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-redis/.python-version @@ -0,0 +1 @@ +otel diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py index c5f19fc736..12afb7e98a 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py @@ -203,6 +203,8 @@ def _traced_execute_pipeline(func, instance, args, kwargs): span_name, ) = _build_span_meta_data_for_pipeline(instance) + reraisable = None + with tracer.start_as_current_span( span_name, kind=trace.SpanKind.CLIENT ) as span: @@ -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 e: span.set_status(StatusCode.UNSET) + reraisable = e if callable(response_hook): response_hook(span, instance, response) - return response + if reraisable: + raise reraisable + + return response pipeline_class = ( "BasePipeline" if redis.VERSION < (3, 0, 0) else "Pipeline" @@ -279,6 +285,8 @@ async def _async_traced_execute_pipeline(func, instance, args, kwargs): span_name, ) = _build_span_meta_data_for_pipeline(instance) + reraisable = None + with tracer.start_as_current_span( span_name, kind=trace.SpanKind.CLIENT ) as span: @@ -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 e: span.set_status(StatusCode.UNSET) + reraisable = e if callable(response_hook): response_hook(span, instance, response) - return response + + if reraisable: + raise reraisable + + return response if redis.VERSION >= _REDIS_ASYNCIO_VERSION: wrap_function_wrapper( diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 23d21b6e5a..c436589adb 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -359,7 +359,7 @@ 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") @@ -367,8 +367,6 @@ def redis_operations(): pipe.multi() pipe.set("a", "1") pipe.execute() - except WatchError: - pass redis_operations() @@ -400,7 +398,7 @@ 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") @@ -408,8 +406,6 @@ async def redis_operations(): pipe.multi() await pipe.set("a", "1") await pipe.execute() - except WatchError: - pass await redis_operations()