Revert previous commits to rollback to commit where interface was extended

This commit is contained in:
Gary Pretty 2020-03-04 10:59:02 +00:00
Родитель 7197d0a7ea
Коммит bee8125481
15 изменённых файлов: 68 добавлений и 450 удалений

Просмотреть файл

@ -1,205 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
namespace Microsoft.Bot.Builder.ApplicationInsights
{
/// <summary>
/// A logging client for bot telemetry.
/// </summary>
public class AppInsightsTelemetryClient : LogTelemetryClientBase
{
private readonly TelemetryClient _telemetryClient;
/// <summary>
/// Initializes a new instance of the <see cref="AppInsightsTelemetryClient"/> class.
/// </summary>
/// <param name="telemetryClient">The telemetry client to forward bot events to.</param>
public AppInsightsTelemetryClient(TelemetryClient telemetryClient)
{
_telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
}
/// <summary>
/// Send information about availability of an application.
/// </summary>
/// <param name="name">Availability test name.</param>
/// <param name="timeStamp">The time when the availability was captured.</param>
/// <param name="duration">The time taken for the availability test to run.</param>
/// <param name="runLocation">Name of the location the availability test was run from.</param>
/// <param name="success">True if the availability test ran successfully.</param>
/// <param name="message">Error message on availability test run failure.</param>
/// <param name="properties">Named string values you can use to classify and search for this availability telemetry.</param>
/// <param name="metrics">Additional values associated with this availability telemetry.</param>
public override void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new AvailabilityTelemetry(name, timeStamp, duration, runLocation, success, message);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackAvailability(telemetry);
}
/// <summary>
/// Send information about an external dependency (outgoing call) in the application.
/// </summary>
/// <param name="dependencyTypeName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are SQL, Azure table, and HTTP.</param>
/// <param name="target">External dependency target.</param>
/// <param name="dependencyName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are stored procedure name and URL path template.</param>
/// <param name="data">Command initiated by this dependency call. Examples are SQL statement and HTTP
/// URL's with all query parameters.</param>
/// <param name="startTime">The time when the dependency was called.</param>
/// <param name="duration">The time taken by the external dependency to handle the call.</param>
/// <param name="resultCode">Result code of dependency call execution.</param>
/// <param name="success">True if the dependency call was handled successfully.</param>
public override void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success)
{
var telemetry = new DependencyTelemetry
{
Type = dependencyTypeName,
Target = target,
Name = dependencyName,
Data = data,
Timestamp = startTime,
Duration = duration,
ResultCode = resultCode,
Success = success,
};
_telemetryClient.TrackDependency(telemetry);
}
/// <summary>
/// Logs custom events with extensible named fields.
/// </summary>
/// <param name="eventName">A name for the event.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
public override void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new EventTelemetry(eventName);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackEvent(telemetry);
}
/// <summary>
/// Logs a system exception.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="properties">Named string values you can use to classify and search for this exception.</param>
/// <param name="metrics">Additional values associated with this exception.</param>
public override void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new ExceptionTelemetry(exception);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackException(telemetry);
}
/// <summary>
/// Send a trace message.
/// </summary>
/// <param name="message">Message to display.</param>
/// <param name="severityLevel">Trace severity level <see cref="Severity"/>.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
public override void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties)
{
var telemetry = new TraceTelemetry(message)
{
SeverityLevel = (SeverityLevel)severityLevel,
};
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackTrace(telemetry);
}
/// <summary>
/// Logs a an Application Insights page view.
/// </summary>
/// <param name="name">The name of the dialog view to log.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
public override void TrackDialogView(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new PageViewTelemetry(name);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackPageView(telemetry);
}
/// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary>
public override void Flush() => _telemetryClient.Flush();
}
}

Просмотреть файл

