Skip to content

Commit 3e1d6a3

Browse files
committed
Merge pull request #2 from Azure/clu
added help files and updates on code review comments
2 parents 3b47868 + 43b752c commit 3e1d6a3

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed

src/CLU/Commands.ResourceManager.Cmdlets/Extensions/ResourceExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ internal static PSResourceObject ToPSResourceObject(this Resource<JToken> resour
6262
psObject.SubscriptionId = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id);
6363
psObject.Tags = TagsHelper.GetTagsHashtables(resource.Tags);
6464

65-
6665
var objectProperties = objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value });
6766

6867
for(int i=0; i< objectProperties.Length; i+=2)

src/CLU/Microsoft.Azure.Commands.Profile/Models/RMProfileClient.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,7 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
513513
if (subscriptions.Any())
514514
{
515515
WriteWarningMessage(string.Format(
516-
"TenantId '{0}' contains more than one subscription. First one will be selected for further use. " +
517-
"To select another subscription, use Set-AzureRmContext.",
516+
Resources.TooManyTenants,
518517
tenantId));
519518
}
520519
subscriptionFromServer = subscriptions.First();

src/CLU/Microsoft.Azure.Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CLU/Microsoft.Azure.Commands.Profile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@
186186
<data name="TenantIdNotFound" xml:space="preserve">
187187
<value>Unable to find tenant '{0}'.</value>
188188
</data>
189+
<data name="TooManyTenants" xml:space="preserve">
190+
<value>TenantId '{0}' contains more than one subscription. First one will be selected for further use. To select another subscription, use 'context set' cmdlet.</value>
191+
</data>
189192
<data name="TypeNotAccessToken" xml:space="preserve">
190193
<value>To create an access token credential, you must provide an access token account.</value>
191194
</data>

src/CLU/Microsoft.CLU/CommandBinder/CmdletBinderAndCommand.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using Microsoft.CLU.Help;
1212
using Microsoft.CLU.Metadata;
1313
using Microsoft.CLU.Common.Properties;
14+
using Microsoft.ApplicationInsights;
15+
using System.Management.Automation.Host;
1416

1517
namespace Microsoft.CLU.CommandBinder
1618
{
@@ -63,6 +65,7 @@ public CmdletBinderAndCommand(ConfigurationDictionary commandConfiguration, ICom
6365
_runtime = runtime;
6466
_commandConfiguration = commandConfiguration;
6567
_staticParameterBindInProgress = true;
68+
InitTelemetry();
6669
InitCmdlet(cmdletValue.LoadCmdlet(), cmdletValue.PackageAssembly.FullPath);
6770
Action<Type, uint, string> discriminatorBindFinished = (Type cmdletType, uint seekBackOffset, string fullPath) =>
6871
{
@@ -83,6 +86,7 @@ public CmdletBinderAndCommand(ConfigurationDictionary commandConfiguration, ICom
8386
Debug.Assert(runtime != null);
8487
_runtime = runtime;
8588
_commandConfiguration = commandConfiguration;
89+
InitTelemetry();
8690
Action<Type, uint, string> discriminatorBindFinished = (Type cmdletType, uint seekBackOffset, string fullPath) =>
8791
{
8892
_staticParameterBindInProgress = true;
@@ -253,12 +257,18 @@ public void Invoke()
253257
}
254258
catch (CmdletTerminateException terminateException)
255259
{
260+
_telemetryClient.TrackException(terminateException, GetErrorTelemetryProperties());
256261
_cmdlet.CommandRuntime.WriteError(terminateException.ErrorRecord);
257262
}
258263
catch (Exception exception)
259264
{
265+
_telemetryClient.TrackException(exception, GetErrorTelemetryProperties());
260266
_cmdlet.CommandRuntime.WriteError(new ErrorRecord(exception, "", ErrorCategory.InvalidResult, _cmdlet));
261267
}
268+
finally
269+
{
270+
_telemetryClient.Flush();
271+
}
262272
}
263273

264274
/// <summary>
@@ -341,6 +351,56 @@ private void InitCmdlet(Type cmdletType, string assemblyLocation)
341351
_staticParametersBindHandler = new BindHandler(_cmdlet, _staticParametersBindState);
342352
}
343353

354+
private IDictionary<string, string> GetErrorTelemetryProperties()
355+
{
356+
Dictionary<string, string> eventProperties = new Dictionary<string, string>();
357+
eventProperties.Add("IsSuccess", "False");
358+
if (_cmdlet != null)
359+
{
360+
eventProperties.Add("ModuleName", _cmdlet.GetType().GetTypeInfo().Assembly.GetName().Name);
361+
eventProperties.Add("ModuleVersion", _cmdlet.GetType().GetTypeInfo().Assembly.GetName().Version.ToString());
362+
var cmdletAliasAttribute = _cmdlet.GetType().GetTypeInfo().GetCustomAttributes()
363+
.FirstOrDefault((at) => at.GetType().FullName.Equals("System.Management.Automation.CliCommandAliasAttribute"));
364+
365+
if (cmdletAliasAttribute != null)
366+
{
367+
var attrType = cmdletAliasAttribute.GetType();
368+
eventProperties.Add("CommandName", "az " + (string)attrType.GetProperty("CommandName").GetValue(cmdletAliasAttribute));
369+
}
370+
}
371+
var _cluHost = _runtime as CLUHost;
372+
if (_cluHost != null)
373+
{
374+
eventProperties.Add("HostVersion", _cluHost.Version.ToString());
375+
eventProperties.Add("InputFromPipeline", _cluHost.IsInputRedirected.ToString());
376+
eventProperties.Add("OutputToPipeline", _cluHost.IsOutputRedirected.ToString());
377+
}
378+
if (CLUEnvironment.Platform.IsMacOSX)
379+
{
380+
eventProperties.Add("OS", "MacOS");
381+
}
382+
else if (CLUEnvironment.Platform.IsUnix)
383+
{
384+
eventProperties.Add("OS", "Unix");
385+
}
386+
else
387+
{
388+
eventProperties.Add("OS", "Windows");
389+
}
390+
return eventProperties;
391+
}
392+
393+
/// <summary>
394+
/// Initializes TelemetryClient using default channel.
395+
/// </summary>
396+
private void InitTelemetry()
397+
{
398+
_telemetryClient = new TelemetryClient
399+
{
400+
InstrumentationKey = "963c4276-ec20-48ad-b9ab-3968e9da5578"
401+
};
402+
}
403+
344404
/// <summary>
345405
/// Bind the dynamic parameters if cmdlet instance supports dynamic parameters.
346406
/// </summary>
@@ -533,7 +593,11 @@ private static bool MatchesParameterSet(ParameterMetadata parameter, string para
533593
return parameterSet == null || parameter.ParameterSets.ContainsKey(parameterSet);
534594
}
535595

536-
#region Private fields
596+
#region Private fields
597+
/// <summary>
598+
/// Telemetry client.
599+
/// </summary>
600+
private TelemetryClient _telemetryClient;
537601

538602
/// <summary>
539603
/// Configuration of the current command.

src/CLU/Microsoft.CLU/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"System.IO": "4.0.11-beta-23516",
1515
"System.Reflection": "4.1.0-beta-23516",
1616
"System.Reflection.TypeExtensions": "4.1.0-beta-23516",
17-
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516"
17+
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
18+
"Microsoft.ApplicationInsights": "2.0.0-beta3"
1819
},
1920
"contentExclude": [
2021
"*.xproj*"

0 commit comments

Comments
 (0)