Skip to content

Commit

Permalink
port: [#4006] Add TelemetryLoggerConstants for adaptive. (#6029) (#4033)
Browse files Browse the repository at this point in the history
* Port telemetry constants from DotNet

* Add telemetry constants into the unit tests

* Fix typo

Co-authored-by: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com>

* Update project signature

* Add missing semicolons

Co-authored-by: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com>
Co-authored-by: CeciliaAvila <cecilia.avila@southworks.com>
Co-authored-by: Eric Dahlvang <erdahlva@microsoft.com>
  • Loading branch information
4 people authored Mar 16, 2022
1 parent 5c4a3aa commit cde0370
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,26 @@ export interface SwitchConditionConfiguration extends DialogConfiguration {
disabled?: BoolProperty;
}

// @public
export class TelemetryLoggerConstants {
static readonly CompleteEvent: string;
static readonly CrossTrainedRecognizerSetResultEvent: string;
static readonly DialogActionEvent: string;
static readonly DialogCancelEvent: string;
static readonly DialogStartEvent: string;
static readonly GeneratorResultEvent: string;
static readonly InputDialogResultEvent: string;
static readonly LogActionResultEvent: string;
static readonly MultiLanguageRecognizerResultEvent: string;
static readonly OAuthInputResultEvent: string;
static readonly RecognizerSetResultEvent: string;
static readonly RegexRecognizerResultEvent: string;
static readonly SendActivityResultEvent: string;
static readonly TriggerEvent: string;
static readonly UpdateActivityResultEvent: string;
static readonly ValueRecognizerResultEvent: string;
}

// @public
export class TelemetryTrackEventAction<O extends object = {}> extends Dialog implements TelemetryTrackEventActionConfiguration {
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from 'botbuilder-dialogs';
import { ActionContext } from '../actionContext';
import { DialogListConverter } from '../converters';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

const OFFSET_KEY = 'this.offset';

Expand Down Expand Up @@ -276,7 +277,7 @@ export class ActionScope<O extends object = {}>
Kind: `Microsoft.${actionName}`,
ActionId: `Microsoft.${action.id}`,
};
this.telemetryClient.trackEvent({ name: 'AdaptiveDialogAction', properties: properties });
this.telemetryClient.trackEvent({ name: TelemetryLoggerConstants.DialogActionEvent, properties: properties });

return await dc.beginDialog(action.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ActivityTemplateConverter } from '../converters';
import { AdaptiveEvents } from '../adaptiveEvents';
import { BoolProperty, StringProperty, TemplateInterfaceProperty } from '../properties';
import { skillClientKey, skillConversationIdFactoryKey } from '../skillExtensions';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
BoolExpression,
Expand Down Expand Up @@ -209,7 +210,7 @@ export class BeginSkill extends SkillDialog implements BeginSkillConfiguration {
const activity = await this.activity.bind(dc, dcState);

this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: this.activity,
result: activity || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Activity, ActivityTypes } from 'botbuilder';
import { BoolProperty, StringProperty } from '../properties';
import { TextTemplate } from '../templates';
import { TextTemplateConverter } from '../converters/textTemplateConverter';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
BoolExpression,
Expand Down Expand Up @@ -118,10 +119,11 @@ export class LogAction<O extends object = {}> extends Dialog<O> implements LogAc

const msg = await this.text.bind(dc, dc.state);
this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: this.text,
result: msg || '',
context: TelemetryLoggerConstants.LogActionResultEvent,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ActivityTemplate, StaticActivityTemplate } from '../templates';
import { ActivityTemplateConverter } from '../converters';
import { BoolExpression, BoolExpressionConverter } from 'adaptive-expressions';
import { BoolProperty, TemplateInterfaceProperty } from '../properties';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
Converter,
Expand Down Expand Up @@ -107,10 +108,11 @@ export class SendActivity<O extends object = {}> extends Dialog<O> implements Se
const activityResult = await this.activity.bind(dc, data);

this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: this.activity,
result: activityResult || '',
context: TelemetryLoggerConstants.SendActivityResultEvent,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Activity, StringUtils } from 'botbuilder';
import { ActivityTemplate, StaticActivityTemplate } from '../templates';
import { ActivityTemplateConverter } from '../converters';
import { BoolProperty, StringProperty, TemplateInterfaceProperty } from '../properties';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
StringExpression,
Expand Down Expand Up @@ -124,10 +125,11 @@ export class UpdateActivity<O extends object = {}> extends Dialog<O> implements
const activityResult = await this.activity.bind(dc, data);