@ -168,6 +168,35 @@ namespace Microsoft.Bot.Builder.ApplicationInsights
_telemetryClient.TrackTrace(telemetry); _telemetryClient.TrackTrace(telemetry);
} }
/// <summary>
/// Logs a dialog entry / as an Application Insights page view.
/// </summary>
/// <param name="dialogName">The name of the dialog to log the entry / start for.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
public virtual void TrackDialogView(string dialogName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
var telemetry = new PageViewTelemetry(dialogName);
if (properties != null)
{
foreach (var pair in properties)
{
telemetry.Properties.Add(pair.Key, pair.Value);
}
}
if (metrics != null)
{
foreach (var pair in metrics)
{
telemetry.Metrics.Add(pair.Key, pair.Value);
}
}
_telemetryClient.TrackPageView(telemetry);
}
/// <summary> /// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated. /// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary> /// </summary>

Просмотреть файл

@ -52,27 +52,6 @@ namespace Microsoft.Bot.Builder.Dialogs
} }
} }
/// <summary>
/// Gets or sets the <see cref="LogTelemetryClient"/> to use for logging.
/// When setting this property, all of the contained dialogs' <see cref="Dialog.TelemetryClient"/>
/// properties are also set.
/// </summary>
/// <value>The <see cref="LogTelemetryClient"/> to use when logging.</value>
/// <seealso cref="DialogSet.LogTelemetryClient"/>
public override LogTelemetryClientBase LogTelemetryClient
{
get
{
return base.LogTelemetryClient;
}
set
{
base.LogTelemetryClient = value ?? new NullLogTelemetryClient();
Dialogs.LogTelemetryClient = base.LogTelemetryClient;
}
}
/// <summary> /// <summary>
/// Called when the dialog is started and pushed onto the parent's dialog stack. /// Called when the dialog is started and pushed onto the parent's dialog stack.
/// </summary> /// </summary>
@ -109,7 +88,7 @@ namespace Microsoft.Bot.Builder.Dialogs
return await EndComponentAsync(outerDc, turnResult.Result, cancellationToken).ConfigureAwait(false); return await EndComponentAsync(outerDc, turnResult.Result, cancellationToken).ConfigureAwait(false);
} }
LogTelemetryClient.TrackDialogView(Id); TelemetryClient.TrackDialogView(Id);
// Just signal waiting // Just signal waiting
return Dialog.EndOfTurn; return Dialog.EndOfTurn;

Просмотреть файл

@ -24,7 +24,6 @@ namespace Microsoft.Bot.Builder.Dialogs
public static readonly DialogTurnResult EndOfTurn = new DialogTurnResult(DialogTurnStatus.Waiting); public static readonly DialogTurnResult EndOfTurn = new DialogTurnResult(DialogTurnStatus.Waiting);
private IBotTelemetryClient _telemetryClient; private IBotTelemetryClient _telemetryClient;
private LogTelemetryClientBase _logTelemetryClient;
[JsonProperty("id")] [JsonProperty("id")]
private string id; private string id;
@ -38,7 +37,6 @@ namespace Microsoft.Bot.Builder.Dialogs
{ {
Id = dialogId; Id = dialogId;
_telemetryClient = NullBotTelemetryClient.Instance; _telemetryClient = NullBotTelemetryClient.Instance;
_logTelemetryClient = new NullLogTelemetryClient();
} }
/// <summary> /// <summary>
@ -81,25 +79,6 @@ namespace Microsoft.Bot.Builder.Dialogs
} }
} }
/// <summary>
/// Gets or sets the <see cref="LogTelemetryClient"/> to use for logging.
/// </summary>
/// <value>The <see cref="LogTelemetryClient"/> to use for logging.</value>
/// <seealso cref="DialogSet.LogTelemetryClient"/>
[JsonIgnore]
public virtual LogTelemetryClientBase LogTelemetryClient
{
get
{
return _logTelemetryClient;
}
set
{
_logTelemetryClient = value;
}
}
[JsonIgnore] [JsonIgnore]
public virtual SourceRange Source => DebugSupport.SourceMap.TryGetValue(this, out var range) ? range : null; public virtual SourceRange Source => DebugSupport.SourceMap.TryGetValue(this, out var range) ? range : null;
@ -264,18 +243,6 @@ namespace Microsoft.Bot.Builder.Dialogs
return this.GetType().Name; return this.GetType().Name;
} }
protected void TrackTelemetryEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
if (_logTelemetryClient != null && !(_logTelemetryClient is NullLogTelemetryClient))
{
_logTelemetryClient.TrackEvent(eventName, properties, metrics);
}
else
{
_telemetryClient.TrackEvent(eventName, properties, metrics);
}
}
protected void RegisterSourceLocation(string path, int lineNumber) protected void RegisterSourceLocation(string path, int lineNumber)
{ {
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))

