Repository: DataDog/dd-trace-py

Issue:
aioredis 1.3.x tracing does not correctly parent spans
### Which version of dd-trace-py are you using?

0.57.1

### Which version of pip are you using?

21.3.1

### Which version of the libraries are you using?

```
aioredis==1.3.1
async-timeout==4.0.2
attrs==21.4.0
coverage==6.2
-e git+ssh://git@github.com/jalaziz/dd-trace-py.git@7e36d871f2efec84c5e49f4a0f6320a9870d88c8#egg=ddtrace
hiredis==2.0.0
hypothesis==6.36.0
iniconfig==1.1.1
mock==4.0.3
opentracing==2.4.0
packaging==21.3
pluggy==1.0.0
protobuf==3.19.3
py==1.11.0
pyparsing==3.0.6
pytest==6.2.5
pytest-asyncio==0.17.2
pytest-cov==3.0.0
pytest-mock==3.6.1
six==1.16.0
sortedcontainers==2.4.0
tenacity==8.0.1
toml==0.10.2
tomli==2.0.0
```

### How can we reproduce your problem?

This test reproduces the problem:
```
@pytest.mark.asyncio
@pytest.mark.snapshot(variants={"": aioredis_version >= (2, 0), "13": aioredis_version < (2, 0)})
async def test_parenting(redis_client):
    with tracer.trace("web-request", service="test"):
        await redis_client.set("blah", "boo")
        await redis_client.set("foo", "bar")
        await redis_client.get("blah")
        await redis_client.get("foo")
```

### What is the result that you get?

The redis command spans are not correctly parented to `web-request` for `aioredis` 1.3, but they are for 2.0.

### What is the result that you expected?

The redis command spans should be correctly reported as children of `web-request`.


Discussion:

Resolving patch:
diff --git a/ddtrace/contrib/aioredis/patch.py b/ddtrace/contrib/aioredis/patch.py
--- a/ddtrace/contrib/aioredis/patch.py
+++ b/ddtrace/contrib/aioredis/patch.py
@@ -110,8 +110,13 @@ def traced_13_execute_command(func, instance, args, kwargs):
     # Don't activate the span since this operation is performed as a future which concludes sometime later on in
     # execution so subsequent operations in the stack are not necessarily semantically related
     # (we don't want this span to be the parent of all other spans created before the future is resolved)
+    parent = pin.tracer.current_span()
     span = pin.tracer.start_span(
-        redisx.CMD, service=trace_utils.ext_service(pin, config.aioredis), span_type=SpanTypes.REDIS, activate=False
+        redisx.CMD,
+        service=trace_utils.ext_service(pin, config.aioredis),
+        span_type=SpanTypes.REDIS,
+        activate=False,
+        child_of=parent,
     )
 
     span.set_tag(SPAN_MEASURED_KEY)


Test patch:
diff --git a/tests/contrib/aioredis/test_aioredis.py b/tests/contrib/aioredis/test_aioredis.py
--- a/tests/contrib/aioredis/test_aioredis.py
+++ b/tests/contrib/aioredis/test_aioredis.py
@@ -64,8 +64,10 @@ def test_patching():
         assert not isinstance(aioredis.client.Pipeline.pipeline, ObjectProxy)
     else:
         assert isinstance(aioredis.Redis.execute, ObjectProxy)
+        assert isinstance(aioredis.commands.Redis.execute, ObjectProxy)
         unpatch()
         assert not isinstance(aioredis.Redis.execute, ObjectProxy)
+        assert not isinstance(aioredis.commands.Redis.execute, ObjectProxy)
 
 
 @pytest.mark.asyncio
@@ -240,3 +242,11 @@ async def test_two_traced_pipelines(redis_client):
         response_list1[1].decode() == "boo"
     )  # response from hset is 'Integer reply: The number of fields that were added.'
     assert response_list2[1].decode() == "bar"
