diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 11e56ad953..c03c20ad91 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -243,3 +243,23 @@ def test_no_op_tracer_provider(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0) + + def test_db_semantic_attributes_server(self): + redis_client = redis.Redis() + connection = redis.connection.Connection() + redis_client.connection = connection + + with mock.patch.object(redis_client, "connection"): + redis_client.set("key", "value") + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + + span = spans[0] + self.assertEqual(span.name, "SET") + self.assertEqual(span.attributes.get("db.system"), "redis") + self.assertEqual(span.attributes.get("net.peer.name"), "localhost") + self.assertEqual(span.attributes.get("net.peer.port"), 6379) + self.assertEqual(span.attributes.get("net.transport"), "ip_tcp") + self.assertEqual(span.attributes.get("db.redis.database_index"), 0) + self.assertEqual(span.attributes.get("db.statement"), "SET ? ?")