Просмотреть файл

@ -18,7 +18,6 @@ namespace Microsoft.Bot.Builder.Dialogs
private readonly IDictionary<string, Dialog> _dialogs = new Dictionary<string, Dialog>(); private readonly IDictionary<string, Dialog> _dialogs = new Dictionary<string, Dialog>();
private IBotTelemetryClient _telemetryClient; private IBotTelemetryClient _telemetryClient;
private LogTelemetryClientBase _logTelemetryClient;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DialogSet"/> class. /// Initializes a new instance of the <see cref="DialogSet"/> class.
@ -33,14 +32,12 @@ namespace Microsoft.Bot.Builder.Dialogs
{ {
_dialogState = dialogState ?? throw new ArgumentNullException(nameof(dialogState)); _dialogState = dialogState ?? throw new ArgumentNullException(nameof(dialogState));
_telemetryClient = NullBotTelemetryClient.Instance; _telemetryClient = NullBotTelemetryClient.Instance;
_logTelemetryClient = new NullLogTelemetryClient();
} }
public DialogSet() public DialogSet()
{ {
_dialogState = null; _dialogState = null;
_telemetryClient = NullBotTelemetryClient.Instance; _telemetryClient = NullBotTelemetryClient.Instance;
_logTelemetryClient = new NullLogTelemetryClient();
} }
/// <summary> /// <summary>
@ -67,30 +64,6 @@ namespace Microsoft.Bot.Builder.Dialogs
} }
} }
/// <summary>
/// Gets or sets the <see cref="LogTelemetryClient"/> to use for logging.
/// </summary>
/// <value>The <see cref="LogTelemetryClient"/> to use for logging.</value>
/// <remarks>When this property is set, it sets the <see cref="Dialog.LogTelemetryClient"/> of each
/// dialog in the set to the new value.</remarks>
[JsonIgnore]
public LogTelemetryClientBase LogTelemetryClient
{
get
{
return _logTelemetryClient;
}
set
{
_logTelemetryClient = value ?? new NullLogTelemetryClient();
foreach (var dialog in _dialogs.Values)
{
dialog.LogTelemetryClient = _logTelemetryClient;
}
}
}
/// <summary> /// <summary>
/// Adds a new dialog to the set and returns the set to allow fluent chaining. /// Adds a new dialog to the set and returns the set to allow fluent chaining.
/// If the Dialog.Id being added already exists in the set, the dialogs id will be updated to /// If the Dialog.Id being added already exists in the set, the dialogs id will be updated to
@ -130,8 +103,6 @@ namespace Microsoft.Bot.Builder.Dialogs
} }
dialog.TelemetryClient = _telemetryClient; dialog.TelemetryClient = _telemetryClient;
dialog.LogTelemetryClient = _logTelemetryClient;
_dialogs[dialog.Id] = dialog; _dialogs[dialog.Id] = dialog;
// Automatically add any dependencies the dialog might have // Automatically add any dependencies the dialog might have

Просмотреть файл

