Skip to content

Commit cd3ac3f

Browse files
committed
get events tracked as otel activity events!
1 parent e2864ec commit cd3ac3f

File tree

8 files changed

+98
-167
lines changed

8 files changed

+98
-167
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class TelemetryEventEntry
1111
public static ITelemetryFilter TelemetryFilter { get; set; } = new BlockFilter();
1212

1313
public static void TrackEvent(
14-
string? eventName = null,
14+
string eventName,
1515
IDictionary<string, string?>? properties = null,
1616
IDictionary<string, double>? measurements = null)
1717
{
@@ -32,7 +32,7 @@ public static void SendFiltered(object? o = null)
3232
}
3333
}
3434

35-
public static void Subscribe(Action<string?, IDictionary<string, string?>?, IDictionary<string, double>?> subscriber)
35+
public static void Subscribe(Action<string, IDictionary<string, string?>?, IDictionary<string, double>?> subscriber)
3636
{
3737
void Handler(object? sender, InstrumentationEventArgs eventArgs)
3838
{
@@ -47,24 +47,24 @@ public sealed class PerformanceMeasurement : IDisposable
4747
{
4848
private readonly Stopwatch? _timer;
4949
private readonly Dictionary<string, double>? _data;
50-
private readonly string? _name;
50+
private readonly string _name;
5151

5252
public PerformanceMeasurement(Dictionary<string, double>? data, string name)
5353
{
54+
_name = name;
5455
// Measurement is a no-op if we don't have a dictionary to store the entry.
5556
if (data == null)
5657
{
5758
return;
5859
}
5960

6061
_data = data;
61-
_name = name;
6262
_timer = Stopwatch.StartNew();
6363
}
6464

6565
public void Dispose()
6666
{
67-
if (_name is not null && _timer is not null)
67+
if (_timer is not null)
6868
{
6969
_data?.Add(_name, _timer.Elapsed.TotalMilliseconds);
7070
}
@@ -82,7 +82,7 @@ public IEnumerable<ApplicationInsightsEntryFormat> Filter(object o)
8282
public class InstrumentationEventArgs : EventArgs
8383
{
8484
internal InstrumentationEventArgs(
85-
string? eventName,
85+
string eventName,
8686
IDictionary<string, string?>? properties,
8787
IDictionary<string, double>? measurements)
8888
{
@@ -91,17 +91,17 @@ internal InstrumentationEventArgs(
9191
Measurements = measurements;
9292
}
9393

94-
public string? EventName { get; }
94+
public string EventName { get; }
9595
public IDictionary<string, string?>? Properties { get; }
9696
public IDictionary<string, double>? Measurements { get; }
9797
}
9898

9999
public class ApplicationInsightsEntryFormat(
100-
string? eventName = null,
100+
string eventName,
101101
IDictionary<string, string?>? properties = null,
102102
IDictionary<string, double>? measurements = null)
103103
{
104-
public string? EventName { get; } = eventName;
104+
public string EventName { get; } = eventName;
105105
public IDictionary<string, string?>? Properties { get; } = properties;
106106
public IDictionary<string, double>? Measurements { get; } = measurements;
107107

src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
using System.CommandLine;
75
using Microsoft.DotNet.Cli.Extensions;
86
using Microsoft.DotNet.Cli.Telemetry;
97
using Microsoft.DotNet.Cli.Utils;
10-
using Microsoft.DotNet.Configurer;
118

129
namespace Microsoft.DotNet.Cli.Commands.Hidden.InternalReportInstallSuccess;
1310

@@ -19,7 +16,6 @@ public static int Run(ParseResult parseResult)
1916
{
2017
var telemetry = new ThreadBlockingTelemetry();
2118
ProcessInputAndSendTelemetry(parseResult, telemetry);
22-
telemetry.Dispose();
2319
return 0;
2420
}
2521

@@ -47,29 +43,19 @@ internal class ThreadBlockingTelemetry : ITelemetry
4743

4844
internal ThreadBlockingTelemetry()
4945
{
50-
var sessionId =
51-
Environment.GetEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName);
52-
telemetry = new Telemetry.Telemetry(sessionId, blockThreadInitialization: true);
46+
var sessionId = Environment.GetEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName);
47+
telemetry = new Telemetry.Telemetry(sessionId);
5348
}
5449
public bool Enabled => telemetry.Enabled;
5550

56-
public void Flush()
57-
{
58-
}
59-
60-
public void Dispose()
61-
{
62-
telemetry.Dispose();
63-
}
64-
65-
public void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements)
51+
public void TrackEvent(string eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements)
6652
{
6753
telemetry.ThreadBlockingTrackEvent(eventName, properties, measurements);
6854
}
6955
}
7056
}
7157

72-
internal class InstallerSuccessReport(string exeName)
58+
internal class InstallerSuccessReport(string? exeName)
7359
{
7460
public string ExeName { get; } = exeName ?? throw new ArgumentNullException(nameof(exeName));
7561
}

src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ public MSBuildLogger()
5757

5858
if (sessionId != null)
5959
{
60-
// senderCount: 0 to disable sender.
61-
// When senders in different process running at the same
62-
// time they will read from the same global queue and cause
63-
// sending duplicated events. Disable sender to reduce it.
64-
_telemetry = new Telemetry.Telemetry(
65-
sessionId,
66-
senderCount: 0);
60+
_telemetry = new Telemetry.Telemetry(sessionId);
6761
}
6862
}
6963
catch (Exception)

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ private static IEnumerable<string> GetTemplateFolders(IEngineEnvironmentSettings
4444
{
4545
var templateFoldersToInstall = new List<string>();
4646

47-
var sdkDirectory = Path.GetDirectoryName(typeof(Utils.DotnetFiles).Assembly.Location);
48-
var dotnetRootPath = Path.GetDirectoryName(Path.GetDirectoryName(sdkDirectory));
49-
47+
var sdksDirectory = new DirectoryInfo(environmentSettings.Environment.GetEnvironmentVariable("MSBuildSDKsPath"));
48+
var sdkDirectory = sdksDirectory.Parent!;
49+
var sdkVersion = sdkDirectory.Name;
50+
var dotnetRootPath = sdkDirectory.Parent!.Parent!;
5051
// First grab templates from dotnet\templates\M.m folders, in ascending order, up to our version
51-
string templatesRootFolder = Path.GetFullPath(Path.Combine(dotnetRootPath, "templates"));
52+
string templatesRootFolder = Path.Combine(dotnetRootPath.FullName, "templates");
5253
if (Directory.Exists(templatesRootFolder))
5354
{
5455
IReadOnlyDictionary<string, SemanticVersion> parsedNames = GetVersionDirectoriesInDirectory(templatesRootFolder);
@@ -59,7 +60,7 @@ private static IEnumerable<string> GetTemplateFolders(IEngineEnvironmentSettings
5960
}
6061

6162
// Now grab templates from our base folder, if present.
62-
string templatesDir = Path.Combine(sdkDirectory, "Templates");
63+
string templatesDir = Path.Combine(sdkDirectory.FullName, "Templates");
6364
if (Directory.Exists(templatesDir))
6465
{
6566
templateFoldersToInstall.Add(templatesDir);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ public Task<IReadOnlyList<ITemplatePackage>> GetAllTemplatePackagesAsync(Cancell
3333
{
3434
var list = new List<TemplatePackage>();
3535
var optionalWorkloadLocator = new TemplateLocator.TemplateLocator();
36-
var sdkDirectory = Path.GetDirectoryName(typeof(DotnetFiles).Assembly.Location);
37-
var sdkVersion = Path.GetFileName(sdkDirectory);
38-
var dotnetRootPath = Path.GetDirectoryName(Path.GetDirectoryName(sdkDirectory));
36+
var sdksDirectory = new DirectoryInfo(_environmentSettings.Environment.GetEnvironmentVariable("MSBuildSDKsPath"));
37+
var sdkDirectory = sdksDirectory.Parent!;
38+
var sdkVersion = sdkDirectory.Name;
39+
var dotnetRootPath = sdkDirectory.Parent!.Parent!;
3940
string userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;
4041

41-
var packages = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetRootPath, userProfileDir);
42+
var packages = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetRootPath.FullName, userProfileDir);
4243
var fileSystem = _environmentSettings.Host.FileSystem;
4344
foreach (var packageInfo in packages)
4445
{
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
64
namespace Microsoft.DotNet.Cli.Telemetry;
75

8-
public interface ITelemetry : IDisposable
6+
public interface ITelemetry
97
{
108
bool Enabled { get; }
119

12-
void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements);
13-
14-
void Flush();
10+
void TrackEvent(string eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements);
1511
}

0 commit comments

Comments
 (0)