Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
daveta committed Dec 4, 2018
1 parent 51d4df6 commit 8861b0a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
68 changes: 66 additions & 2 deletions ApplicationInsights_DataGenTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ static void Main(string[] args)
{
TelemetryConfiguration configuration = TelemetryConfiguration.CreateFromConfiguration(File.ReadAllText("ApplicationInsights.config"));
var telemetryClient = new TelemetryClient(configuration);

//

// run app...
SimulateUsage(telemetryClient, 500);

Expand Down Expand Up @@ -43,21 +46,34 @@ static void SimulateUsage(TelemetryClient telemetryClient, int users)

};



for (int i=0; i<users; i++)
{
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();

telemetryClient.Context.User.Id = Guid.NewGuid().ToString();




var traceString = $"UserId:{telemetryClient.Context.Session.Id}:SessionId:{telemetryClient.Context.User.Id}";
foreach (var dialog in dialogs)
{

var properties = CreateProperties();

telemetryClient.Context.Operation.Id = Guid.NewGuid().ToString();
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();

var dialogInstanceId = Guid.NewGuid().ToString();

properties.Add("DialogId", dialog.Name);
properties.Add("InstanceId", dialogInstanceId);
traceString += $":DialogId:{properties["DialogId"]}:";


LogLuisIntent(telemetryClient, properties);

for (int stepIndex=0; stepIndex < dialog.Steps.Length; stepIndex++)
{
var step = dialog.Steps[stepIndex];
Expand Down Expand Up @@ -125,6 +141,41 @@ static Dictionary<string, string> CreateProperties()
{ "activityType", activityType },
};
}

static void LogLuisIntent(TelemetryClient telemetryClient, Dictionary<string, string> properties)
{
var props = new Dictionary<string, string>(properties);
LUISIntentStats[] intents =
{
new LUISIntentStats("FirstIntent", 5),
new LUISIntentStats("SecondIntent", 5),
new LUISIntentStats("ThirdIntent", 5)
};

bool found = false;
foreach (var intent in intents)
{
if (intent.CurCount < intent.MaxCount)
{
props.Add("Question", $"{intent.Name} question");
props.Add("Intent", intent.Name);
props.Add("IntentScore", ".45");
telemetryClient.TrackEvent($"LuisIntent.{intent.Name}", props);
found = true;
break;
}
}

// No slots open, take first one.
if (!found)
{
var intent2 = intents[0];
props.Add("Question", $"{intent2.Name} question");
props.Add("Intent", intent2.Name);
props.Add("IntentScore", ".48");
telemetryClient.TrackEvent($"LuisIntent.{intent2.Name}", props);
}
}
}
public class StepStats
{
Expand All @@ -150,4 +201,17 @@ public DialogStats(string name, StepStats[] steps)
public string Name { get; set; }
public StepStats[] Steps { get; set; }
}
}

public class LUISIntentStats
{
public LUISIntentStats(string name, int maxCount)
{
Name = name;
MaxCount = maxCount;
}

public string Name { get; set; }
public int MaxCount { get; set; }
public int CurCount { get; set; } = 0;
}
}
29 changes: 28 additions & 1 deletion appinsights_blog_42/bot_application_insights.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,34 @@ Property |Type | Details

## WaterfallDialog events

In addition to generating your own events, the` WaterfallDialog` object within the SDK now generates events. The following section describes the events generated from within the Bot Framework. By setting the `TelemetryClient` property on the `WaterfallDialog` these events will be stored.
In addition to generating your own events, the `WaterfallDialog` object within the SDK now generates events. The following section describes the events generated from within the Bot Framework. By setting the `TelemetryClient` property on the `WaterfallDialog` these events will be stored.

Here's an example of modifying a sample (BasicBot) which employs the `WaterfallDialog`, to log telemetry events. BasicBot employs a common pattern used where a `WaterfallDialog` is placed within a `ComponentDialog` (`GreetingDialog`).
```csharp
// IBotTelemetryClient is direct injected into our Bot
public BasicBot(BotServices services, UserState userState, ConversationState conversationState, IBotTelemetryClient telemetryClient)
...

// The IBotTelemetryClient passed to the GreetingDialog
...
Dialogs = new DialogSet(_dialogStateAccessor);
Dialogs.Add(new GreetingDialog(_greetingStateAccessor, telemetryClient));
...

// The IBotTelemetryClient to the WaterfallDialog
...
AddDialog(new WaterfallDialog(ProfileDialog, waterfallSteps) { TelemetryClient = telemetryClient });
...

```

> ASP.Net Core Example



Once the `WaterfallDialog` has a configured `IBotTelemetryClient`, it will begin logging events.



### CustomEvent: "WaterfallStart"

Expand Down

0 comments on commit 8861b0a

Please sign in to comment.