@ -76,9 +76,8 @@ namespace Microsoft.Bot.Builder.Dialogs
{ "DialogId", Id }, { "DialogId", Id },
{ "InstanceId", instanceId }, { "InstanceId", instanceId },
}; };
TrackTelemetryEvent("WaterfallStart", properties); TelemetryClient.TrackEvent("WaterfallStart", properties);
TelemetryClient.TrackDialogView(Id);
LogTelemetryClient.TrackDialogView(Id);
// Run first step // Run first step
return await RunStepAsync(dc, 0, DialogReason.BeginCalled, null, cancellationToken).ConfigureAwait(false); return await RunStepAsync(dc, 0, DialogReason.BeginCalled, null, cancellationToken).ConfigureAwait(false);
@ -146,7 +145,7 @@ namespace Microsoft.Bot.Builder.Dialogs
{ "StepName", stepName }, { "StepName", stepName },
{ "InstanceId", instanceId }, { "InstanceId", instanceId },
}; };
TrackTelemetryEvent("WaterfallCancel", properties); TelemetryClient.TrackEvent("WaterfallCancel", properties);
} }
else if (reason == DialogReason.EndCalled) else if (reason == DialogReason.EndCalled)
{ {
@ -157,7 +156,7 @@ namespace Microsoft.Bot.Builder.Dialogs
{ "DialogId", Id }, { "DialogId", Id },
{ "InstanceId", instanceId }, { "InstanceId", instanceId },
}; };
TrackTelemetryEvent("WaterfallComplete", properties); TelemetryClient.TrackEvent("WaterfallComplete", properties);
} }
return Task.CompletedTask; return Task.CompletedTask;
@ -173,7 +172,7 @@ namespace Microsoft.Bot.Builder.Dialogs
{ "StepName", stepName }, { "StepName", stepName },
{ "InstanceId", instanceId }, { "InstanceId", instanceId },
}; };
TrackTelemetryEvent("WaterfallStep", properties); TelemetryClient.TrackEvent("WaterfallStep", properties);
return await _steps[stepContext.Index](stepContext, cancellationToken).ConfigureAwait(false); return await _steps[stepContext.Index](stepContext, cancellationToken).ConfigureAwait(false);
} }

Просмотреть файл

@ -64,6 +64,14 @@ namespace Microsoft.Bot.Builder
/// <param name="properties">Named string values you can use to search and classify events.</param> /// <param name="properties">Named string values you can use to search and classify events.</param>
void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties); void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties);
/// <summary>
/// Logs a dialog entry / as an Application Insights page view.
/// </summary>
/// <param name="dialogName">The name of the dialog to log the entry / start for.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
void TrackDialogView(string dialogName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary> /// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated. /// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary> /// </summary>

Просмотреть файл

@ -1,80 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
namespace Microsoft.Bot.Builder
{
/// <summary>
/// A logging client for bot telemetry.
/// </summary>
public abstract class LogTelemetryClientBase
{
/// <summary>
/// Send information about availability of an application.
/// </summary>
/// <param name="name">Availability test name.</param>
/// <param name="timeStamp">The time when the availability was captured.</param>
/// <param name="duration">The time taken for the availability test to run.</param>
/// <param name="runLocation">Name of the location the availability test was run from.</param>
/// <param name="success">True if the availability test ran successfully.</param>
/// <param name="message">Error message on availability test run failure.</param>
/// <param name="properties">Named string values you can use to classify and search for this availability telemetry.</param>
/// <param name="metrics">Additional values associated with this availability telemetry.</param>
public abstract void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Send information about an external dependency (outgoing call) in the application.
/// </summary>
/// <param name="dependencyTypeName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are SQL, Azure table, and HTTP.</param>
/// <param name="target">External dependency target.</param>
/// <param name="dependencyName">Name of the command initiated with this dependency call. Low cardinality value.
/// Examples are stored procedure name and URL path template.</param>
/// <param name="data">Command initiated by this dependency call. Examples are SQL statement and HTTP
/// URL's with all query parameters.</param>
/// <param name="startTime">The time when the dependency was called.</param>
/// <param name="duration">The time taken by the external dependency to handle the call.</param>
/// <param name="resultCode">Result code of dependency call execution.</param>
/// <param name="success">True if the dependency call was handled successfully.</param>
public abstract void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success);
/// <summary>
/// Logs custom events with extensible named fields.
/// </summary>
/// <param name="eventName">A name for the event.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
public abstract void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Logs a system exception.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="properties">Named string values you can use to classify and search for this exception.</param>
/// <param name="metrics">Additional values associated with this exception.</param>
public abstract void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Send a trace message.
/// </summary>
/// <param name="message">Message to display.</param>
/// <param name="severityLevel">Trace severity level <see cref="Severity"/>.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
public abstract void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties);
/// <summary>
/// Logs a page view.
/// </summary>
/// <param name="name">The name of the dialog view to log.</param>
/// <param name="properties">Named string values you can use to search and classify events.</param>
/// <param name="metrics">Measurements associated with this event.</param>
public abstract void TrackDialogView(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null);
/// <summary>
/// Flushes the in-memory buffer and any metrics being pre-aggregated.
/// </summary>
public abstract void Flush();
}
}

