@@ -243,3 +243,64 @@ def test_no_op_tracer_provider(self):
243243
244244 spans = self .memory_exporter .get_finished_spans ()
245245 self .assertEqual (len (spans ), 0 )
246+
247+ def test_db_semantic_attributes_server (self ):
248+ redis_client = redis .Redis (host = "test.db.semantic.conv" , port = 12345 )
249+ connection = redis .connection .Connection ()
250+ redis_client .connection = connection
251+
252+ with mock .patch .object (redis_client , "connection" ):
253+ redis_client .set ("key" , "value" )
254+
255+ spans = self .memory_exporter .get_finished_spans ()
256+ self .assertEqual (len (spans ), 1 )
257+
258+ # semconv 1.20.0
259+ span = spans [0 ]
260+ self .assertEqual (span .name , "SET" )
261+ self .assertEqual (span .attributes .get ("db.system" ), "redis" )
262+ self .assertEqual (
263+ span .attributes .get ("net.peer.name" ), "test.db.semantic.conv"
264+ )
265+ self .assertEqual (span .attributes .get ("net.peer.port" ), 12345 )
266+ self .assertEqual (span .attributes .get ("net.transport" ), "ip_tcp" )
267+ self .assertEqual (span .attributes .get ("db.statement" ), "SET ? ?" )
268+ self .assertEqual (span .attributes .get ("db.redis.database_index" ), 0 )
269+
270+ self .assertNotIn ("net.sock.family" , span .attributes )
271+ self .assertNotIn ("net.sock.peer.addr" , span .attributes )
272+ self .assertNotIn ("db.connection_string" , span .attributes )
273+ self .assertNotIn ("db.user" , span .attributes )
274+ self .assertNotIn ("db.name" , span .attributes )
275+ self .assertNotIn ("db.operation" , span .attributes )
276+
277+ def test_db_semantic_attributes_socket (self ):
278+ redis_client = redis .Redis (unix_socket_path = "/tmp/semantic.conv.sock" )
279+ connection = redis .connection .Connection ()
280+ redis_client .connection = connection
281+
282+ with mock .patch .object (redis_client , "connection" ):
283+ redis_client .set ("key" , "value" )
284+
285+ spans = self .memory_exporter .get_finished_spans ()
286+ self .assertEqual (len (spans ), 1 )
287+
288+ # semconv 1.20.0
289+ span = spans [0 ]
290+ self .assertEqual (span .name , "SET" )
291+ self .assertEqual (span .attributes .get ("db.system" ), "redis" )
292+ self .assertEqual (
293+ span .attributes .get ("net.sock.peer.addr" ),
294+ "/tmp/semantic.conv.sock" ,
295+ )
296+ self .assertEqual (span .attributes .get ("net.sock.family" ), "unix" )
297+ self .assertEqual (span .attributes .get ("db.statement" ), "SET ? ?" )
298+ self .assertEqual (span .attributes .get ("db.redis.database_index" ), 0 )
299+
300+ self .assertNotIn ("net.transport" , span .attributes )
301+ self .assertNotIn ("net.peer.name" , span .attributes )
302+ self .assertNotIn ("net.peer.port" , span .attributes )
303+ self .assertNotIn ("db.connection_string" , span .attributes )
304+ self .assertNotIn ("db.user" , span .attributes )
305+ self .assertNotIn ("db.name" , span .attributes )
306+ self .assertNotIn ("db.operation" , span .attributes )
0 commit comments