Skip to content

Commit 6ee764b

Browse files
committed
add traces to dotnet new instantiation
1 parent cd3ac3f commit 6ee764b

13 files changed

+43
-35
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<PackageVersion Include="System.Composition.Runtime" Version="$(SystemCompositionRuntimePackageVersion)" />
111111
<PackageVersion Include="System.Composition.TypedParts" Version="$(SystemCompositionTypedPartsPackageVersion)" />
112112
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
113+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourcePackageVersion)" />
113114
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
114115
<PackageVersion Include="System.IO.Hashing" Version="$(SystemIOHashingPackageVersion)" />
115116
<!-- System.Reflection.Metadata and System.Collections.Immutable cannot be pinned here because of hard dependencies within Roslyn on specific versions that have to work both here and in VS -->
@@ -159,4 +160,4 @@
159160
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildMinimumVersion)" />
160161
<PackageVersion Include="Microsoft.NET.StringTools" Version="$(MicrosoftBuildMinimumVersion)" />
161162
</ItemGroup>
162-
</Project>
163+
</Project>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<SystemCompositionRuntimePackageVersion>10.0.0-preview.6.25313.102</SystemCompositionRuntimePackageVersion>
125125
<SystemCompositionTypedPartsPackageVersion>10.0.0-preview.6.25313.102</SystemCompositionTypedPartsPackageVersion>
126126
<SystemConfigurationConfigurationManagerPackageVersion>10.0.0-preview.6.25313.102</SystemConfigurationConfigurationManagerPackageVersion>
127+
<SystemDiagnosticsDiagnosticSourcePackageVersion>10.0.0-preview.6.25313.106</SystemDiagnosticsDiagnosticSourcePackageVersion>
127128
<SystemReflectionMetadataLoadContextVersion>10.0.0-preview.6.25313.102</SystemReflectionMetadataLoadContextVersion>
128129
<SystemResourcesExtensionsPackageVersion>10.0.0-preview.6.25313.102</SystemResourcesExtensionsPackageVersion>
129130
<SystemSecurityCryptographyPkcsPackageVersion>10.0.0-preview.6.25313.102</SystemSecurityCryptographyPkcsPackageVersion>

src/Cli/dotnet/Activities.cs renamed to src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
14
using System.Diagnostics;
2-
using Microsoft.DotNet.Cli.Utils;
35

4-
namespace Microsoft.DotNet.Cli;
6+
namespace Microsoft.DotNet.Cli.Utils;
57

68

79
public static class Activities

src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static string GetMSBuildExePath()
171171
MSBuildExeName);
172172
}
173173

