forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TelemetryExtensions.cs
76 lines (64 loc) · 2.86 KB
/
TelemetryExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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;
}
}
}