@@ -63,6 +63,9 @@ type ClientWrapper struct {
6363 Config * nosqldb.Config
6464}
6565
66+ type ClientRequestWrapper [R any ] struct {
67+ ClientRequest R
68+ }
6669type ClientResponseWrapper [T any ] struct {
6770 ClientResponse T
6871}
@@ -128,14 +131,27 @@ func extractHostPort(endpoint string) (host, port string) {
128131 return host , port
129132}
130133
134+ func extractRequestFields (req any ) (string , string , string ) {
135+ var collection , statement , databaseName string
136+ switch r := req .(type ) {
137+ case * nosqldb.TableRequest :
138+ collection = r .TableName
139+ statement = r .Statement
140+ databaseName = r .Namespace
141+ default :
142+ // keep strings empty
143+ }
144+ return collection , statement , databaseName
145+ }
146+
131147// executeWithDatastoreSegment is a generic helper function that executes a query with a given function from the
132148// OCI Client. It takes a type parameter T as any because of the different response types that are used within the
133149// OCI Client. This function will take the transaction from the context (if it exists) and create a Datastore Segment.
134150// It will then call whatever client function has been passed in.
135- func executeWithDatastoreSegment [T any ](
151+ func executeWithDatastoreSegment [T any , R any ](
136152 cw * ClientWrapper ,
137153 ctx context.Context ,
138- req * nosqldb. TableRequest ,
154+ rw * ClientRequestWrapper [ R ] ,
139155 fn func () (T , error ),
140156) (* ClientResponseWrapper [T ], error ) {
141157
@@ -146,14 +162,14 @@ func executeWithDatastoreSegment[T any](
146162
147163 // Extract host and port from config endpoint
148164 host , port := extractHostPort (cw .Config .Endpoint )
149-
165+ collection , statement , databaseName := extractRequestFields ( rw . ClientRequest )
150166 sgmt := newrelic.DatastoreSegment {
151167 StartTime : txn .StartSegmentNow (),
152168 Product : newrelic .DatastoreOracle ,
153- Collection : req . TableName ,
154- Operation : extractOperation (req . Statement ),
155- DatabaseName : req . Namespace ,
156- ParameterizedQuery : req . Statement ,
169+ Collection : collection ,
170+ Operation : extractOperation (statement ),
171+ DatabaseName : databaseName ,
172+ ParameterizedQuery : statement ,
157173 Host : host ,
158174 PortPathOrID : port ,
159175 }
0 commit comments