174-
private static string GetMSBuildSDKsPath()
174+
public static string GetMSBuildSDKsPath()
175175
{
176176
var envMSBuildSDKsPath = Environment.GetEnvironmentVariable("MSBuildSDKsPath");
177177

src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' == '.NETCoreApp'"
4343
GeneratePathProperty="true" />
4444
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
45+
<PackageReference Include="System.Diagnostics.DiagnosticSource"/>
4546
<PackageReference Include="NuGet.Versioning" />
4647
<PackageReference Include="NuGet.Packaging" />
4748
<PackageReference Include="NuGet.Frameworks" />

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal static async Task<IEnumerable<TemplateGroup>> GetTemplateGroupsAsync(
7474
HostSpecificDataLoader hostSpecificDataLoader,
7575
CancellationToken cancellationToken)
7676
{
77+
using var createTemplateGroupsActivity = Activities.s_source.StartActivity("create-template-groups");
7778
IReadOnlyList<ITemplateInfo> templates = await templatePackageManager.GetTemplatesAsync(cancellationToken).ConfigureAwait(false);
7879
return TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templates, hostSpecificDataLoader));
7980
}
@@ -84,6 +85,7 @@ internal static HashSet<TemplateCommand> GetTemplateCommand(
8485
TemplatePackageManager templatePackageManager,
8586
TemplateGroup templateGroup)
8687
{
88+
using var getTemplateActivity = Activities.s_source.StartActivity("get-template-command");
8789
//groups templates in the group by precedence
8890
foreach (IGrouping<int, CliTemplateInfo> templateGrouping in templateGroup.Templates.GroupBy(g => g.Precedence).OrderByDescending(g => g.Key))
8991
{
@@ -204,6 +206,8 @@ private static async Task<NewCommandStatus> ExecuteIntAsync(
204206

205207
return await templateListCoordinator.DisplayCommandDescriptionAsync(instantiateArgs, cancellationToken).ConfigureAwait(false);
206208
}
209+
using var createActivity = Activities.s_source.StartActivity("instantiate-command");
210+
createActivity?.DisplayName = $"Invoke '{instantiateArgs.ShortName}'";
207211

208212
IEnumerable<TemplateGroup> allTemplateGroups = await GetTemplateGroupsAsync(
209213
templatePackageManager,
@@ -273,10 +277,11 @@ private static async Task<NewCommandStatus> HandleTemplateInstantiationAsync(
273277
{
274278
TemplateCommand templateCommandToRun = candidates.Single();
275279
args.Command.Subcommands.Add(templateCommandToRun);
276-
280+
var templateParseActivity = Activities.s_source.StartActivity("reparse-for-template");
277281
ParseResult updatedParseResult = args.ParseResult.RootCommandResult.Command.Parse(
278282
args.ParseResult.Tokens.Select(t => t.Value).ToArray(),
279283
args.ParseResult.Configuration);
284+
templateParseActivity?.Stop();
280285
return await candidates.Single().InvokeAsync(updatedParseResult, cancellationToken).ConfigureAwait(false);
281286
}
282287
else if (candidates.Any())

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,23 @@ internal static async Task<IReadOnlyList<TemplateConstraintResult>> ValidateCons
146146

147147
internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
148148
{
149+
using var templateInvocationActivity = Activities.s_source.StartActivity("invoke-template");
149150
TemplateCommandArgs args = new(this, _instantiateCommand, parseResult);
150151
TemplateInvoker invoker = new(_environmentSettings, () => Console.ReadLine() ?? string.Empty);
151152
TemplatePackageCoordinator packageCoordinator = new(_environmentSettings, _templatePackageManager);
152-
TemplateConstraintManager constraintManager = new(_environmentSettings);
153+
using TemplateConstraintManager constraintManager = new(_environmentSettings);
153154
TemplatePackageDisplay templatePackageDisplay = new(Reporter.Output, Reporter.Error);
154155

155156
CancellationTokenSource cancellationTokenSource = new();
156157
cancellationTokenSource.CancelAfter(ConstraintEvaluationTimeout);
157158

159+
#pragma warning disable CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
158160
Task<IReadOnlyList<TemplateConstraintResult>> constraintsEvaluation = ValidateConstraintsAsync(constraintManager, args.Template, args.IsForceFlagSpecified ? cancellationTokenSource.Token : cancellationToken);
161+
#pragma warning restore CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
159162

160163
if (!args.IsForceFlagSpecified)
161164
{
165+
using var constraintResultsActivity = Activities.s_source.StartActivity("validate-constraints");
162166
var constraintResults = await constraintsEvaluation.ConfigureAwait(false);
163167
if (constraintResults.Any())
164168
{

src/Cli/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal TemplateInvoker(
3737

3838
internal async Task<NewCommandStatus> InvokeTemplateAsync(TemplateCommandArgs templateArgs, CancellationToken cancellationToken)
3939
{
40+
using var invokerActivity = Activities.s_source.StartActivity("invoker-invoking");
4041
cancellationToken.ThrowIfCancellationRequested();
4142

4243
CliTemplateInfo templateToRun = templateArgs.Template;
@@ -158,6 +159,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
158159

159160
try
160161
{
162+
using var templateCreationActivity = Activities.s_source.StartActivity("actual-instantiate-template");
161163
instantiateResult = await _templateCreator.InstantiateAsync(
162164
templateArgs.Template,
163165
templateArgs.Name,
@@ -306,6 +308,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
306308

307309
private NewCommandStatus HandlePostActions(ITemplateCreationResult creationResult, TemplateCommandArgs args)
308310
{
311+
using var postActionActivity = Activities.s_source.StartActivity("post-actions");
309312
PostActionExecutionStatus result = _postActionDispatcher.Process(creationResult, args.IsDryRun, args.AllowScripts ?? AllowRunScripts.Prompt);
310313

311314
return result switch

src/Cli/Microsoft.TemplateEngine.Cli/TemplateListCoordinator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal TemplateListCoordinator(
3030
_templatePackageManager = templatePackageManager ?? throw new ArgumentNullException(nameof(templatePackageManager));
3131
_hostSpecificDataLoader = hostSpecificDataLoader ?? throw new ArgumentNullException(nameof(hostSpecificDataLoader));
3232
_defaultLanguage = engineEnvironmentSettings.GetDefaultLanguage();
33+
using var constraintManagerActivity = Activities.s_source.StartActivity("create-constraints");
3334
_constraintManager = new TemplateConstraintManager(_engineEnvironmentSettings);
3435
}
3536

src/Cli/dotnet/Commands/New/BuiltInTemplatePackageProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable disable
55

6+
using Microsoft.DotNet.Cli.Utils;
67
using Microsoft.TemplateEngine.Abstractions;
78
using Microsoft.TemplateEngine.Abstractions.TemplatePackage;
89
using NuGet.Versioning;
@@ -44,7 +45,7 @@ private static IEnumerable<string> GetTemplateFolders(IEngineEnvironmentSettings
4445
{
4546
var templateFoldersToInstall = new List<string>();
4647

47-
var sdksDirectory = new DirectoryInfo(environmentSettings.Environment.GetEnvironmentVariable("MSBuildSDKsPath"));
48+
var sdksDirectory = new DirectoryInfo(MSBuildForwardingAppWithoutLogging.GetMSBuildSDKsPath());
4849
var sdkDirectory = sdksDirectory.Parent!;
4950
var sdkVersion = sdkDirectory.Name;
5051
var dotnetRootPath = sdkDirectory.Parent!.Parent!;

src/Cli/dotnet/Commands/New/OptionalWorkloadProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable disable
55

6+
using Microsoft.DotNet.Cli.Commands.MSBuild;
67
using Microsoft.DotNet.Cli.Utils;
78
using Microsoft.DotNet.Configurer;
89
using Microsoft.TemplateEngine.Abstractions;
@@ -33,7 +34,7 @@ public Task<IReadOnlyList<ITemplatePackage>> GetAllTemplatePackagesAsync(Cancell
3334
{
3435
var list = new List<TemplatePackage>();
3536
var optionalWorkloadLocator = new TemplateLocator.TemplateLocator();
36-
var sdksDirectory = new DirectoryInfo(_environmentSettings.Environment.GetEnvironmentVariable("MSBuildSDKsPath"));
37+
var sdksDirectory = new DirectoryInfo(MSBuildForwardingAppWithoutLogging.GetMSBuildSDKsPath());
3738
var sdkDirectory = sdksDirectory.Parent!;
3839
var sdkVersion = sdkDirectory.Name;
3940
var dotnetRootPath = sdkDirectory.Parent!.Parent!;

test/dotnet.Tests/ConfigurerTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,7 @@ private Telemetry RunConfigUsingMocks(bool isInstallerRun)
252252

253253
configurer.Configure();
254254

255-
return new Telemetry("test",
256-
environmentProvider: _environmentProviderObject,
257-
senderCount: 0);
255+
return new Telemetry("test", environmentProvider: _environmentProviderObject);
258256
}
259257

260258
private class MockBasicSentinel : IFileSentinel, IFirstTimeUseNoticeSentinel, IAspNetCertificateSentinel

test/dotnet.Tests/TelemetryCommonPropertiesTests.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,24 @@ public void TelemetryCommonPropertiesShouldReturnDevDeviceId()
4141
var unitUnderTest = new TelemetryCommonProperties(getDeviceId: () => "plaintext", userLevelCacheWriter: new NothingCache());
4242
unitUnderTest.GetTelemetryCommonProperties()["devdeviceid"].Should().Be("plaintext");
4343
}
44-
4544
[Fact]
4645
public void TelemetryCommonPropertiesShouldReturnNewGuidWhenCannotGetMacAddress()
4746
{
4847
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
4948
var assignedMachineId = unitUnderTest.GetTelemetryCommonProperties()["Machine ID"];
5049

51-
Guid.TryParse(assignedMachineId, out var _).Should().BeTrue("it should be a guid");
50+
Guid.TryParse((string)assignedMachineId, out var _).Should().BeTrue("it should be a guid");
5251
}
53-
5452
[Fact]
5553
public void TelemetryCommonPropertiesShouldEnsureDevDeviceIDIsCached()
5654
{
5755
var unitUnderTest = new TelemetryCommonProperties(userLevelCacheWriter: new NothingCache());
5856
var assignedMachineId = unitUnderTest.GetTelemetryCommonProperties()["devdeviceid"];
5957

60-
Guid.TryParse(assignedMachineId, out var _).Should().BeTrue("it should be a guid");
58+
Guid.TryParse((string)assignedMachineId, out var _).Should().BeTrue("it should be a guid");
6159
var secondAssignedMachineId = unitUnderTest.GetTelemetryCommonProperties()["devdeviceid"];
6260

63-
Guid.TryParse(secondAssignedMachineId, out var _).Should().BeTrue("it should be a guid");
61+
Guid.TryParse((string)secondAssignedMachineId, out var _).Should().BeTrue("it should be a guid");
6462
secondAssignedMachineId.Should().Be(assignedMachineId, "it should match the previously assigned guid");
6563
}
6664

@@ -70,14 +68,13 @@ public void TelemetryCommonPropertiesShouldReturnHashedMachineIdOld()
7068
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => "plaintext", userLevelCacheWriter: new NothingCache());
7169
unitUnderTest.GetTelemetryCommonProperties()["Machine ID Old"].Should().NotBe("plaintext");
7270
}
73-
7471
[Fact]
7572
public void TelemetryCommonPropertiesShouldReturnNewGuidWhenCannotGetMacAddressOld()
7673
{
7774
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
7875
var assignedMachineId = unitUnderTest.GetTelemetryCommonProperties()["Machine ID Old"];
7976

80-
Guid.TryParse(assignedMachineId, out var _).Should().BeTrue("it should be a guid");
77+
Guid.TryParse((string)assignedMachineId, out var _).Should().BeTrue("it should be a guid");
8178
}
8279

8380
[Fact]
@@ -107,59 +104,52 @@ public void TelemetryCommonPropertiesShouldContainArchitectureInformation()
107104
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
108105
unitUnderTest.GetTelemetryCommonProperties()["OS Architecture"].Should().Be(RuntimeInformation.OSArchitecture.ToString());
109106
}
110-
111107
[WindowsOnlyFact]
112108
public void TelemetryCommonPropertiesShouldContainWindowsInstallType()
113109
{
114110
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
115-
unitUnderTest.GetTelemetryCommonProperties()["Installation Type"].Should().NotBeEmpty();
111+
((string)unitUnderTest.GetTelemetryCommonProperties()["Installation Type"]).Should().NotBeEmpty();
116112
}
117-
118113
[UnixOnlyFact]
119114
public void TelemetryCommonPropertiesShouldContainEmptyWindowsInstallType()
120115
{
121116
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
122-
unitUnderTest.GetTelemetryCommonProperties()["Installation Type"].Should().BeEmpty();
117+
((string)unitUnderTest.GetTelemetryCommonProperties()["Installation Type"]).Should().BeEmpty();
123118
}
124-
125119
[WindowsOnlyFact]
126120
public void TelemetryCommonPropertiesShouldContainWindowsProductType()
127121
{
128122
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
129-
unitUnderTest.GetTelemetryCommonProperties()["Product Type"].Should().NotBeEmpty();
123+
((string)unitUnderTest.GetTelemetryCommonProperties()["Product Type"]).Should().NotBeEmpty();
130124
}
131-
132125
[UnixOnlyFact]
133126
public void TelemetryCommonPropertiesShouldContainEmptyWindowsProductType()
134127
{
135128
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
136-
unitUnderTest.GetTelemetryCommonProperties()["Product Type"].Should().BeEmpty();
129+
((string)unitUnderTest.GetTelemetryCommonProperties()["Product Type"]).Should().BeEmpty();
137130
}
138-
139131
[WindowsOnlyFact]
140132
public void TelemetryCommonPropertiesShouldContainEmptyLibcReleaseAndVersion()
141133
{
142134
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
143-
unitUnderTest.GetTelemetryCommonProperties()["Libc Release"].Should().BeEmpty();
144-
unitUnderTest.GetTelemetryCommonProperties()["Libc Version"].Should().BeEmpty();
135+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Release"]).Should().BeEmpty();
136+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Version"]).Should().BeEmpty();
145137
}
146-
147138
[MacOsOnlyFact]
148139
public void TelemetryCommonPropertiesShouldContainEmptyLibcReleaseAndVersion2()
149140
{
150141
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
151-
unitUnderTest.GetTelemetryCommonProperties()["Libc Release"].Should().BeEmpty();
152-
unitUnderTest.GetTelemetryCommonProperties()["Libc Version"].Should().BeEmpty();
142+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Release"]).Should().BeEmpty();
143+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Version"]).Should().BeEmpty();
153144
}
154-
155145
[LinuxOnlyFact]
156146
public void TelemetryCommonPropertiesShouldContainLibcReleaseAndVersion()
157147
{
158148
if (!RuntimeInformation.RuntimeIdentifier.Contains("alpine", StringComparison.OrdinalIgnoreCase))
159149
{
160150
var unitUnderTest = new TelemetryCommonProperties(getMACAddress: () => null, userLevelCacheWriter: new NothingCache());
161-
unitUnderTest.GetTelemetryCommonProperties()["Libc Release"].Should().NotBeEmpty();
162-
unitUnderTest.GetTelemetryCommonProperties()["Libc Version"].Should().NotBeEmpty();
151+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Release"]).Should().NotBeEmpty();
152+
((string)unitUnderTest.GetTelemetryCommonProperties()["Libc Version"]).Should().NotBeEmpty();
163153
}
164154
}
165155

0 commit comments

Comments
 (0)