Просмотреть файл

@ -33,5 +33,9 @@ namespace Microsoft.Bot.Builder
public void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties) public void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties)
{ {
} }
public void TrackDialogView(string dialogName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
} }
} }

Просмотреть файл

@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
namespace Microsoft.Bot.Builder
{
public class NullLogTelemetryClient : LogTelemetryClientBase
{
public override void Flush()
{
}
public override void TrackAvailability(string name, DateTimeOffset timeStamp, TimeSpan duration, string runLocation, bool success, string message = null, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public override void TrackDependency(string dependencyTypeName, string target, string dependencyName, string data, DateTimeOffset startTime, TimeSpan duration, string resultCode, bool success)
{
}
public override void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public override void TrackException(Exception exception, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public override void TrackDialogView(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
}
public override void TrackTrace(string message, Severity severityLevel, IDictionary<string, string> properties)
{
}
}
}

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -21,24 +20,12 @@ namespace Microsoft.Bot.Builder
/// </summary> /// </summary>
/// <param name="telemetryClient">The telemetry client to send telemetry events to.</param> /// <param name="telemetryClient">The telemetry client to send telemetry events to.</param>
/// <param name="logPersonalInformation">`true` to include personally identifiable information; otherwise, `false`.</param> /// <param name="logPersonalInformation">`true` to include personally identifiable information; otherwise, `false`.</param>
[Obsolete("IBotTelemetryClient is now obselete. Please create with an instance of LogTelemetryClient instead.", false)]
public TelemetryLoggerMiddleware(IBotTelemetryClient telemetryClient, bool logPersonalInformation = false) public TelemetryLoggerMiddleware(IBotTelemetryClient telemetryClient, bool logPersonalInformation = false)
{ {
TelemetryClient = telemetryClient ?? new NullBotTelemetryClient(); TelemetryClient = telemetryClient ?? new NullBotTelemetryClient();
LogPersonalInformation = logPersonalInformation; LogPersonalInformation = logPersonalInformation;
} }
/// <summary>
/// Initializes a new instance of the <see cref="TelemetryLoggerMiddleware"/> class.
/// </summary>
/// <param name="logTelemetryClient">The telemetry client to send telemetry events to.</param>
/// <param name="logPersonalInformation">`true` to include personally identifiable information; otherwise, `false`.</param>
public TelemetryLoggerMiddleware(LogTelemetryClientBase logTelemetryClient, bool logPersonalInformation = false)
{
LogTelemetryClient = logTelemetryClient ?? new NullLogTelemetryClient();
LogPersonalInformation = logPersonalInformation;
}
/// <summary> /// <summary>
/// Gets a value indicating whether to include personal information that came from the user. /// Gets a value indicating whether to include personal information that came from the user.
/// </summary> /// </summary>
@ -59,15 +46,6 @@ namespace Microsoft.Bot.Builder
[JsonIgnore] [JsonIgnore]
public IBotTelemetryClient TelemetryClient { get; } public IBotTelemetryClient TelemetryClient { get; }
/// <summary>
/// Gets The telemetry client to send telemetry events to.
/// </summary>
/// <value>
/// The <see cref="IBotTelemetryClient"/> this middleware uses to log events.
/// </value>
[JsonIgnore]
public LogTelemetryClientBase LogTelemetryClient { get; }
/// <summary> /// <summary>
/// Logs events for incoming, outgoing, updated, or deleted message activities, using the <see cref="TelemetryClient"/>. /// Logs events for incoming, outgoing, updated, or deleted message activities, using the <see cref="TelemetryClient"/>.
/// </summary> /// </summary>
@ -151,7 +129,7 @@ namespace Microsoft.Bot.Builder
/// <returns>A task that represents the work queued to execute.</returns> /// <returns>A task that represents the work queued to execute.</returns>
protected virtual async Task OnReceiveActivityAsync(Activity activity, CancellationToken cancellation) protected virtual async Task OnReceiveActivityAsync(Activity activity, CancellationToken cancellation)
{ {
TrackTelemetryEvent(TelemetryLoggerConstants.BotMsgReceiveEvent, await FillReceiveEventPropertiesAsync(activity).ConfigureAwait(false)); TelemetryClient.TrackEvent(TelemetryLoggerConstants.BotMsgReceiveEvent, await FillReceiveEventPropertiesAsync(activity).ConfigureAwait(false));
return; return;
} }
@ -167,7 +145,7 @@ namespace Microsoft.Bot.Builder
/// <returns>A task that represents the work queued to execute.</returns> /// <returns>A task that represents the work queued to execute.</returns>
protected virtual async Task OnSendActivityAsync(Activity activity, CancellationToken cancellation) protected virtual async Task OnSendActivityAsync(Activity activity, CancellationToken cancellation)
{ {
TrackTelemetryEvent(TelemetryLoggerConstants.BotMsgSendEvent, await FillSendEventPropertiesAsync(activity).ConfigureAwait(false)); TelemetryClient.TrackEvent(TelemetryLoggerConstants.BotMsgSendEvent, await FillSendEventPropertiesAsync(activity).ConfigureAwait(false));
return; return;
} }
@ -183,7 +161,7 @@ namespace Microsoft.Bot.Builder
/// <returns>A task that represents the work queued to execute.</returns> /// <returns>A task that represents the work queued to execute.</returns>
protected virtual async Task OnUpdateActivityAsync(Activity activity, CancellationToken cancellation) protected virtual async Task OnUpdateActivityAsync(Activity activity, CancellationToken cancellation)
{ {
TrackTelemetryEvent(TelemetryLoggerConstants.BotMsgUpdateEvent, await FillUpdateEventPropertiesAsync(activity).ConfigureAwait(false)); TelemetryClient.TrackEvent(TelemetryLoggerConstants.BotMsgUpdateEvent, await FillUpdateEventPropertiesAsync(activity).ConfigureAwait(false));
return; return;
} }
@ -199,7 +177,7 @@ namespace Microsoft.Bot.Builder
/// <returns>A task that represents the work queued to execute.</returns> /// <returns>A task that represents the work queued to execute.</returns>
protected virtual async Task OnDeleteActivityAsync(Activity activity, CancellationToken cancellation) protected virtual async Task OnDeleteActivityAsync(Activity activity, CancellationToken cancellation)
{ {
TrackTelemetryEvent(TelemetryLoggerConstants.BotMsgDeleteEvent, await FillDeleteEventPropertiesAsync(activity).ConfigureAwait(false)); TelemetryClient.TrackEvent(TelemetryLoggerConstants.BotMsgDeleteEvent, await FillDeleteEventPropertiesAsync(activity).ConfigureAwait(false));
return; return;
} }
@ -359,17 +337,5 @@ namespace Microsoft.Bot.Builder
return Task.FromResult(properties); return Task.FromResult(properties);
} }
protected void TrackTelemetryEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
if (LogTelemetryClient != null && !(LogTelemetryClient is NullLogTelemetryClient))
{
LogTelemetryClient.TrackEvent(eventName, properties, metrics);
}
else
{
TelemetryClient.TrackEvent(eventName, properties, metrics);
}
}
} }
} }

