Skip to content

Commit

Permalink
chore: checks
Browse files Browse the repository at this point in the history
  • Loading branch information
therightstuff committed Aug 29, 2023
1 parent aeafb14 commit 7b3a87c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/lumigo_opentelemetry/instrumentations/redis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from typing import Any, Dict, List

from opentelemetry.trace.span import Span

from lumigo_opentelemetry.instrumentations import AbstractInstrumentor
from lumigo_opentelemetry.instrumentations.instrumentation_utils import \
add_body_attribute
from lumigo_opentelemetry.instrumentations.instrumentation_utils import (
add_body_attribute,
)


class RedisInstrumentor(AbstractInstrumentor):
Expand Down
48 changes: 27 additions & 21 deletions src/test/integration/redis/tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def run_redis_sample(sample_name: str, redis_host: str, redis_port: int):
class TestRedisSpans(unittest.TestCase):
def test_redis_set_and_get(self):
with RedisContainer("redis:latest") as redis_server:
run_redis_sample("set_and_get", redis_server.get_container_host_ip(), redis_server.get_exposed_port(6379))
run_redis_sample(
"set_and_get",
redis_server.get_container_host_ip(),
redis_server.get_exposed_port(6379),
)

wait_for_exporter()

Expand All @@ -50,16 +54,16 @@ def test_redis_set_and_get(self):
self.assertEqual(set_span[ATTRIBUTES][REDIS_RESPONSE_BODY], "True")

self.assertEqual(get_span[ATTRIBUTES][DB_SYSTEM], "redis")
self.assertEqual(
get_span[ATTRIBUTES][DB_STATEMENT],
"GET my-key"
)
self.assertEqual(get_span[ATTRIBUTES][DB_STATEMENT], "GET my-key")
self.assertEqual(get_span[ATTRIBUTES][REDIS_RESPONSE_BODY], "my-value")


def test_redis_hash(self):
with RedisContainer("redis:latest") as redis_server:
run_redis_sample("hash", redis_server.get_container_host_ip(), redis_server.get_exposed_port(6379))
run_redis_sample(
"hash",
redis_server.get_container_host_ip(),
redis_server.get_exposed_port(6379),
)

wait_for_exporter()

Expand All @@ -75,18 +79,19 @@ def test_redis_hash(self):
self.assertEqual(set_span[ATTRIBUTES][REDIS_RESPONSE_BODY], "True")

self.assertEqual(get_span[ATTRIBUTES][DB_SYSTEM], "redis")
self.assertEqual(
get_span[ATTRIBUTES][DB_STATEMENT],
"HGETALL my-key"
)
self.assertEqual(get_span[ATTRIBUTES][DB_STATEMENT], "HGETALL my-key")
self.assertEqual(
ast.literal_eval(get_span[ATTRIBUTES][REDIS_RESPONSE_BODY]),
{b'key1': b'value1', b'key2': b'value2'})

{b"key1": b"value1", b"key2": b"value2"},
)

def test_redis_transaction(self):
with RedisContainer("redis:latest") as redis_server:
run_redis_sample("transaction", redis_server.get_container_host_ip(), redis_server.get_exposed_port(6379))
run_redis_sample(
"transaction",
redis_server.get_container_host_ip(),
redis_server.get_exposed_port(6379),
)

wait_for_exporter()

Expand All @@ -98,13 +103,14 @@ def test_redis_transaction(self):
self.assertEqual(
transaction_span[ATTRIBUTES][DB_STATEMENT].split("\n"),
[
'SET my-key pre-key-value',
'GET my-key',
'SET my-key key-value',
'GET my-key',
'GET unknown-key',
]
"SET my-key pre-key-value",
"GET my-key",
"SET my-key key-value",
"GET my-key",
"GET unknown-key",
],
)
self.assertEqual(
ast.literal_eval(transaction_span[ATTRIBUTES][REDIS_RESPONSE_BODY]),
[True, b'pre-key-value', True, b'key-value', None])
[True, b"pre-key-value", True, b"key-value", None],
)

0 comments on commit 7b3a87c

Please sign in to comment.