@@ -216,6 +216,73 @@ describe('Plugin', () => {
216
216
. catch ( done ) ,
217
217
rawExpectedSchema . outbound
218
218
)
219
+
220
+ if ( implementation !== 'pg.native' ) {
221
+ // pg-cursor is not supported on pg.native, pg-query-stream uses pg-cursor so it is also unsupported
222
+ describe ( 'streaming capabilities' , ( ) => {
223
+ withVersions ( 'pg' , 'pg-cursor' , pgCursorVersion => {
224
+ let Cursor
225
+
226
+ beforeEach ( ( ) => {
227
+ Cursor = require ( `../../../versions/pg-cursor@${ pgCursorVersion } ` ) . get ( )
228
+ } )
229
+
230
+ it ( 'should instrument cursor-based streaming with pg-cursor' , async ( ) => {
231
+ const tracingPromise = agent . use ( traces => {
232
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'name' , expectedSchema . outbound . opName )
233
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'service' , expectedSchema . outbound . serviceName )
234
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'resource' , 'SELECT * FROM generate_series(0, 1) num' )
235
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'type' , 'sql' )
236
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'span.kind' , 'client' )
237
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'db.name' , 'postgres' )
238
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'db.type' , 'postgres' )
239
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'component' , 'pg' )
240
+ expect ( traces [ 0 ] [ 0 ] . metrics ) . to . have . property ( 'db.stream' , 1 )
241
+ expect ( traces [ 0 ] [ 0 ] . metrics ) . to . have . property ( 'network.destination.port' , 5432 )
242
+ } )
243
+
244
+ const cursor = client . query ( new Cursor ( 'SELECT * FROM generate_series(0, 1) num' ) )
245
+
246
+ cursor . read ( 1 , ( ) => {
247
+ cursor . close ( )
248
+ } )
249
+ await tracingPromise
250
+ } )
251
+ } )
252
+
253
+ withVersions ( 'pg' , 'pg-query-stream' , pgQueryStreamVersion => {
254
+ let QueryStream
255
+
256
+ beforeEach ( ( ) => {
257
+ QueryStream = require ( `../../../versions/pg-query-stream@${ pgQueryStreamVersion } ` ) . get ( )
258
+ } )
259
+
260
+ it ( 'should instrument stream-based queries with pg-query-stream' , async ( ) => {
261
+ const agentPromise = agent . use ( traces => {
262
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'name' , expectedSchema . outbound . opName )
263
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'service' , expectedSchema . outbound . serviceName )
264
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'resource' , 'SELECT * FROM generate_series(0, 1) num' )
265
+ expect ( traces [ 0 ] [ 0 ] ) . to . have . property ( 'type' , 'sql' )
266
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'span.kind' , 'client' )
267
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'db.name' , 'postgres' )
268
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'db.type' , 'postgres' )
269
+ expect ( traces [ 0 ] [ 0 ] . meta ) . to . have . property ( 'component' , 'pg' )
270
+ expect ( traces [ 0 ] [ 0 ] . metrics ) . to . have . property ( 'db.stream' , 1 )
271
+ expect ( traces [ 0 ] [ 0 ] . metrics ) . to . have . property ( 'network.destination.port' , 5432 )
272
+ } )
273
+
274
+ const query = new QueryStream ( 'SELECT * FROM generate_series(0, 1) num' , [ ] )
275
+ const stream = client . query ( query )
276
+
277
+ for await ( const row of stream ) {
278
+ expect ( row ) . to . have . property ( 'num' )
279
+ }
280
+
281
+ await agentPromise
282
+ } )
283
+ } )
284
+ } )
285
+ }
219
286
} )
220
287
} )
221
288
0 commit comments