Просмотреть файл

@ -128,6 +128,16 @@ namespace Microsoft.Bot.Builder.Integration.ApplicationInsights.Tests
_mockTelemetryChannel.Verify(tc => tc.Send(It.Is<TraceTelemetry>(t => t.SeverityLevel == SeverityLevel.Critical))); _mockTelemetryChannel.Verify(tc => tc.Send(It.Is<TraceTelemetry>(t => t.SeverityLevel == SeverityLevel.Critical)));
_mockTelemetryChannel.Verify(tc => tc.Send(It.Is<TraceTelemetry>(t => t.Properties["foo"] == "bar"))); _mockTelemetryChannel.Verify(tc => tc.Send(It.Is<TraceTelemetry>(t => t.Properties["foo"] == "bar")));
} }
[TestMethod]
public void TrackDialogViewTest()
{
_botTelemetryClient.TrackDialogView("test", new Dictionary<string, string>() { { "hello", "value" } }, new Dictionary<string, double>() { { "metric", 0.6 } });
_mockTelemetryChannel.Verify(tc => tc.Send(It.Is<PageViewTelemetry>(t => t.Name == "test")));
_mockTelemetryChannel.Verify(tc => tc.Send(It.Is<PageViewTelemetry>(t => t.Properties["hello"] == "value")));
_mockTelemetryChannel.Verify(tc => tc.Send(It.Is<PageViewTelemetry>(t => t.Metrics["metric"] == 0.6)));
}
} }
} }
} }

