@@ -148,156 +148,151 @@ describe('Plugin', () => {
148148 } )
149149 } )
150150
151- const ignoreVersions = version =>
152- semver . intersects ( version , '3.2.0 - 3.2.1' ) // related to JSCBC-916
153-
154151 withVersions ( 'couchbase' , 'couchbase' , '>=3.0.0' , version => {
155152 let collection
156153
157- if ( ! ignoreVersions ( version ) ) {
158- describe ( 'without configuration' , ( ) => {
159- beforeEach ( done => {
160- agent . load ( 'couchbase' ) . then ( ( ) => {
161- couchbase = proxyquire ( `../../../versions/couchbase@${ version } ` , { } ) . get ( )
162- couchbase . connect ( 'couchbase://localhost' , {
163- username : 'Administrator' ,
164- password : 'password'
165- } ) . then ( _cluster => {
166- cluster = _cluster
167- bucket = cluster . bucket ( 'datadog-test' )
168- collection = bucket . defaultCollection ( )
169- } ) . then ( done ) . catch ( done )
170- } )
154+ describe ( 'without configuration' , ( ) => {
155+ beforeEach ( done => {
156+ agent . load ( 'couchbase' ) . then ( ( ) => {
157+ couchbase = proxyquire ( `../../../versions/couchbase@${ version } ` , { } ) . get ( )
158+ couchbase . connect ( 'couchbase://localhost' , {
159+ username : 'Administrator' ,
160+ password : 'password'
161+ } ) . then ( _cluster => {
162+ cluster = _cluster
163+ bucket = cluster . bucket ( 'datadog-test' )
164+ collection = bucket . defaultCollection ( )
165+ } ) . then ( done ) . catch ( done )
171166 } )
167+ } )
168+
169+ afterEach ( async ( ) => {
170+ await cluster . close ( )
171+ } )
172172
173- afterEach ( async ( ) => {
174- await cluster . close ( )
173+ after ( ( ) => {
174+ return agent . close ( { ritmReset : false } )
175+ } )
176+
177+ it ( 'should run the Query callback in the parent context' , done => {
178+ const query = 'SELECT 1+1'
179+ const span = tracer . startSpan ( 'test.query.cb' )
180+
181+ tracer . scope ( ) . activate ( span , ( ) => {
182+ cluster . query ( query ) . then ( rows => {
183+ expect ( tracer . scope ( ) . active ( ) ) . to . equal ( span )
184+ } ) . then ( done )
185+ . catch ( done )
175186 } )
187+ } )
176188
177- after ( ( ) => {
178- return agent . close ( { ritmReset : false } )
189+ it ( 'should run any Collection operations in the parent context' , done => {
190+ const span = tracer . startSpan ( 'test' )
191+ tracer . scope ( ) . activate ( span , ( ) => {
192+ collection . exists ( '1' ) . then ( ( ) => {
193+ expect ( tracer . scope ( ) . active ( ) ) . to . equal ( span )
194+ } ) . then ( done ) . catch ( done )
179195 } )
196+ } )
180197
181- it ( 'should run the Query callback in the parent context' , done => {
198+ describe ( 'queries on Cluster' , ( ) => {
199+ it ( 'should handle N1QL queries' , done => {
182200 const query = 'SELECT 1+1'
183- const span = tracer . startSpan ( 'test.query.cb' )
184201
185- tracer . scope ( ) . activate ( span , ( ) => {
186- cluster . query ( query ) . then ( rows => {
187- expect ( tracer . scope ( ) . active ( ) ) . to . equal ( span )
188- } ) . then ( done )
189- . catch ( done )
190- } )
191- } )
202+ agent
203+ . use ( traces => {
204+ const span = traces [ 0 ] [ 0 ]
205+ expect ( span ) . to . have . property ( 'name' , 'couchbase.query' )
206+ expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
207+ expect ( span ) . to . have . property ( 'resource' , query )
208+ expect ( span ) . to . have . property ( 'type' , 'sql' )
209+ expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
210+ } )
211+ . then ( done )
212+ . catch ( done )
192213
193- it ( 'should run any Collection operations in the parent context' , done => {
194- const span = tracer . startSpan ( 'test' )
195- tracer . scope ( ) . activate ( span , ( ) => {
196- collection . exists ( '1' ) . then ( ( ) => {
197- expect ( tracer . scope ( ) . active ( ) ) . to . equal ( span )
198- } ) . then ( done ) . catch ( done )
199- } )
214+ cluster . query ( query ) . catch ( done )
200215 } )
201216
202- describe ( 'queries on Cluster' , ( ) => {
203- it ( 'should handle N1QL queries' , done => {
204- const query = 'SELECT 1+1'
205-
206- agent
207- . use ( traces => {
208- const span = traces [ 0 ] [ 0 ]
209- expect ( span ) . to . have . property ( 'name' , 'couchbase.query' )
210- expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
211- expect ( span ) . to . have . property ( 'resource' , query )
212- expect ( span ) . to . have . property ( 'type' , 'sql' )
213- expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
214- } )
215- . then ( done )
216- . catch ( done )
217-
218- cluster . query ( query ) . catch ( done )
219- } )
217+ it ( 'should handle storage queries' , done => {
218+ agent
219+ . use ( traces => {
220+ const span = traces [ 0 ] [ 0 ]
221+ expect ( span ) . to . have . property ( 'name' , 'couchbase.upsert' )
222+ expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
223+ expect ( span ) . to . have . property ( 'resource' , 'couchbase.upsert' )
224+ expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
225+ expect ( span . meta ) . to . have . property ( 'couchbase.bucket.name' , 'datadog-test' )
226+ expect ( span . meta ) . to . have . property ( 'couchbase.collection.name' , '_default' )
227+ } )
228+ . then ( done )
229+ . catch ( done )
220230
221- it ( 'should handle storage queries' , done => {
222- agent
223- . use ( traces => {
224- const span = traces [ 0 ] [ 0 ]
225- expect ( span ) . to . have . property ( 'name' , 'couchbase.upsert' )
226- expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
227- expect ( span ) . to . have . property ( 'resource' , 'couchbase.upsert' )
228- expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
229- expect ( span . meta ) . to . have . property ( 'couchbase.bucket.name' , 'datadog-test' )
230- expect ( span . meta ) . to . have . property ( 'couchbase.collection.name' , '_default' )
231- } )
232- . then ( done )
233- . catch ( done )
234-
235- collection . upsert ( 'testdoc' , { name : 'Frank' } ) . catch ( err => done ( err ) )
236- } )
231+ collection . upsert ( 'testdoc' , { name : 'Frank' } ) . catch ( err => done ( err ) )
232+ } )
237233
238- it ( 'should skip instrumentation for invalid arguments' , ( done ) => {
239- const checkError = ( e ) => {
240- expect ( e . message ) . to . be . oneOf ( [
241- // depending on version of node
242- 'Cannot read property \'toString\' of undefined' ,
243- 'Cannot read properties of undefined (reading \'toString\')' ,
244- 'parsing failure' // sdk 4
245- ] )
246- done ( )
247- }
248- try {
249- cluster . query ( undefined ) . catch ( checkError ) // catch bad errors
250- } catch ( e ) {
251- // catch errors conventionally as well
252- checkError ( e )
253- }
254- } )
234+ it ( 'should skip instrumentation for invalid arguments' , ( done ) => {
235+ const checkError = ( e ) => {
236+ expect ( e . message ) . to . be . oneOf ( [
237+ // depending on version of node
238+ 'Cannot read property \'toString\' of undefined' ,
239+ 'Cannot read properties of undefined (reading \'toString\')' ,
240+ 'parsing failure' // sdk 4
241+ ] )
242+ done ( )
243+ }
244+ try {
245+ cluster . query ( undefined ) . catch ( checkError ) // catch bad errors
246+ } catch ( e ) {
247+ // catch errors conventionally as well
248+ checkError ( e )
249+ }
255250 } )
251+ } )
256252
257- describe ( 'operations still work with callbacks' , ( ) => {
258- it ( 'should perform normal cluster query operation with callback' , done => {
259- agent
260- . use ( traces => {
261- const span = traces [ 0 ] [ 0 ]
262- expect ( span ) . to . have . property ( 'name' , 'couchbase.query' )
263- expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
264- expect ( span ) . to . have . property ( 'resource' , query )
265- expect ( span ) . to . have . property ( 'type' , 'sql' )
266- expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
267- } )
268- . then ( done )
269- . catch ( done )
270-
271- const query = 'SELECT 1+1'
272- cluster . query ( query , ( err , rows ) => {
273- if ( err ) done ( err )
274- } )
275- } )
276- describe ( 'errors are handled correctly in callbacks' , ( ) => {
277- it ( 'should catch error in callback for non-traced functions' , done => {
278- const invalidIndex = '-1'
279- collection . get ( invalidIndex , ( err ) => { if ( err ) done ( ) } )
253+ describe ( 'operations still work with callbacks' , ( ) => {
254+ it ( 'should perform normal cluster query operation with callback' , done => {
255+ agent
256+ . use ( traces => {
257+ const span = traces [ 0 ] [ 0 ]
258+ expect ( span ) . to . have . property ( 'name' , 'couchbase.query' )
259+ expect ( span ) . to . have . property ( 'service' , 'test-couchbase' )
260+ expect ( span ) . to . have . property ( 'resource' , query )
261+ expect ( span ) . to . have . property ( 'type' , 'sql' )
262+ expect ( span . meta ) . to . have . property ( 'span.kind' , 'client' )
280263 } )
264+ . then ( done )
265+ . catch ( done )
281266
282- // due to bug in couchbase for these versions (see JSCBC-945)
283- if ( ! semver . intersects ( '3.2.0 - 3.2.1' , version ) ) {
284- it ( 'should catch errors in callback and report error in trace' , done => {
285- const invalidQuery = 'SELECT'
286- const cb = sinon . spy ( )
287- agent
288- . use ( traces => {
289- const span = traces [ 0 ] [ 0 ]
290- expect ( cb ) . to . have . been . calledOnce
291- // different couchbase sdk versions will have different error messages/types
292- expect ( span . error ) . to . equal ( 1 )
293- } ) . then ( done ) . catch ( done )
294- cluster . query ( invalidQuery , cb )
295- } )
296- }
267+ const query = 'SELECT 1+1'
268+ cluster . query ( query , ( err , rows ) => {
269+ if ( err ) done ( err )
270+ } )
271+ } )
272+ describe ( 'errors are handled correctly in callbacks' , ( ) => {
273+ it ( 'should catch error in callback for non-traced functions' , done => {
274+ const invalidIndex = '-1'
275+ collection . get ( invalidIndex , ( err ) => { if ( err ) done ( ) } )
297276 } )
277+
278+ // due to bug in couchbase for these versions (see JSCBC-945)
279+ if ( ! semver . intersects ( '3.2.0 - 3.2.1' , version ) ) {
280+ it ( 'should catch errors in callback and report error in trace' , done => {
281+ const invalidQuery = 'SELECT'
282+ const cb = sinon . spy ( )
283+ agent
284+ . use ( traces => {
285+ const span = traces [ 0 ] [ 0 ]
286+ expect ( cb ) . to . have . been . calledOnce
287+ // different couchbase sdk versions will have different error messages/types
288+ expect ( span . error ) . to . equal ( 1 )
289+ } ) . then ( done ) . catch ( done )
290+ cluster . query ( invalidQuery , cb )
291+ } )
292+ }
298293 } )
299294 } )
300- }
295+ } )
301296 } )
302297 } )
303298} )
0 commit comments