@microsoft/agents-hosting-dialogs 1.5.0-beta.6.ga236d9a19c → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DialogsTraceDefinitions = void 0;
6
+ const agents_telemetry_1 = require("@microsoft/agents-telemetry");
7
+ const metrics_1 = require("./metrics");
8
+ const agents_activity_1 = require("@microsoft/agents-activity");
9
+ const unknownValue = (value) => value || 'unknown';
10
+ const defaultActivity = agents_activity_1.Activity.fromObject({ type: 'unknown' });
11
+ exports.DialogsTraceDefinitions = {
12
+ run: agents_telemetry_1.trace.define({
13
+ name: agents_telemetry_1.SpanNames.DIALOGS_RUN,
14
+ record: {
15
+ dialogId: '',
16
+ activity: defaultActivity,
17
+ status: 'unknown',
18
+ attemptCount: 0,
19
+ },
20
+ end({ span, record }) {
21
+ var _a, _b, _c, _d, _e;
22
+ span.setAttributes({
23
+ 'dialog.root_id': unknownValue(record.dialogId),
24
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
25
+ 'activity.channel_id': unknownValue((_b = record.activity) === null || _b === void 0 ? void 0 : _b.channelId),
26
+ 'activity.conversation_id': unknownValue((_d = (_c = record.activity) === null || _c === void 0 ? void 0 : _c.conversation) === null || _d === void 0 ? void 0 : _d.id),
27
+ 'dialog.status': unknownValue(record.status),
28
+ 'dialog.attempt_count': (_e = record.attemptCount) !== null && _e !== void 0 ? _e : 0,
29
+ });
30
+ }
31
+ }),
32
+ contextBegin: agents_telemetry_1.trace.define({
33
+ name: agents_telemetry_1.SpanNames.DIALOGS_CONTEXT_BEGIN,
34
+ record: {
35
+ dialogId: '',
36
+ name: 'unknown',
37
+ parentId: '',
38
+ status: 'unknown',
39
+ activity: defaultActivity,
40
+ },
41
+ end({ span, record, duration }) {
42
+ var _a, _b, _c;
43
+ const spanAttributes = {
44
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
45
+ 'activity.conversation_id': unknownValue((_c = (_b = record.activity) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.id),
46
+ 'dialog.id': unknownValue(record.dialogId),
47
+ 'dialog.name': unknownValue(record.name),
48
+ 'dialog.parent_id': unknownValue(record.parentId),
49
+ 'dialog.status': unknownValue(record.status),
50
+ };
51
+ span.setAttributes(spanAttributes);
52
+ const metricAttributes = {
53
+ operation: 'begin',
54
+ 'result.status': unknownValue(record.status),
55
+ };
56
+ metrics_1.DialogsMetrics.contextCount.add(1, metricAttributes);
57
+ metrics_1.DialogsMetrics.contextDuration.record(duration, metricAttributes);
58
+ }
59
+ }),
60
+ contextContinue: agents_telemetry_1.trace.define({
61
+ name: agents_telemetry_1.SpanNames.DIALOGS_CONTEXT_CONTINUE,
62
+ record: {
63
+ dialogId: '',
64
+ name: 'unknown',
65
+ status: 'unknown',
66
+ activity: defaultActivity,
67
+ },
68
+ end({ span, record, duration }) {
69
+ var _a, _b, _c;
70
+ const spanAttributes = {
71
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
72
+ 'activity.conversation_id': unknownValue((_c = (_b = record.activity) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.id),
73
+ 'dialog.id': unknownValue(record.dialogId),
74
+ 'dialog.name': unknownValue(record.name),
75
+ 'dialog.status': unknownValue(record.status),
76
+ };
77
+ span.setAttributes(spanAttributes);
78
+ const metricAttributes = {
79
+ operation: 'continue',
80
+ 'result.status': unknownValue(record.status),
81
+ };
82
+ metrics_1.DialogsMetrics.contextCount.add(1, metricAttributes);
83
+ metrics_1.DialogsMetrics.contextDuration.record(duration, metricAttributes);
84
+ }
85
+ }),
86
+ contextEnd: agents_telemetry_1.trace.define({
87
+ name: agents_telemetry_1.SpanNames.DIALOGS_CONTEXT_END,
88
+ record: {
89
+ activity: defaultActivity,
90
+ dialogId: '',
91
+ name: 'unknown',
92
+ status: 'unknown',
93
+ },
94
+ end({ span, record, duration }) {
95
+ var _a, _b, _c;
96
+ const spanAttributes = {
97
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
98
+ 'activity.conversation_id': unknownValue((_c = (_b = record.activity) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.id),
99
+ 'dialog.id': unknownValue(record.dialogId),
100
+ 'dialog.name': unknownValue(record.name),
101
+ 'dialog.status': unknownValue(record.status),
102
+ };
103
+ span.setAttributes(spanAttributes);
104
+ const metricAttributes = {
105
+ operation: 'end',
106
+ 'result.status': unknownValue(record.status),
107
+ };
108
+ metrics_1.DialogsMetrics.contextCount.add(1, metricAttributes);
109
+ metrics_1.DialogsMetrics.contextDuration.record(duration, metricAttributes);
110
+ }
111
+ }),
112
+ contextReplace: agents_telemetry_1.trace.define({
113
+ name: agents_telemetry_1.SpanNames.DIALOGS_CONTEXT_REPLACE,
114
+ record: {
115
+ activity: defaultActivity,
116
+ dialogId: '',
117
+ name: 'unknown',
118
+ replacementDialogId: '',
119
+ replacementName: 'unknown',
120
+ status: 'unknown',
121
+ },
122
+ end({ span, record, duration }) {
123
+ var _a, _b, _c;
124
+ const spanAttributes = {
125
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
126
+ 'activity.conversation_id': unknownValue((_c = (_b = record.activity) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.id),
127
+ 'dialog.id': unknownValue(record.dialogId),
128
+ 'dialog.name': unknownValue(record.name),
129
+ 'dialog.replacement_id': unknownValue(record.replacementDialogId),
130
+ 'dialog.replacement_name': unknownValue(record.replacementName),
131
+ 'dialog.status': unknownValue(record.status),
132
+ };
133
+ span.setAttributes(spanAttributes);
134
+ const metricAttributes = {
135
+ operation: 'replace',
136
+ 'result.status': unknownValue(record.status),
137
+ };
138
+ metrics_1.DialogsMetrics.contextCount.add(1, metricAttributes);
139
+ metrics_1.DialogsMetrics.contextDuration.record(duration, metricAttributes);
140
+ }
141
+ }),
142
+ contextCancelAll: agents_telemetry_1.trace.define({
143
+ name: agents_telemetry_1.SpanNames.DIALOGS_CONTEXT_CANCEL_ALL,
144
+ record: {
145
+ activity: defaultActivity,
146
+ cancelParents: false,
147
+ dialogId: '',
148
+ eventName: '',
149
+ name: 'unknown',
150
+ status: 'unknown',
151
+ },
152
+ end({ span, record, duration }) {
153
+ var _a, _b, _c;
154
+ const spanAttributes = {
155
+ 'activity.type': unknownValue((_a = record.activity) === null || _a === void 0 ? void 0 : _a.type),
156
+ 'activity.conversation_id': unknownValue((_c = (_b = record.activity) === null || _b === void 0 ? void 0 : _b.conversation) === null || _c === void 0 ? void 0 : _c.id),
157
+ 'dialog.cancel_parents': record.cancelParents,
158
+ 'dialog.event_name': unknownValue(record.eventName),
159
+ 'dialog.id': unknownValue(record.dialogId),
160
+ 'dialog.name': unknownValue(record.name),
161
+ 'dialog.status': unknownValue(record.status),
162
+ };
163
+ span.setAttributes(spanAttributes);
164
+ const metricAttributes = {
165
+ operation: 'cancel_all',
166
+ 'result.status': unknownValue(record.status),
167
+ 'dialog.cancel_parents': record.cancelParents,
168
+ };
169
+ metrics_1.DialogsMetrics.contextCount.add(1, metricAttributes);
170
+ metrics_1.DialogsMetrics.contextDuration.record(duration, metricAttributes);
171
+ }
172
+ }),
173
+ };
174
+ //# sourceMappingURL=traces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../src/observability/traces.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,kEAA8D;AAC9D,uCAA0C;AAC1C,gEAAqD;AAErD,MAAM,YAAY,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,KAAK,IAAI,SAAS,CAAA;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A;YACpD,wBAAc,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;QACnE,CAAC;KACF,CAAC;CACH,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@microsoft/agents-hosting-dialogs",
4
- "version": "1.5.0-beta.6.ga236d9a19c",
4
+ "version": "1.5.1",
5
5
  "homepage": "https://github.com/microsoft/Agents-for-js",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,16 +16,17 @@
16
16
  "main": "dist/index.js",
17
17
  "types": "dist/src/index.d.ts",
18
18
  "dependencies": {
19
- "@microsoft/agents-hosting": "1.5.0-beta.6.ga236d9a19c",
20
- "@microsoft/agents-activity": "1.5.0-beta.6.ga236d9a19c",
21
- "@types/lodash": "^4.17.24",
22
- "dependency-graph": "^1.0.0",
23
- "@microsoft/recognizers-text-suite": "^1.3.1",
24
- "@microsoft/recognizers-text-number": "^1.3.1",
25
- "@microsoft/recognizers-text-date-time": "^1.3.2",
26
- "@microsoft/recognizers-text-choice": "^1.3.1",
27
- "globalize": "^1.7.1",
28
- "zod": "^3.25.75"
19
+ "@microsoft/agents-hosting": "1.5.1",
20
+ "@microsoft/agents-activity": "1.5.1",
21
+ "@types/lodash": "4.17.24",
22
+ "dependency-graph": "1.0.0",
23
+ "@microsoft/recognizers-text-suite": "1.3.1",
24
+ "@microsoft/recognizers-text-number": "1.3.1",
25
+ "@microsoft/recognizers-text-date-time": "1.3.2",
26
+ "@microsoft/recognizers-text-choice": "1.3.1",
27
+ "globalize": "1.7.1",
28
+ "zod": "3.25.75",
29
+ "@microsoft/agents-telemetry": "1.5.1"
29
30
  },
30
31
  "license": "MIT",
31
32
  "files": [
@@ -5,7 +5,7 @@
5
5
  import { findChoices, FindChoicesOptions, FoundChoice } from './findChoices'
6
6
  import { ModelResult } from './modelResult'
7
7
  import { Choice } from './choice'
8
- import { debug } from '@microsoft/agents-activity/logger'
8
+ import { debug } from '@microsoft/agents-telemetry'
9
9
  import * as Recognizers from '@microsoft/recognizers-text-number'
10
10
 
11
11
  const logger = debug('dialogs:recognizeChoices')
@@ -19,6 +19,7 @@ import { DialogTurnResult } from './dialogTurnResult'
19
19
  import { DialogTurnStatus } from './dialogTurnStatus'
20
20
  import { Choice } from './choices'
21
21
  import { Activity } from '@microsoft/agents-activity'
22
+ import { DialogsTraceDefinitions, trace } from './observability'
22
23
 
23
24
  /**
24
25
  * Wraps a promise in a try-catch that automatically enriches errors with extra dialog context.
@@ -248,24 +249,36 @@ export class DialogContext {
248
249
  *
249
250
  */
250
251
  async beginDialog (dialogId: string, options?: object): Promise<DialogTurnResult> {
251
- // Lookup dialog
252
- const dialog: Dialog<{}> = this.findDialog(dialogId)
253
- if (!dialog) {
254
- throw new DialogContextError(
255
- `DialogContext.beginDialog(): A dialog with an id of '${dialogId}' wasn't found.`,
256
- this
257
- )
258
- }
252
+ return trace(DialogsTraceDefinitions.contextBegin, async ({ record }) => {
253
+ record({
254
+ dialogId,
255
+ parentId: this.activeDialog?.id,
256
+ activity: this.context.activity,
257
+ })
259
258
 
260
- // Push new instance onto stack.
261
- const instance: DialogInstance<any> = {
262
- id: dialogId,
263
- state: {},
264
- }
265
- this.stack.push(instance)
259
+ // Lookup dialog
260
+ const dialog: Dialog<{}> = this.findDialog(dialogId)
261
+ if (!dialog) {
262
+ throw new DialogContextError(
263
+ `DialogContext.beginDialog(): A dialog with an id of '${dialogId}' wasn't found.`,
264
+ this
265
+ )
266
+ }
266
267
 
267
- // Call dialogs begin() method.
268
- return wrapErrors(this, dialog.beginDialog(this, options))
268
+ record({ name: dialog.constructor.name })
269
+
270
+ // Push new instance onto stack.
271
+ const instance: DialogInstance<any> = {
272
+ id: dialogId,
273
+ state: {},
274
+ }
275
+ this.stack.push(instance)
276
+
277
+ // Call dialogs begin() method.
278
+ const result = await wrapErrors(this, dialog.beginDialog(this, options))
279
+ record({ status: result?.status })
280
+ return result
281
+ })
269
282
  }
270
283
 
271
284
  /**
@@ -286,36 +299,52 @@ export class DialogContext {
286
299
  *
287
300
  */
288
301
  async cancelAllDialogs (cancelParents = false, eventName?: string, eventValue?: any): Promise<DialogTurnResult> {
289
- eventName = eventName || DialogEvents.cancelDialog
290
- if (this.stack.length > 0 || this.parent !== undefined) {
291
- // Cancel all local and parent dialogs while checking for interception
292
- let notify = false
293
-
294
- let dialogContext: DialogContext = this
295
- while (dialogContext !== undefined) {
296
- if (dialogContext.stack.length > 0) {
297
- // Check to see if the dialog wants to handle the event
298
- // - We skip notifying the first dialog which actually called cancelAllDialogs()
299
- if (notify) {
300
- const handled = await dialogContext.emitEvent(eventName, eventValue, false, false)
301
- if (handled) {
302
- break
302
+ return trace(DialogsTraceDefinitions.contextCancelAll, async ({ record }) => {
303
+ eventName = eventName || DialogEvents.cancelDialog
304
+ const activeDialogDefinition = this.activeDialog ? this.findDialog(this.activeDialog.id) : undefined
305
+
306
+ record({
307
+ activity: this.context.activity,
308
+ cancelParents,
309
+ dialogId: this.activeDialog?.id,
310
+ eventName,
311
+ name: activeDialogDefinition?.constructor.name,
312
+ })
313
+
314
+ let result: DialogTurnResult
315
+ if (this.stack.length > 0 || this.parent !== undefined) {
316
+ // Cancel all local and parent dialogs while checking for interception
317
+ let notify = false
318
+
319
+ let dialogContext: DialogContext = this
320
+ while (dialogContext !== undefined) {
321
+ if (dialogContext.stack.length > 0) {
322
+ // Check to see if the dialog wants to handle the event
323
+ // - We skip notifying the first dialog which actually called cancelAllDialogs()
324
+ if (notify) {
325
+ const handled = await dialogContext.emitEvent(eventName, eventValue, false, false)
326
+ if (handled) {
327
+ break
328
+ }
303
329
  }
330
+
331
+ // End the active dialog
332
+ await dialogContext.endActiveDialog(DialogReason.cancelCalled)
333
+ } else {
334
+ dialogContext = cancelParents ? dialogContext.parent : undefined
304
335
  }
305
336
 
306
- // End the active dialog
307
- await dialogContext.endActiveDialog(DialogReason.cancelCalled)
308
- } else {
309
- dialogContext = cancelParents ? dialogContext.parent : undefined
337
+ notify = true
310
338
  }
311
339
 
312
- notify = true
340
+ result = { status: DialogTurnStatus.cancelled }
341
+ } else {
342
+ result = { status: DialogTurnStatus.empty }
313
343
  }
314
344
 
315
- return { status: DialogTurnStatus.cancelled }
316
- } else {
317
- return { status: DialogTurnStatus.empty }
318
- }
345
+ record({ status: result.status })
346
+ return result
347
+ })
319
348
  }
320
349
 
321
350
  /**
@@ -430,33 +459,46 @@ export class DialogContext {
430
459
  *
431
460
  */
432
461
  async continueDialog (): Promise<DialogTurnResult> {
433
- // if we are continuing and haven't emitted the activityReceived event, emit it
434
- // NOTE: This is backward compatible way for activity received to be fired even if you have legacy dialog loop
435
- if (!this.context.turnState.has(ACTIVITY_RECEIVED_EMITTED)) {
436
- this.context.turnState.set(ACTIVITY_RECEIVED_EMITTED, true)
437
-
438
- // Dispatch "activityReceived" event
439
- // - This fired from teh leaf and will queue up any interruptions.
440
- await this.emitEvent(DialogEvents.activityReceived, this.context.activity, true, true)
441
- }
462
+ return trace(DialogsTraceDefinitions.contextContinue, async ({ record }) => {
463
+ record({
464
+ dialogId: this.activeDialog?.id,
465
+ activity: this.context.activity,
466
+ })
467
+
468
+ // if we are continuing and haven't emitted the activityReceived event, emit it
469
+ // NOTE: This is backward compatible way for activity received to be fired even if you have legacy dialog loop
470
+ if (!this.context.turnState.has(ACTIVITY_RECEIVED_EMITTED)) {
471
+ this.context.turnState.set(ACTIVITY_RECEIVED_EMITTED, true)
472
+
473
+ // Dispatch "activityReceived" event
474
+ // - This fired from the leaf and will queue up any interruptions.
475
+ await this.emitEvent(DialogEvents.activityReceived, this.context.activity, true, true)
476
+ }
442
477
 
443
- // Check for a dialog on the stack
444
- const instance: DialogInstance<any> = this.activeDialog
445
- if (instance) {
446
- // Lookup dialog
447
- const dialog: Dialog<{}> = this.findDialog(instance.id)
448
- if (!dialog) {
449
- throw new DialogContextError(
450
- `DialogContext.continueDialog(): Can't continue dialog. A dialog with an id of '${instance.id}' wasn't found.`,
451
- this
452
- )
478
+ // Check for a dialog on the stack
479
+ const instance: DialogInstance<any> = this.activeDialog
480
+ let result: DialogTurnResult
481
+ if (instance) {
482
+ // Lookup dialog
483
+ const dialog: Dialog<{}> = this.findDialog(instance.id)
484
+ if (!dialog) {
485
+ throw new DialogContextError(
486
+ `DialogContext.continueDialog(): Can't continue dialog. A dialog with an id of '${instance.id}' wasn't found.`,
487
+ this
488
+ )
489
+ }
490
+
491
+ record({ name: dialog.constructor.name })
492
+
493
+ // Continue execution of dialog
494
+ result = await wrapErrors(this, dialog.continueDialog(this))
495
+ } else {
496
+ result = { status: DialogTurnStatus.empty }
453
497
  }
454
498
 
455
- // Continue execution of dialog
456
- return wrapErrors(this, dialog.continueDialog(this))
457
- } else {
458
- return { status: DialogTurnStatus.empty }
459
- }
499
+ record({ status: result.status })
500
+ return result
501
+ })
460
502
  }
461
503
 
462
504
  /**
@@ -483,27 +525,41 @@ export class DialogContext {
483
525
  *
484
526
  */
485
527
  async endDialog (result?: any): Promise<DialogTurnResult> {
486
- // End the active dialog
487
- await this.endActiveDialog(DialogReason.endCalled, result)
528
+ return trace(DialogsTraceDefinitions.contextEnd, async ({ record }) => {
529
+ const activeDialogDefinition = this.activeDialog ? this.findDialog(this.activeDialog.id) : undefined
488
530
 
489
- // Resume parent dialog
490
- const instance: DialogInstance<any> = this.activeDialog
491
- if (instance) {
492
- // Lookup dialog
493
- const dialog: Dialog<{}> = this.findDialog(instance.id)
494
- if (!dialog) {
495
- throw new DialogContextError(
496
- `DialogContext.endDialog(): Can't resume previous dialog. A dialog with an id of '${instance.id}' wasn't found.`,
497
- this
498
- )
531
+ record({
532
+ activity: this.context.activity,
533
+ dialogId: this.activeDialog?.id,
534
+ name: activeDialogDefinition?.constructor.name,
535
+ })
536
+
537
+ // End the active dialog
538
+ await this.endActiveDialog(DialogReason.endCalled, result)
539
+
540
+ // Resume parent dialog
541
+ const instance: DialogInstance<any> = this.activeDialog
542
+ let turnResult: DialogTurnResult
543
+ if (instance) {
544
+ // Lookup dialog
545
+ const dialog: Dialog<{}> = this.findDialog(instance.id)
546
+ if (!dialog) {
547
+ throw new DialogContextError(
548
+ `DialogContext.endDialog(): Can't resume previous dialog. A dialog with an id of '${instance.id}' wasn't found.`,
549
+ this
550
+ )
551
+ }
552
+
553
+ // Return result to previous dialog
554
+ turnResult = await wrapErrors(this, dialog.resumeDialog(this, DialogReason.endCalled, result))
555
+ } else {
556
+ // Signal completion
557
+ turnResult = { status: DialogTurnStatus.complete, result }
499
558
  }
500
559
 
501
- // Return result to previous dialog
502
- return wrapErrors(this, dialog.resumeDialog(this, DialogReason.endCalled, result))
503
- } else {
504
- // Signal completion
505
- return { status: DialogTurnStatus.complete, result }
506
- }
560
+ record({ status: turnResult.status })
561
+ return turnResult
562
+ })
507
563
  }
508
564
 
509
565
  /**
@@ -524,11 +580,26 @@ export class DialogContext {
524
580
  *
525
581
  */
526
582
  async replaceDialog (dialogId: string, options?: object): Promise<DialogTurnResult> {
527
- // End the active dialog
528
- await this.endActiveDialog(DialogReason.replaceCalled)
529
-
530
- // Start replacement dialog
531
- return this.beginDialog(dialogId, options)
583
+ return trace(DialogsTraceDefinitions.contextReplace, async ({ record }) => {
584
+ const activeDialogDefinition = this.activeDialog ? this.findDialog(this.activeDialog.id) : undefined
585
+ const replacementDialog = this.findDialog(dialogId)
586
+
587
+ record({
588
+ activity: this.context.activity,
589
+ dialogId: this.activeDialog?.id,
590
+ name: activeDialogDefinition?.constructor.name,
591
+ replacementDialogId: dialogId,
592
+ replacementName: replacementDialog?.constructor.name,
593
+ })
594
+
595
+ // End the active dialog
596
+ await this.endActiveDialog(DialogReason.replaceCalled)
597
+
598
+ // Start replacement dialog
599
+ const result = await this.beginDialog(dialogId, options)
600
+ record({ status: result?.status })
601
+ return result
602
+ })
532
603
  }
533
604
 
534
605
  /**
@@ -16,6 +16,7 @@ import { DialogSet } from './dialogSet'
16
16
  import { DialogStateManager, DialogStateManagerConfiguration } from './memory'
17
17
  import { DialogTurnResult } from './dialogTurnResult'
18
18
  import { DialogTurnStatus } from './dialogTurnStatus'
19
+ import { DialogsTraceDefinitions, trace } from './observability'
19
20
 
20
21
  /**
21
22
  * Runs a dialog from a given context and accessor.
@@ -78,45 +79,53 @@ export async function internalRun (
78
79
  dialogContext: DialogContext,
79
80
  dialogStateManagerConfiguration?: DialogStateManagerConfiguration
80
81
  ): Promise<DialogTurnResult> {
81
- // map TurnState into root dialog context.services
82
- context.turnState.forEach((service, key) => {
83
- dialogContext.services.push(key, service)
84
- })
85
-
86
- const dialogStateManager = new DialogStateManager(dialogContext, dialogStateManagerConfiguration)
87
-
88
- await dialogStateManager.loadAllScopes()
89
- dialogContext.context.turnState.push('DialogStateManager', dialogStateManager)
90
- let dialogTurnResult: DialogTurnResult = null
91
-
92
- // Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn.
93
- // NOTE: We loop around this block because each pass through we either complete the turn and break out of the loop
94
- // or we have had an exception AND there was an OnError action which captured the error. We need to continue the
95
- // turn based on the actions the OnError handler introduced.
96
- let endOfTurn = false
97
- while (!endOfTurn) {
98
- try {
99
- dialogTurnResult = await innerRun(context, dialogId, dialogContext)
100
-
101
- // turn successfully completed, break the loop
102
- endOfTurn = true
103
- } catch (err) {
104
- // fire error event, bubbling from the leaf.
105
- const handled = await dialogContext.emitEvent(DialogEvents.error, err, true, true)
106
-
107
- if (!handled) {
108
- // error was NOT handled, throw the exception and end the turn.
109
- // (This will trigger the Adapter.OnError handler and end the entire dialog stack)
110
- throw err
82
+ return trace(DialogsTraceDefinitions.run, async ({ record }) => {
83
+ record({ activity: context.activity, dialogId })
84
+
85
+ // map TurnState into root dialog context.services
86
+ context.turnState.forEach((service, key) => {
87
+ dialogContext.services.push(key, service)
88
+ })
89
+
90
+ const dialogStateManager = new DialogStateManager(dialogContext, dialogStateManagerConfiguration)
91
+
92
+ await dialogStateManager.loadAllScopes()
93
+ dialogContext.context.turnState.push('DialogStateManager', dialogStateManager)
94
+ let dialogTurnResult: DialogTurnResult = null
95
+ let attemptCount = 0
96
+
97
+ // Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn.
98
+ // NOTE: We loop around this block because each pass through we either complete the turn and break out of the loop
99
+ // or we have had an exception AND there was an OnError action which captured the error. We need to continue the
100
+ // turn based on the actions the OnError handler introduced.
101
+ let endOfTurn = false
102
+ while (!endOfTurn) {
103
+ attemptCount += 1
104
+ record({ attemptCount })
105
+ try {
106
+ dialogTurnResult = await innerRun(context, dialogId, dialogContext)
107
+ record({ status: dialogTurnResult?.status })
108
+
109
+ // turn successfully completed, break the loop
110
+ endOfTurn = true
111
+ } catch (err) {
112
+ // fire error event, bubbling from the leaf.
113
+ const handled = await dialogContext.emitEvent(DialogEvents.error, err, true, true)
114
+
115
+ if (!handled) {
116
+ // error was NOT handled, throw the exception and end the turn.
117
+ // (This will trigger the Adapter.OnError handler and end the entire dialog stack)
118
+ throw err
119
+ }
111
120
  }
112
121
  }
113
- }
114
122
 
115
- // save all state scopes to their respective agentState locations.
116
- await dialogStateManager.saveAllChanges()
123
+ // save all state scopes to their respective agentState locations.
124
+ await dialogStateManager.saveAllChanges()
117
125
 
118
- // return the redundant result because the DialogManager contract expects it
119
- return dialogTurnResult
126
+ // return the redundant result because the DialogManager contract expects it
127
+ return dialogTurnResult
128
+ })
120
129
  }
121
130
 
122
131
  /**
@@ -0,0 +1,6 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ export * from './metrics'
5
+ export * from './traces'
6
+ export { trace } from '@microsoft/agents-telemetry'