Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

TelemetryExtensions.cs 2.9 KB

You have to be logged in to leave a comment. Sign In
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
  1. namespace AppInsightsBot
  2. {
  3. using System.Collections.Generic;
  4. using Microsoft.ApplicationInsights.DataContracts;
  5. using Microsoft.Bot.Builder.Dialogs;
  6. using Newtonsoft.Json;
  7. public static class TelemetryExtensions
  8. {
  9. public static TraceTelemetry CreateTraceTelemetry(this IDialogContext ctx, string message = null, IDictionary<string, string> properties = null)
  10. {
  11. var t = new TraceTelemetry(message);
  12. t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData));
  13. t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData));
  14. t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData));
  15. var m = ctx.MakeMessage();
  16. t.Properties.Add("ConversationId", m.Conversation.Id);
  17. t.Properties.Add("UserId", m.Recipient.Id);
  18. if (properties != null)
  19. {
  20. foreach (var p in properties)
  21. {
  22. t.Properties.Add(p);
  23. }
  24. }
  25. return t;
  26. }
  27. public static EventTelemetry CreateEventTelemetry(this IDialogContext ctx, string message = null, IDictionary<string, string> properties = null)
  28. {
  29. var t = new EventTelemetry(message);
  30. t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData));
  31. t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData));
  32. t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData));
  33. var m = ctx.MakeMessage();
  34. t.Properties.Add("ConversationId", m.Conversation.Id);
  35. t.Properties.Add("UserId", m.Recipient.Id);
  36. if (properties != null)
  37. {
  38. foreach (var p in properties)
  39. {
  40. t.Properties.Add(p);
  41. }
  42. }
  43. return t;
  44. }
  45. public static ExceptionTelemetry CreateExceptionTelemetry(this IDialogContext ctx, System.Exception ex, IDictionary<string, string> properties = null)
  46. {
  47. var t = new ExceptionTelemetry(ex);
  48. t.Properties.Add("ConversationData", JsonConvert.SerializeObject(ctx.ConversationData));
  49. t.Properties.Add("PrivateConversationData", JsonConvert.SerializeObject(ctx.PrivateConversationData));
  50. t.Properties.Add("UserData", JsonConvert.SerializeObject(ctx.UserData));
  51. var m = ctx.MakeMessage();
  52. t.Properties.Add("ConversationId", m.Conversation.Id);
  53. t.Properties.Add("UserId", m.Recipient.Id);
  54. if (properties != null)
  55. {
  56. foreach (var p in properties)
  57. {
  58. t.Properties.Add(p);
  59. }
  60. }
  61. return t;
  62. }
  63. }
  64. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...