@@ -144,8 +144,8 @@ describe('TraceManager', () => {
144
144
expect ( report . duration ) . toBeNull ( )
145
145
} )
146
146
147
- describe ( 'transitionDraftToActive: report errors ' , ( ) => {
148
- it ( 'reports warning when calling `transitionDraftToActive` with no reporting opts when a draft trace has not yet been created ' , ( ) => {
147
+ describe ( 'transitionDraftToActive() ' , ( ) => {
148
+ it ( 'after a trace is active: reports warning ' , ( ) => {
149
149
const traceManager = new TraceManager ( {
150
150
relationSchemas : { ticket : { ticketId : String } } ,
151
151
reportFn,
@@ -164,21 +164,28 @@ describe('TraceManager', () => {
164
164
} ,
165
165
} )
166
166
167
+ tracer . createDraft ( {
168
+ variant : 'cold_boot' ,
169
+ } )
170
+
167
171
tracer . transitionDraftToActive ( { relatedTo : { ticketId : '1' } } )
172
+ tracer . transitionDraftToActive ( { relatedTo : { ticketId : '2' } } )
168
173
169
174
expect ( reportWarningFn ) . toHaveBeenCalledWith (
170
175
expect . objectContaining ( {
171
176
message : expect . stringContaining (
172
- 'No current active trace when initializing ' ,
177
+ 'You are trying to activate a trace that has already been activated ' ,
173
178
) ,
174
179
} ) ,
175
180
expect . objectContaining ( {
176
- definition : expect . any ( Object ) ,
181
+ definition : expect . objectContaining ( {
182
+ name : 'ticket.basic-operation' ,
183
+ } ) ,
177
184
} ) ,
178
185
)
179
186
} )
180
187
181
- it ( 'reports error when calling `transitionDraftToActive` when reporting with error ' , ( ) => {
188
+ it ( 'after a trace is active and previouslyActivatedBehavior is "warn-and-continue": reports error and continues trace with new trace modification ' , ( ) => {
182
189
const traceManager = new TraceManager ( {
183
190
relationSchemas : { ticket : { ticketId : String } } ,
184
191
reportFn,
@@ -197,24 +204,45 @@ describe('TraceManager', () => {
197
204
} ,
198
205
} )
199
206
207
+ tracer . createDraft ( {
208
+ variant : 'cold_boot' ,
209
+ } )
210
+
211
+ tracer . transitionDraftToActive ( { relatedTo : { ticketId : '1' } } )
200
212
tracer . transitionDraftToActive (
201
- { relatedTo : { ticketId : '1 ' } } ,
202
- { previouslyActivatedBehavior : 'error ' } ,
213
+ { relatedTo : { ticketId : '2 ' } } ,
214
+ { previouslyActivatedBehavior : 'warn-and-continue ' } ,
203
215
)
204
216
205
- expect ( reportErrorFn ) . toHaveBeenCalledWith (
217
+ // prettier-ignore
218
+ const { spans } = getSpansFromTimeline < TicketIdRelationSchemasFixture > `
219
+ Events: ${ Render ( 'Component' , 0 , { type : 'component-render-start' } ) } --${ Render ( 'Component' , 50 ) } --${ Render ( 'end' , 50 , ) }
220
+ Time: ${ 0 } ${ 50 } ${ 100 }
221
+ `
222
+ processSpans ( spans , traceManager )
223
+
224
+ expect ( reportWarningFn ) . toHaveBeenCalledWith (
206
225
expect . objectContaining ( {
207
226
message : expect . stringContaining (
208
- 'No current active trace when initializing ' ,
227
+ 'You are trying to activate a trace that has already been activated ' ,
209
228
) ,
210
229
} ) ,
211
230
expect . objectContaining ( {
212
- definition : expect . any ( Object ) ,
231
+ definition : expect . objectContaining ( {
232
+ name : 'ticket.basic-operation' ,
233
+ } ) ,
213
234
} ) ,
214
235
)
236
+
237
+ expect ( reportFn ) . toHaveBeenCalled ( )
238
+ const report = reportFn . mock . calls [ 0 ] ! [ 0 ]
239
+
240
+ expect ( report . relatedTo ) . toEqual ( {
241
+ ticketId : '2' , // relatedTo successfully replaced
242
+ } )
215
243
} )
216
244
217
- it ( 'reports error when calling `transitionDraftToActive` before creating a Trace when reporting with error-and-continue' , ( ) => {
245
+ it ( 'after a trace is active and previouslyActivatedBehavior is " error-and-continue": reports error and continues trace with new trace modification ' , ( ) => {
218
246
const traceManager = new TraceManager ( {
219
247
relationSchemas : { ticket : { ticketId : String } } ,
220
248
reportFn,
@@ -233,60 +261,45 @@ describe('TraceManager', () => {
233
261
} ,
234
262
} )
235
263
264
+ tracer . createDraft ( {
265
+ variant : 'cold_boot' ,
266
+ } )
267
+
268
+ tracer . transitionDraftToActive ( { relatedTo : { ticketId : '1' } } )
236
269
tracer . transitionDraftToActive (
237
- { relatedTo : { ticketId : '1 ' } } ,
270
+ { relatedTo : { ticketId : '2 ' } } ,
238
271
{ previouslyActivatedBehavior : 'error-and-continue' } ,
239
272
)
240
273
274
+ // prettier-ignore
275
+ const { spans } = getSpansFromTimeline < TicketIdRelationSchemasFixture > `
276
+ Events: ${ Render ( 'Component' , 0 , { type : 'component-render-start' } ) } --${ Render ( 'Component' , 50 ) } --${ Render ( 'end' , 50 , ) }
277
+ Time: ${ 0 } ${ 50 } ${ 100 }
278
+ `
279
+ processSpans ( spans , traceManager )
280
+
241
281
expect ( reportErrorFn ) . toHaveBeenCalledWith (
242
282
expect . objectContaining ( {
243
283
message : expect . stringContaining (
244
- 'No current active trace when initializing ' ,
284
+ 'You are trying to activate a trace that has already been activated ' ,
245
285
) ,
246
286
} ) ,
247
287
expect . objectContaining ( {
248
- definition : expect . any ( Object ) ,
288
+ definition : expect . objectContaining ( {
289
+ name : 'ticket.basic-operation' ,
290
+ } ) ,
249
291
} ) ,
250
292
)
251
- } )
252
293
253
- it ( 'reports error when calling `transitionDraftToActive` when reporting with error' , ( ) => {
254
- const traceManager = new TraceManager ( {
255
- relationSchemas : { ticket : { ticketId : String } } ,
256
- reportFn,
257
- generateId,
258
- reportErrorFn,
259
- reportWarningFn,
260
- } )
294
+ expect ( reportFn ) . toHaveBeenCalled ( )
295
+ const report = reportFn . mock . calls [ 0 ] ! [ 0 ]
261
296
262
- const tracer = traceManager . createTracer ( {
263
- name : 'ticket.basic-operation' ,
264
- type : 'operation' ,
265
- relationSchemaName : 'ticket' ,
266
- requiredSpans : [ { name : 'end' } ] ,
267
- variants : {
268
- cold_boot : { timeout : DEFAULT_COLDBOOT_TIMEOUT_DURATION } ,
269
- } ,
297
+ expect ( report . relatedTo ) . toEqual ( {
298
+ ticketId : '2' , // relatedTo successfully replaced
270
299
} )
271
-
272
- tracer . transitionDraftToActive (
273
- { relatedTo : { ticketId : '1' } } ,
274
- { previouslyActivatedBehavior : 'warn-and-continue' } ,
275
- )
276
-
277
- expect ( reportWarningFn ) . toHaveBeenCalledWith (
278
- expect . objectContaining ( {
279
- message : expect . stringContaining (
280
- 'No current active trace when initializing' ,
281
- ) ,
282
- } ) ,
283
- expect . objectContaining ( {
284
- definition : expect . any ( Object ) ,
285
- } ) ,
286
- )
287
300
} )
288
301
289
- it ( 'reports warning when calling `transitionDraftToActive` with no report opts again after a trace is active ' , ( ) => {
302
+ it ( 'after a trace is active and previouslyActivatedBehavior is "error": reports error and continues trace with original trace definition ' , ( ) => {
290
303
const traceManager = new TraceManager ( {
291
304
relationSchemas : { ticket : { ticketId : String } } ,
292
305
reportFn,
@@ -312,13 +325,13 @@ describe('TraceManager', () => {
312
325
tracer . transitionDraftToActive ( { relatedTo : { ticketId : '1' } } )
313
326
tracer . transitionDraftToActive (
314
327
{ relatedTo : { ticketId : '2' } } ,
315
- { previouslyActivatedBehavior : '' } ,
328
+ { previouslyActivatedBehavior : 'error ' } ,
316
329
)
317
330
318
- expect ( reportWarningFn ) . toHaveBeenCalledWith (
331
+ expect ( reportErrorFn ) . toHaveBeenCalledWith (
319
332
expect . objectContaining ( {
320
333
message : expect . stringContaining (
321
- 'trace that has already been initialized ' ,
334
+ 'You are trying to activate a trace that has already been activated ' ,
322
335
) ,
323
336
} ) ,
324
337
expect . objectContaining ( {
@@ -327,9 +340,34 @@ describe('TraceManager', () => {
327
340
} ) ,
328
341
} ) ,
329
342
)
330
- } )
331
343
332
- // add relatedTo was overridden (expected for the 2 continue actions) or not
344
+ // prettier-ignore
345
+ const { spans } = getSpansFromTimeline < TicketIdRelationSchemasFixture > `
346
+ Events: ${ Render ( 'Component' , 0 , { type : 'component-render-start' } ) } --${ Render ( 'Component' , 50 ) } --${ Render ( 'end' , 50 , ) }
347
+ Time: ${ 0 } ${ 50 } ${ 100 }
348
+ `
349
+ processSpans ( spans , traceManager )
350
+
351
+ expect ( reportErrorFn ) . toHaveBeenCalledWith (
352
+ expect . objectContaining ( {
353
+ message : expect . stringContaining (
354
+ 'You are trying to activate a trace that has already been activated' ,
355
+ ) ,
356
+ } ) ,
357
+ expect . objectContaining ( {
358
+ definition : expect . objectContaining ( {
359
+ name : 'ticket.basic-operation' ,
360
+ } ) ,
361
+ } ) ,
362
+ )
363
+
364
+ expect ( reportFn ) . toHaveBeenCalled ( )
365
+ const report = reportFn . mock . calls [ 0 ] ! [ 0 ]
366
+
367
+ expect ( report . relatedTo ) . toEqual ( {
368
+ ticketId : '1' , // relatedTo was not replaced!
369
+ } )
370
+ } )
333
371
} )
334
372
335
373
describe ( 'interrupt()' , ( ) => {
0 commit comments