@@ -29,10 +29,6 @@ class PostgreSqlInstrumentation
2929    public  static  function  register (): void 
3030    {
3131
32-         //TODO DB_OPERATION_BATCH_SIZE 
33- //TODO Large objet - track by PgLob instance 
34- //db.response.status_code 
35- 
3632        // https://opentelemetry.io/docs/specs/semconv/database/postgresql/ 
3733        $ instrumentation  = new  CachedInstrumentation (
3834            'io.opentelemetry.contrib.php.postgresql ' ,
@@ -69,7 +65,7 @@ public static function register(): void
6965                self ::basicPreHook ('pg_convert ' , $ instrumentation , $ tracker , ...$ args );
7066            },
7167            post: static  function  (...$ args ) use  ($ instrumentation , $ tracker ) {
72-                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , true ,  ...$ args );
68+                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , true , null ,  ...$ args );
7369            }
7470        );
7571
@@ -82,7 +78,7 @@ public static function register(): void
8278                self ::basicPreHook ('pg_copy_from ' , $ instrumentation , $ tracker , ...$ args );
8379            },
8480            post: static  function  (...$ args ) use  ($ instrumentation , $ tracker ) {
85-                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , ...$ args );
81+                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , null ,  ...$ args );
8682            }
8783        );
8884
@@ -93,7 +89,7 @@ public static function register(): void
9389                self ::basicPreHook ('pg_copy_to ' , $ instrumentation , $ tracker , ...$ args );
9490            },
9591            post: static  function  (...$ args ) use  ($ instrumentation , $ tracker ) {
96-                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , ...$ args );
92+                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , null ,  ...$ args );
9793            }
9894        );
9995
@@ -104,7 +100,7 @@ public static function register(): void
104100                self ::basicPreHook ('pg_delete ' , $ instrumentation , $ tracker , ...$ args );
105101            },
106102            post: static  function  (...$ args ) use  ($ instrumentation , $ tracker ) {
107-                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , ...$ args );
103+                 self ::tableOperationsPostHook ($ instrumentation , $ tracker , false , ' DELETE ' ,  ...$ args );
108104            }
109105        );
110106
@@ -126,7 +122,7 @@ public static function register(): void
126122                self ::basicPreHook ('pg_execute ' , $ instrumentation , $ tracker , ...$ args );
127123            },
128124            post: static  function  (...$ args ) use  ($ instrumentation , $ tracker ) {
129-                 self ::executePostHook ($ instrumentation , false ,  $ tracker , ...$ args );
125+                 self ::executePostHook ($ instrumentation , $ tracker ,  false ,   ...$ args );
130126            }
131127        );
132128
@@ -315,13 +311,16 @@ private static function basicPostHook(CachedInstrumentation $instrumentation, Pg
315311        self ::endSpan ($ attributes , $ exception , $ errorStatus );
316312    }
317313
318-     private  static  function  tableOperationsPostHook (CachedInstrumentation   $ instrumentation , PgSqlTracker   $ tracker , bool  $ dropIfNoError , $ obj , array  $ params , mixed  $ retVal , ?\Throwable   $ exception )
314+     private  static  function  tableOperationsPostHook (CachedInstrumentation   $ instrumentation , PgSqlTracker   $ tracker , bool  $ dropIfNoError , ? string   $ operationName ,  $ obj , array  $ params , mixed  $ retVal , ?\Throwable   $ exception )
319315    {
320316        $ connection  = $ params [0 ];
321317        $ attributes  = null ;
322318        if  ($ connection  instanceof  Connection) {
323319            $ attributes  = $ tracker ->getConnectionAttributes ($ connection );
324-             $ attributes [TraceAttributes::DB_NAMESPACE ] = mb_convert_encoding ($ params [1 ], 'UTF-8 ' );
320+             $ attributes [TraceAttributes::DB_COLLECTION_NAME ] = mb_convert_encoding ($ params [1 ], 'UTF-8 ' );
321+             if  ($ operationName ) {
322+                 $ attributes [TraceAttributes::DB_OPERATION_NAME ] = $ operationName ;
323+             }
325324        }
326325
327326        $ errorStatus  = $ retVal  == false  ? pg_last_error ($ params [0 ]) : null ;
@@ -464,6 +463,7 @@ private static function selectPostHook(CachedInstrumentation $instrumentation, P
464463            if  ($ query ) {
465464                $ attributes [TraceAttributes::DB_QUERY_TEXT ] = mb_convert_encoding ($ query , 'UTF-8 ' );
466465            }
466+             $ attributes [TraceAttributes::DB_COLLECTION_NAME ] = mb_convert_encoding ($ table , 'UTF-8 ' );
467467            $ attributes [TraceAttributes::DB_OPERATION_NAME ] = 'SELECT ' ;
468468        }
469469
@@ -511,9 +511,6 @@ private static function loReadPostHook(CachedInstrumentation $instrumentation, P
511511            if  ($ connection  = $ tracker ->getConnectionFromLob ($ lob )) {
512512                $ attributes  = $ tracker ->getConnectionAttributes ($ connection );
513513            }
514-             if  ($ retVal  !== false ) {
515-                 $ attributes ['db.postgres.bytes_read ' ] = $ params [1 ];
516-             }
517514        }
518515        $ attributes [TraceAttributes::DB_OPERATION_NAME ] = 'READ ' ;
519516        $ errorStatus  = $ retVal  == false  ? pg_last_error ($ params [0 ]) : null ;
@@ -551,14 +548,7 @@ private static function loUnlinkPostHook(CachedInstrumentation $instrumentation,
551548
552549    private  static  function  loImportExportPostHook (CachedInstrumentation   $ instrumentation , PgSqlTracker   $ tracker , string  $ operation , $ obj , array  $ params , mixed  $ retVal , ?\Throwable   $ exception )
553550    {
554-         $ attributes  = [];
555- 
556-         $ lob  = $ params [0 ];
557-         if  ($ lob  instanceof  Lob) {
558-             if  ($ connection  = $ tracker ->getConnectionFromLob ($ lob )) {
559-                 $ attributes  = $ tracker ->getConnectionAttributes ($ connection );
560-             }
561-         }
551+         $ attributes  = $ tracker ->getConnectionAttributes ($ params [0 ]);
562552        $ attributes [TraceAttributes::DB_OPERATION_NAME ] = $ operation ;
563553
564554        $ errorStatus  = $ retVal  == false  ? pg_last_error ($ params [0 ]) : null ;
0 commit comments