Skip to content

Commit 7952011

Browse files
authored
only try to decode aioredis command if it is a bytes object (#1308)
* only try to decode aioredis command if it is a bytes object fixes #1307 * updated changelog
1 parent 4c9870b commit 7952011

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ endif::[]
4646
* Fixed cookie sanitization when Cookie is capitalized {pull}1301[#1301]
4747
* Fix a bug with exception capturing for bad UUIDs {pull}1304[#1304]
4848
* Fix potential errors in json serialization {pull}1203[#1203]
49+
* Fix an issue with certain aioredis commands {pull}1308[#1308]
4950
5051
5152
[[release-notes-6.x]]

elasticapm/instrumentation/packages/asyncio/aioredis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@
3838
class RedisConnectionPoolInstrumentation(AbstractInstrumentedModule):
3939
name = "aioredis"
4040

41-
instrument_list = [("aioredis.pool", "ConnectionsPool.execute"),
42-
("aioredis.pool", "ConnectionsPool.execute_pubsub")]
41+
instrument_list = [
42+
("aioredis.pool", "ConnectionsPool.execute"),
43+
("aioredis.pool", "ConnectionsPool.execute_pubsub"),
44+
]
4345

4446
def call(self, module, method, wrapped, instance, args, kwargs):
4547
if len(args) > 0:
46-
wrapped_name = args[0].decode()
48+
wrapped_name = args[0]
49+
if isinstance(wrapped_name, bytes):
50+
wrapped_name = wrapped_name.decode()
4751
else:
4852
wrapped_name = self.get_wrapped_name(wrapped, instance, method)
4953

@@ -74,8 +78,10 @@ def call(self, module, method, wrapped, instance, args, kwargs):
7478
class RedisConnectionInstrumentation(AbstractInstrumentedModule):
7579
name = "aioredis"
7680

77-
instrument_list = (("aioredis.connection", "RedisConnection.execute"),
78-
("aioredis.pool", "ConnectionsPool.execute_pubsub"))
81+
instrument_list = (
82+
("aioredis.connection", "RedisConnection.execute"),
83+
("aioredis.pool", "ConnectionsPool.execute_pubsub"),
84+
)
7985

8086
def call(self, module, method, wrapped, instance, args, kwargs):
8187
span = execution_context.get_span()

tests/instrumentation/asyncio_tests/aioredis_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ async def redis_conn():
5555
await conn.wait_closed()
5656

5757

58+
@pytest.mark.integrationtest
59+
async def test_ping(instrument, elasticapm_client, redis_conn):
60+
# The PING command is sent as a byte string, so this tests if we can handle
61+
# the command both as a str and as a bytes. See #1307
62+
elasticapm_client.begin_transaction("transaction.test")
63+
redis_conn.ping()
64+
elasticapm_client.end_transaction("test")
65+
transaction = elasticapm_client.events[TRANSACTION][0]
66+
span = elasticapm_client.spans_for_transaction(transaction)[0]
67+
assert span["name"] == "PING"
68+
69+
5870
@pytest.mark.integrationtest
5971
async def test_pipeline(instrument, elasticapm_client, redis_conn):
6072
elasticapm_client.begin_transaction("transaction.test")

0 commit comments

Comments
 (0)