this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: this.activity,
result: activityResult || '',
context: TelemetryLoggerConstants.UpdateActivityResultEvent,
},
});

Expand Down
15 changes: 9 additions & 6 deletions libraries/botbuilder-dialogs-adaptive/src/adaptiveDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { ValueRecognizer } from './recognizers/valueRecognizer';
import { SchemaHelper } from './schemaHelper';
import { FirstSelector, MostSpecificSelector } from './selectors';
import { TriggerSelector } from './triggerSelector';
import { TelemetryLoggerConstants } from './telemetryLoggerConstants';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isDialogDependencies(val: any): val is DialogDependencies {
Expand Down Expand Up @@ -308,9 +309,10 @@ export class AdaptiveDialog<O extends object = {}> extends DialogContainer<O> im
const properties: { [key: string]: string } = {
DialogId: this.id,
Kind: 'Microsoft.AdaptiveDialog',
context: TelemetryLoggerConstants.DialogStartEvent,
};
this.telemetryClient.trackEvent({
name: 'AdaptiveDialogStart',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: properties,
});
telemetryTrackDialogView(this.telemetryClient, this.id);
Expand Down Expand Up @@ -354,13 +356,13 @@ export class AdaptiveDialog<O extends object = {}> extends DialogContainer<O> im
};
if (reason === DialogReason.cancelCalled) {
this.telemetryClient.trackEvent({
name: 'AdaptiveDialogCancel',
properties: properties,
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: { ...properties, context: TelemetryLoggerConstants.DialogCancelEvent },
});
} else if (reason === DialogReason.endCalled) {
this.telemetryClient.trackEvent({
name: 'AdaptiveDialogComplete',
properties: properties,
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: { ...properties, context: TelemetryLoggerConstants.CompleteEvent },
});
}
await super.endDialog(turnContext, instance, reason);
Expand Down Expand Up @@ -674,9 +676,10 @@ export class AdaptiveDialog<O extends object = {}> extends DialogContainer<O> im
Expression: evt.getExpression().toString(),
Kind: `Microsoft.${evt.constructor.name}`,
ConditionId: evt.id,
context: TelemetryLoggerConstants.TriggerEvent,
};
this.telemetryClient.trackEvent({
name: 'AdaptiveDialogTrigger',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: properties,
});

Expand Down
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs-adaptive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export * from './schemaHelper';
export * from './selectors';
export * from './skillExtensions';
export * from './telemetryExtensions';
export * from './telemetryLoggerConstants';
export * from './templates';
export * from './triggerSelector';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ActivityTypes, Activity, InputHints, MessageFactory } from 'botbuilder'
import { AdaptiveEvents } from '../adaptiveEvents';
import { AttachmentInput } from './attachmentInput';
import { BoolProperty, IntProperty, StringProperty, TemplateInterfaceProperty, UnknownProperty } from '../properties';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
BoolExpression,
Expand Down Expand Up @@ -262,10 +263,11 @@ export abstract class InputDialog extends Dialog implements InputDialogConfigura
if (this.defaultValueResponse) {
const response = await this.defaultValueResponse.bind(dc, dc.state);
this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: this.defaultValueResponse,
result: response || '',
context: TelemetryLoggerConstants.InputDialogResultEvent,
},
});

Expand Down Expand Up @@ -381,10 +383,11 @@ export abstract class InputDialog extends Dialog implements InputDialogConfigura
}

