11import { addTracingExtensions , Hub , makeMain } from '../../../src' ;
2- import { trace } from '../../../src/tracing' ;
2+ import { startActiveSpan } from '../../../src/tracing' ;
33import { getDefaultTestClientOptions , TestClient } from '../../mocks/client' ;
44
55beforeAll ( ( ) => {
@@ -14,7 +14,7 @@ const enum Type {
1414let hub : Hub ;
1515let client : TestClient ;
1616
17- describe ( 'trace ' , ( ) => {
17+ describe ( 'startActiveSpan ' , ( ) => {
1818 beforeEach ( ( ) => {
1919 const options = getDefaultTestClientOptions ( { tracesSampleRate : 0.0 } ) ;
2020 client = new TestClient ( options ) ;
@@ -38,7 +38,7 @@ describe('trace', () => {
3838 ] ) ( 'with %s callback and error %s' , ( _type , isError , callback , expected ) => {
3939 it ( 'should return the same value as the callback' , async ( ) => {
4040 try {
41- const result = await trace ( { name : 'GET users/[id]' } , ( ) => {
41+ const result = await startActiveSpan ( { name : 'GET users/[id]' } , ( ) => {
4242 return callback ( ) ;
4343 } ) ;
4444 expect ( result ) . toEqual ( expected ) ;
@@ -53,7 +53,7 @@ describe('trace', () => {
5353 // if tracingExtensions are not enabled
5454 jest . spyOn ( hub , 'startTransaction' ) . mockReturnValue ( undefined ) ;
5555 try {
56- const result = await trace ( { name : 'GET users/[id]' } , ( ) => {
56+ const result = await startActiveSpan ( { name : 'GET users/[id]' } , ( ) => {
5757 return callback ( ) ;
5858 } ) ;
5959 expect ( result ) . toEqual ( expected ) ;
@@ -68,7 +68,7 @@ describe('trace', () => {
6868 ref = transaction ;
6969 } ) ;
7070 try {
71- await trace ( { name : 'GET users/[id]' } , ( ) => {
71+ await startActiveSpan ( { name : 'GET users/[id]' } , ( ) => {
7272 return callback ( ) ;
7373 } ) ;
7474 } catch ( e ) {
@@ -86,7 +86,7 @@ describe('trace', () => {
8686 ref = transaction ;
8787 } ) ;
8888 try {
89- await trace (
89+ await startActiveSpan (
9090 {
9191 name : 'GET users/[id]' ,
9292 parentSampled : true ,
@@ -113,7 +113,7 @@ describe('trace', () => {
113113 ref = transaction ;
114114 } ) ;
115115 try {
116- await trace ( { name : 'GET users/[id]' } , span => {
116+ await startActiveSpan ( { name : 'GET users/[id]' } , span => {
117117 if ( span ) {
118118 span . op = 'http.server' ;
119119 }
@@ -132,8 +132,8 @@ describe('trace', () => {
132132 ref = transaction ;
133133 } ) ;
134134 try {
135- await trace ( { name : 'GET users/[id]' , parentSampled : true } , ( ) => {
136- return trace ( { name : 'SELECT * from users' } , ( ) => {
135+ await startActiveSpan ( { name : 'GET users/[id]' , parentSampled : true } , ( ) => {
136+ return startActiveSpan ( { name : 'SELECT * from users' } , ( ) => {
137137 return callback ( ) ;
138138 } ) ;
139139 } ) ;
@@ -153,8 +153,8 @@ describe('trace', () => {
153153 ref = transaction ;
154154 } ) ;
155155 try {
156- await trace ( { name : 'GET users/[id]' , parentSampled : true } , ( ) => {
157- return trace ( { name : 'SELECT * from users' } , childSpan => {
156+ await startActiveSpan ( { name : 'GET users/[id]' , parentSampled : true } , ( ) => {
157+ return startActiveSpan ( { name : 'SELECT * from users' } , childSpan => {
158158 if ( childSpan ) {
159159 childSpan . op = 'db.query' ;
160160 }
@@ -168,50 +168,5 @@ describe('trace', () => {
168168 expect ( ref . spanRecorder . spans ) . toHaveLength ( 2 ) ;
169169 expect ( ref . spanRecorder . spans [ 1 ] . op ) . toEqual ( 'db.query' ) ;
170170 } ) ;
171-
172- it ( 'calls `onError` hook' , async ( ) => {
173- const onError = jest . fn ( ) ;
174- try {
175- await trace (
176- { name : 'GET users/[id]' } ,
177- ( ) => {
178- return callback ( ) ;
179- } ,
180- onError ,
181- ) ;
182- } catch ( e ) {
183- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
184- expect ( onError ) . toHaveBeenCalledWith ( e ) ;
185- }
186- expect ( onError ) . toHaveBeenCalledTimes ( isError ? 1 : 0 ) ;
187- } ) ;
188-
189- it ( "doesn't create spans but calls onError if tracing is disabled" , async ( ) => {
190- const options = getDefaultTestClientOptions ( {
191- /* we don't set tracesSampleRate or tracesSampler */
192- } ) ;
193- client = new TestClient ( options ) ;
194- hub = new Hub ( client ) ;
195- makeMain ( hub ) ;
196-
197- const startTxnSpy = jest . spyOn ( hub , 'startTransaction' ) ;
198-
199- const onError = jest . fn ( ) ;
200- try {
201- await trace (
202- { name : 'GET users/[id]' } ,
203- ( ) => {
204- return callback ( ) ;
205- } ,
206- onError ,
207- ) ;
208- } catch ( e ) {
209- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
210- expect ( onError ) . toHaveBeenCalledWith ( e ) ;
211- }
212- expect ( onError ) . toHaveBeenCalledTimes ( isError ? 1 : 0 ) ;
213-
214- expect ( startTxnSpy ) . not . toHaveBeenCalled ( ) ;
215- } ) ;
216171 } ) ;
217172} ) ;
0 commit comments