+
+
+@pytest.mark.asyncio
+@pytest.mark.snapshot(variants={"": aioredis_version >= (2, 0), "13": aioredis_version < (2, 0)})
+async def test_parenting(redis_client):
+    with tracer.trace("web-request", service="test"):
+        await redis_client.set("blah", "boo")
+        await redis_client.get("blah")
diff --git a/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting.json b/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting.json
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting.json
@@ -0,0 +1,65 @@
+[[
+  {
+    "name": "web-request",
+    "service": "test",
+    "resource": "web-request",
+    "trace_id": 0,
+    "span_id": 1,
+    "parent_id": 0,
+    "meta": {
+      "runtime-id": "c75fe8a124e046a88374ca4e690d96f7"
+    },
+    "metrics": {
+      "_dd.agent_psr": 1.0,
+      "_dd.top_level": 1,
+      "_dd.tracer_kr": 1.0,
+      "_sampling_priority_v1": 1,
+      "system.pid": 2807
+    },
+    "duration": 4925125,
+    "start": 1642687869451527501
+  },
+     {
+       "name": "redis.command",
+       "service": "redis",
+       "resource": "SET blah boo",
+       "trace_id": 0,
+       "span_id": 2,
+       "parent_id": 1,
+       "type": "redis",
+       "meta": {
+         "out.host": "127.0.0.1",
+         "redis.raw_command": "SET blah boo"
+       },
+       "metrics": {
+         "_dd.measured": 1,
+         "_dd.top_level": 1,
+         "out.port": 6379,
+         "out.redis_db": 0,
+         "redis.args_length": 3
+       },
+       "duration": 1989125,
+       "start": 1642687869452441335
+     },
+     {
+       "name": "redis.command",
+       "service": "redis",
+       "resource": "GET blah",
+       "trace_id": 0,
+       "span_id": 3,
+       "parent_id": 1,
+       "type": "redis",
+       "meta": {
+         "out.host": "127.0.0.1",
+         "redis.raw_command": "GET blah"
+       },
+       "metrics": {
+         "_dd.measured": 1,
+         "_dd.top_level": 1,
+         "out.port": 6379,
+         "out.redis_db": 0,
+         "redis.args_length": 2
+       },
+       "duration": 1576875,
+       "start": 1642687869454763335
+     }]]
diff --git a/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting_13.json b/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting_13.json
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.aioredis.test_aioredis.test_parenting_13.json
@@ -0,0 +1,65 @@
+[[
+  {
+    "name": "web-request",
+    "service": "test",
+    "resource": "web-request",
+    "trace_id": 0,
+    "span_id": 1,
+    "parent_id": 0,
+    "meta": {
+      "runtime-id": "f48fe46e55d54ff38b2bd90772d8001e"
+    },
+    "metrics": {
+      "_dd.agent_psr": 1.0,
+      "_dd.top_level": 1,
+      "_dd.tracer_kr": 1.0,
+      "_sampling_priority_v1": 1,
+      "system.pid": 2802
+    },
+    "duration": 2725083,
+    "start": 1642687829923888303
+  },
+     {
+       "name": "redis.command",
+       "service": "redis",
+       "resource": "SET blah boo",
+       "trace_id": 0,
+       "span_id": 2,
+       "parent_id": 1,
+       "type": "redis",
+       "meta": {
+         "out.host": "127.0.0.1",
+         "redis.raw_command": "SET blah boo"
+       },
+       "metrics": {
+         "_dd.measured": 1,
+         "_dd.top_level": 1,
+         "out.port": 6379,
+         "out.redis_db": 0,
+         "redis.args_length": 3
+       },
+       "duration": 1074709,
+       "start": 1642687829924429969
+     },
+     {
+       "name": "redis.command",
+       "service": "redis",
+       "resource": "GET blah",
+       "trace_id": 0,
+       "span_id": 3,
+       "parent_id": 1,
+       "type": "redis",
+       "meta": {
+         "out.host": "127.0.0.1",
+         "redis.raw_command": "GET blah"
+       },
+       "metrics": {
+         "_dd.measured": 1,
+         "_dd.top_level": 1,
+         "out.port": 6379,
+         "out.redis_db": 0,
+         "redis.args_length": 2
+       },
+       "duration": 809833,
+       "start": 1642687829925730428
+     }]]