forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b98584
commit 0c9dc50
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace AppInsightsBot | ||
{ | ||
public static class TelemetryExtensions | ||
{ | ||
public static TraceTelemetry CreateTraceTelemetry(this IDialogContext ctx, string message = null, IDictionary<string, string> properties = null) | ||
{ | ||
var t = new TraceTelemetry(message); | ||
t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData)); | ||
t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData)); | ||
t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData)); | ||
|
||
var m = ctx.MakeMessage(); | ||
t.Properties.Add("ConversationId", m.Conversation.Id); | ||
t.Properties.Add("UserId", m.Recipient.Id); | ||
|
||
if (properties != null) | ||
{ | ||
foreach (var p in properties) | ||
{ | ||
t.Properties.Add(p); | ||
} | ||
} | ||
|
||
return t; | ||
} | ||
|
||
public static EventTelemetry CreateEventTelemetry(this IDialogContext ctx, string message = null, IDictionary<string, string> properties = null) | ||
{ | ||
var t = new EventTelemetry(message); | ||
t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData)); | ||
t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData)); | ||
t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData)); | ||
|
||
var m = ctx.MakeMessage(); | ||
t.Properties.Add("ConversationId", m.Conversation.Id); | ||
t.Properties.Add("UserId", m.Recipient.Id); | ||
|
||
if (properties != null) | ||
{ | ||
foreach (var p in properties) | ||
{ | ||
t.Properties.Add(p); | ||
} | ||
} | ||
|
||
return t; | ||
} | ||
|
||
public static ExceptionTelemetry CreateExceptionTelemetry(this IDialogContext ctx, System.Exception ex, IDictionary<string, string> properties = null) | ||
{ | ||
var t = new ExceptionTelemetry(ex); | ||
t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData)); | ||
t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData)); | ||
t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData)); | ||
|
||
var m = ctx.MakeMessage(); | ||
t.Properties.Add("ConversationId", m.Conversation.Id); | ||
t.Properties.Add("UserId", m.Recipient.Id); | ||
|
||
if (properties != null) | ||
{ | ||
foreach (var p in properties) | ||
{ | ||
t.Properties.Add(p); | ||
} | ||
} | ||
|
||
return t; | ||
} | ||
} | ||
} |