/// <summary>
        /// Add the common properties to the telemetry event.
        /// </summary>
        private IDictionary <string, string> CreateProperties(ITelemetryData telemetryData, PredictionClient client)
        {
            var properties = TelemetryUtilities.CreateCommonProperties(this._azContext);

            properties.Add("RequestId", telemetryData.RequestId);
            properties.Add("CommandId", telemetryData.CommandId);

            if (client != null)
            {
                properties.Add("ClientId", client.Name);
                properties.Add("ClientType", client.Kind.ToString());
            }

            return(properties);
        }
Пример #2
0
        /// <inheritdoc/>
        protected override void EndProcessing()
        {
            TelemetryClient telemetryClient         = TelemetryUtilities.CreateApplicationInsightTelemetryClient();
            var             settings                = Settings.GetSettings();
            var             nestedPowerShellRuntime = new PowerShellRuntime();
            var             azContext               = new AzContext(nestedPowerShellRuntime)
            {
                IsInternal = (settings.SetAsInternal == true) ? true : false,
            };

            var invocation      = MyInvocation;
            var command         = invocation.MyCommand;
            var boundParameters = new StringBuilder("{");

            foreach (var p in invocation.BoundParameters)
            {
                boundParameters.Append($"{p.Key}: {p.Value.ToString()},");
            }

            if (boundParameters.Length > 1)
            {
                // There is a ',' at the end. We need to remove it.
                boundParameters.Remove(boundParameters.Length - 1, 1);
            }

            boundParameters.Append("}");

            var properties = TelemetryUtilities.CreateCommonProperties(azContext);

            properties.Add("CommandName", command.Name);
            properties.Add("BoundParameters", boundParameters.ToString());

            if (AdditionalTelemetryProperties != null)
            {
                foreach (var property in AdditionalTelemetryProperties)
                {
                    properties.TryAdd(property.Key, property.Value);
                }
            }

            telemetryClient.TrackEvent($"{TelemetryUtilities.TelemetryEventPrefix}/Cmdlet", properties);

#if DEBUG
            WriteDebug($"command name: {command.Name}, parameters: {boundParameters.ToString()}");
#endif

            base.EndProcessing();
        }
Пример #3
0
        /// <inheritdoc/>
        protected override void BeginProcessing()
        {
            TelemetryClient telemetryClient = TelemetryUtilities.CreateApplicationInsightTelemetryClient();
            var             settings        = Settings.GetSettings();
            var             azContext       = new AzContext()
            {
                IsInternal = (settings.SetAsInternal == true) ? true : false,
                SurveyId   = settings.SurveyId?.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
            };

            var invocation      = MyInvocation;
            var command         = invocation.MyCommand;
            var boundParameters = new StringBuilder("{");

            foreach (var p in invocation.BoundParameters)
            {
                boundParameters.Append($"{p.Key}: {p.Value.ToString()},");
            }

            if (boundParameters.Length > 1)
            {
                // There is a ',' at the end. We need to remove it.
                boundParameters.Remove(boundParameters.Length - 1, 1);
            }

            boundParameters.Append("}");

            var properties = TelemetryUtilities.CreateCommonProperties(azContext);

            properties.Add("CommandName", command.Name);
            properties.Add("BoundParameters", boundParameters.ToString());
            telemetryClient.TrackEvent($"{TelemetryUtilities.TelemetryEventPrefix}/Cmdlet", properties);

#if DEBUG
            WriteDebug($"command name: {command.Name}, parameters: {boundParameters.ToString()}");
#endif

            base.BeginProcessing();
        }
 /// <summary>
 /// Gets the client that can send telemetry via Application Insight.
 /// </summary>
 protected virtual TelemetryClient GetApplicationInsightTelemetryClient() => TelemetryUtilities.CreateApplicationInsightTelemetryClient();