-
Notifications
You must be signed in to change notification settings - Fork 492
Fixes for QnA / Recognizer Adaptive telemetry #3715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e808a72
81ad47b
4aee5e9
0d1dc37
0591aec
1e99d5e
d6e022f
2d1d12a
0c85976
1a3fd47
fb89716
e9c0e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Bot.Builder.Dialogs.Adaptive | ||
| { | ||
| public static class TelemetryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Register IBotTelemetryClient as default langugage generator. | ||
| /// </summary> | ||
| /// <param name="dialogManager">botAdapter to add services to.</param> | ||
| /// <param name="telemetryClient">IBotTelemetryClient to use.</param> | ||
| /// <returns>botAdapter.</returns> | ||
| public static DialogManager UseTelemetry(this DialogManager dialogManager, IBotTelemetryClient telemetryClient) | ||
| { | ||
| dialogManager.TurnState.Set<IBotTelemetryClient>(telemetryClient); | ||
| dialogManager.Dialogs.TelemetryClient = telemetryClient; | ||
| return dialogManager; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,10 @@ | ||||||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||||||
| using System.Collections.Generic; | ||||||||||||||||||||||||||||||||||||
| using System.Linq; | ||||||||||||||||||||||||||||||||||||
| using System.Text; | ||||||||||||||||||||||||||||||||||||
| using System.Threading; | ||||||||||||||||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||||||||||||||||
| using Microsoft.Bot.Schema; | ||||||||||||||||||||||||||||||||||||
| using Newtonsoft.Json; | ||||||||||||||||||||||||||||||||||||
| using Newtonsoft.Json.Linq; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| namespace Microsoft.Bot.Builder.Dialogs | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -70,22 +68,53 @@ public virtual async Task<T> RecognizeAsync<T>(DialogContext dialogContext, Acti | |||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| protected virtual Dictionary<string, string> FillRecognizerResultTelemetryProperties(RecognizerResult recognizerResult, Dictionary<string, string> telemetryProperties, ITurnContext turnContext = null) | ||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||
| /// Uses the RecognizerResult to create a list of propeties to be included when tracking the result in telemetry. | ||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||
| /// <param name="recognizerResult">Recognizer Result.</param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="telemetryProperties">A list of properties to append or override the properties created using the RecognizerResult.</param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="dialogContext">Dialog Context.</param> | ||||||||||||||||||||||||||||||||||||
| /// <returns>A dictionary that can be included when calling the TrackEvent method on the TelemetryClient.</returns> | ||||||||||||||||||||||||||||||||||||
| protected virtual Dictionary<string, string> FillRecognizerResultTelemetryProperties(RecognizerResult recognizerResult, Dictionary<string, string> telemetryProperties, DialogContext dialogContext = null) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this shipped in 4.8? I would think this is a breaking change to change this signature.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was. I had misunderstood the way the expression value worked, which means that the current implementation doesn't get the right application ID, so I think I do need the dialog context unless there is another way to get the value -> botbuilder-dotnet/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/LUIS/LuisAdaptiveRecognizer.cs Lines 140 to 156 in 0c85976
If I do need DialogContext, given that adaptive isn't GA yet and we have not documented any of the telemetry bits yet, I think this is an acceptable change for us to make here. Thoughts? |
||||||||||||||||||||||||||||||||||||
| if (telemetryProperties == null) | ||||||||||||||||||||||||||||||||||||
| var properties = new Dictionary<string, string>() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| { "Text", recognizerResult.Text }, | ||||||||||||||||||||||||||||||||||||
| { "AlteredText", recognizerResult.AlteredText }, | ||||||||||||||||||||||||||||||||||||
| { "TopIntent", recognizerResult.Intents.Any() ? recognizerResult.Intents.First().Key : null }, | ||||||||||||||||||||||||||||||||||||
| { "TopIntentScore", recognizerResult.Intents.Any() ? recognizerResult.Intents.First().Value?.ToString() : null }, | ||||||||||||||||||||||||||||||||||||
| { "Intents", recognizerResult.Intents.Any() ? JsonConvert.SerializeObject(recognizerResult.Intents) : null }, | ||||||||||||||||||||||||||||||||||||
| { "Entities", recognizerResult.Entities != null ? recognizerResult.Entities.ToString() : null }, | ||||||||||||||||||||||||||||||||||||
| { "AdditionalProperties", recognizerResult.Properties.Any() ? JsonConvert.SerializeObject(recognizerResult.Properties) : null }, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Additional Properties can override "stock" properties. | ||||||||||||||||||||||||||||||||||||
| if (telemetryProperties != null) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| telemetryProperties = new Dictionary<string, string>(); | ||||||||||||||||||||||||||||||||||||
| return telemetryProperties.Concat(properties) | ||||||||||||||||||||||||||||||||||||
| .GroupBy(kv => kv.Key) | ||||||||||||||||||||||||||||||||||||
| .ToDictionary(g => g.Key, g => g.First().Value); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("Text", recognizerResult.Text); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("AlteredText", recognizerResult.AlteredText); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("TopIntent", recognizerResult.Intents.Any() ? recognizerResult.Intents.First().Key : null); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("TopIntentScore", recognizerResult.Intents.Any() ? recognizerResult.Intents.First().Value?.ToString() : null); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("Intents", recognizerResult.Intents.Any() ? JsonConvert.SerializeObject(recognizerResult.Intents) : null); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("Entities", recognizerResult.Entities != null ? recognizerResult.Entities.ToString() : null); | ||||||||||||||||||||||||||||||||||||
| telemetryProperties.Add("AdditionalProperties", recognizerResult.Properties.Any() ? JsonConvert.SerializeObject(recognizerResult.Properties) : null); | ||||||||||||||||||||||||||||||||||||
| return properties; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||
| /// Tracks an event with the event name provided using the TelemetryClient attaching the properties / metrics. | ||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||
| /// <param name="dialogContext">Dialog Context.</param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="eventName">The name of the event to track.</param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="telemetryProperties">The properties to be included as part of the event tracking.</param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="telemetryMetrics">The metrics to be included as part of the event tracking.</param> | ||||||||||||||||||||||||||||||||||||
| protected void TrackRecognizerResult(DialogContext dialogContext, string eventName, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
garypretty marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| if (this.TelemetryClient is NullBotTelemetryClient) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var turnStateTelemetryClient = dialogContext.Context.TurnState.Get<IBotTelemetryClient>(); | ||||||||||||||||||||||||||||||||||||
| this.TelemetryClient = turnStateTelemetryClient ?? this.TelemetryClient; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return telemetryProperties; | ||||||||||||||||||||||||||||||||||||
| this.TelemetryClient.TrackEvent(eventName, telemetryProperties, telemetryMetrics); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the new property, we need an update to the component schema file as well as re-gen the sdk.schema.