this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties: {
template: template,
result: msg,
context: TelemetryLoggerConstants.InputDialogResultEvent,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { InputDialog, InputDialogConfiguration, InputState } from './inputDialog';
import { IntProperty, StringProperty } from '../properties';
import { TextTemplate } from '../templates';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

import {
ConversationState,
Expand Down Expand Up @@ -279,9 +280,10 @@ export class OAuthInput extends InputDialog implements OAuthInputConfiguration {
const properties = {
template: JSON.stringify(this.defaultValueResponse),
result: response ? JSON.stringify(response) : '',
context: TelemetryLoggerConstants.OAuthInputResultEvent,
};
this.telemetryClient.trackEvent({
name: 'GeneratorResult',
name: TelemetryLoggerConstants.GeneratorResultEvent,
properties,
});
await dc.context.sendActivity(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Activity, RecognizerResult, getTopScoringIntent } from 'botbuilder';
import { Converter, ConverterFactory, DialogContext, Recognizer, RecognizerConfiguration } from 'botbuilder-dialogs';
import { RecognizerListConverter } from '../converters';
import { AdaptiveRecognizer } from './adaptiveRecognizer';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

/**
* Standard cross trained intent name prefix.
Expand Down Expand Up @@ -89,7 +90,7 @@ export class CrossTrainedRecognizerSet extends AdaptiveRecognizer implements Cro
const result = this.processResults(results);
this.trackRecognizerResult(
dialogContext,
'CrossTrainedRecognizerSetResult',
TelemetryLoggerConstants.CrossTrainedRecognizerSetResultEvent,
this.fillRecognizerResultTelemetryProperties(result, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LanguagePolicy, LanguagePolicyConverter } from '../languagePolicy';
import { MultiLanguageRecognizerConverter } from '../converters';
import { languagePolicyKey } from '../languageGeneratorExtensions';
import { AdaptiveRecognizer } from './adaptiveRecognizer';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

export interface MultiLanguageRecognizerConfiguration extends RecognizerConfiguration {
languagePolicy?: Record<string, string[]> | LanguagePolicy;
Expand Down Expand Up @@ -94,7 +95,7 @@ export class MultiLanguageRecognizer extends AdaptiveRecognizer implements Multi
);
this.trackRecognizerResult(
dialogContext,
'MultiLanguageRecognizerResult',
TelemetryLoggerConstants.MultiLanguageRecognizerResultEvent,
this.fillRecognizerResultTelemetryProperties(result, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand All @@ -109,7 +110,7 @@ export class MultiLanguageRecognizer extends AdaptiveRecognizer implements Multi
};
this.trackRecognizerResult(
dialogContext,
'MultiLanguagesRecognizerResult',
TelemetryLoggerConstants.MultiLanguageRecognizerResultEvent,
this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Activity, RecognizerResult, getTopScoringIntent } from 'botbuilder';
import { Converter, ConverterFactory, DialogContext, Recognizer, RecognizerConfiguration } from 'botbuilder-dialogs';
import { RecognizerListConverter } from '../converters';
import { AdaptiveRecognizer } from './adaptiveRecognizer';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

export interface RecognizerSetConfiguration extends RecognizerConfiguration {
recognizers?: string[] | Recognizer[];
Expand Down Expand Up @@ -63,7 +64,7 @@ export class RecognizerSet extends AdaptiveRecognizer implements RecognizerSetCo

this.trackRecognizerResult(
dialogContext,
'RecognizerSetResult',
TelemetryLoggerConstants.RecognizerSetResultEvent,
this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IntentPattern } from './intentPattern';
import { EntityRecognizer, TextEntity, EntityRecognizerSet } from './entityRecognizers';
import { RecognizerSetConfiguration } from './recognizerSet';
import { AdaptiveRecognizer } from './adaptiveRecognizer';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

type IntentPatternInput = {
intent: string;
Expand Down Expand Up @@ -181,7 +182,7 @@ export class RegexRecognizer extends AdaptiveRecognizer implements RegexRecogniz
);
this.trackRecognizerResult(
dialogContext,
'RegexRecognizerResult',
TelemetryLoggerConstants.RegexRecognizerResultEvent,
this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { Activity, ActivityTypes, RecognizerResult } from 'botbuilder';
import { DialogContext } from 'botbuilder-dialogs';
import { AdaptiveRecognizer } from './adaptiveRecognizer';
import { TelemetryLoggerConstants } from '../telemetryLoggerConstants';

/**
* ValueRecognizer - Recognizer for mapping message activity. Value payload into intent/entities.
Expand Down Expand Up @@ -57,7 +58,7 @@ export class ValueRecognizer extends AdaptiveRecognizer {
}
this.trackRecognizerResult(
dialogContext,
'ValueRecognizerResult',
TelemetryLoggerConstants.ValueRecognizerResultEvent,
this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dialogContext),
telemetryMetrics
);
Expand Down
Loading

0 comments on commit cde0370

Please sign in to comment.