Просмотреть файл

@ -40,6 +40,11 @@ namespace Microsoft.Bot.Builder.Integration.ApplicationInsights.Tests
base.TrackTrace(message, severityLevel, properties); base.TrackTrace(message, severityLevel, properties);
} }
public override void TrackDialogView(string name, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
base.TrackDialogView(name, properties, metrics);
}
public override void Flush() public override void Flush()
{ {
base.Flush(); base.Flush();

Просмотреть файл

@ -48,6 +48,7 @@ namespace Microsoft.Bot.Builder.Integration.ApplicationInsights.Tests
.Send("hello") .Send("hello")
.AssertReply("step3") .AssertReply("step3")
.StartTestAsync(); .StartTestAsync();
telemetryClient.Verify(m => m.TrackDialogView("test", It.IsAny<IDictionary<string, string>>(), It.IsAny<IDictionary<string, double>>()), Times.Exactly(1));
telemetryClient.Verify(m => m.TrackEvent(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<IDictionary<string, double>>()), Times.Exactly(4)); telemetryClient.Verify(m => m.TrackEvent(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<IDictionary<string, double>>()), Times.Exactly(4));
Console.WriteLine("Complete"); Console.WriteLine("Complete");
} }

Просмотреть файл

@ -25,7 +25,7 @@ namespace Microsoft.Bot.Builder.Tests
// //
// Note: The TelemetryClient will most likely be DI'd in, and handling a null // Note: The TelemetryClient will most likely be DI'd in, and handling a null
// TelemetryClient should be handled by placing the NullBotTelemetryClient(). // TelemetryClient should be handled by placing the NullBotTelemetryClient().
var logger = new TelemetryLoggerMiddleware(telemetryClient: null, logPersonalInformation: true); var logger = new TelemetryLoggerMiddleware(null, logPersonalInformation: true);
// Assert // Assert
Assert.IsNotNull(logger); Assert.IsNotNull(logger);