Skip to content

Commit db38a80

Browse files
authored
Convert numeric telemetry parameters to measurements for better analytics (#51071)
2 parents 8f5ca8f + 5c69c4d commit db38a80

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/Cli/dotnet/Commands/Run/RunTelemetry.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public static void TrackRunEvent(
4747
{
4848
["app_type"] = isFileBased ? "file_based" : "project_based",
4949
["project_id"] = projectIdentifier,
50-
["sdk_count"] = sdkCount.ToString(),
51-
["package_reference_count"] = packageReferenceCount.ToString(),
52-
["project_reference_count"] = projectReferenceCount.ToString(),
50+
};
51+
52+
var measurements = new Dictionary<string, double>
53+
{
54+
["sdk_count"] = sdkCount,
55+
["package_reference_count"] = packageReferenceCount,
56+
["project_reference_count"] = projectReferenceCount,
5357
};
5458

5559
// Launch profile telemetry
@@ -75,7 +79,7 @@ public static void TrackRunEvent(
7579
// File-based app specific telemetry
7680
if (isFileBased)
7781
{
78-
properties["additional_properties_count"] = additionalPropertiesCount.ToString();
82+
measurements["additional_properties_count"] = additionalPropertiesCount;
7983
if (usedMSBuild.HasValue)
8084
{
8185
properties["used_msbuild"] = usedMSBuild.Value ? "true" : "false";
@@ -86,7 +90,7 @@ public static void TrackRunEvent(
8690
}
8791
}
8892

89-
TelemetryEventEntry.TrackEvent(RunEventName, properties, measurements: null);
93+
TelemetryEventEntry.TrackEvent(RunEventName, properties, measurements);
9094
}
9195

9296
/// <summary>
@@ -234,4 +238,4 @@ private static bool IsDefaultProfile(string? profileName)
234238
// The default profile name at this point is "(Default)"
235239
return profileName.Equals("(Default)", StringComparison.OrdinalIgnoreCase);
236240
}
237-
}
241+
}

test/dotnet.Tests/CommandTests/Run/RunTelemetryTests.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ public void TrackRunEvent_FileBasedApp_SendsCorrectTelemetry()
146146
{
147147
// Arrange
148148
var events = new List<(string? eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements)>();
149-
149+
150150
void handler(object? sender, InstrumentationEventArgs args) => events.Add((args.EventName, args.Properties, args.Measurements));
151-
151+
152152
TelemetryEventEntry.EntryPosted += handler;
153153

154154
try
@@ -172,18 +172,21 @@ public void TrackRunEvent_FileBasedApp_SendsCorrectTelemetry()
172172
var eventData = events[0];
173173
eventData.eventName.Should().Be("run");
174174
eventData.properties.Should().NotBeNull();
175-
175+
eventData.measurements.Should().NotBeNull();
176+
176177
var props = eventData.properties!;
177178
props["app_type"].Should().Be("file_based");
178179
props["project_id"].Should().Be("test-hash");
179-
props["sdk_count"].Should().Be("2");
180-
props["package_reference_count"].Should().Be("3");
181-
props["project_reference_count"].Should().Be("1");
182-
props["additional_properties_count"].Should().Be("2");
183180
props["used_msbuild"].Should().Be("true");
184181
props["used_roslyn_compiler"].Should().Be("false");
185182
props["launch_profile_requested"].Should().Be("explicit");
186183
props["launch_profile_is_default"].Should().Be("true");
184+
185+
var measurements = eventData.measurements!;
186+
measurements["sdk_count"].Should().Be(2);
187+
measurements["package_reference_count"].Should().Be(3);
188+
measurements["project_reference_count"].Should().Be(1);
189+
measurements["additional_properties_count"].Should().Be(2);
187190
}
188191
finally
189192
{
@@ -197,9 +200,9 @@ public void TrackRunEvent_ProjectBasedApp_SendsCorrectTelemetry()
197200
{
198201
// Arrange
199202
var events = new List<(string? eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements)>();
200-
203+
201204
void handler(object? sender, InstrumentationEventArgs args) => events.Add((args.EventName, args.Properties, args.Measurements));
202-
205+
203206
TelemetryEventEntry.EntryPosted += handler;
204207

205208
try
@@ -220,17 +223,20 @@ public void TrackRunEvent_ProjectBasedApp_SendsCorrectTelemetry()
220223
var eventData = events[0];
221224
eventData.eventName.Should().Be("run");
222225
eventData.properties.Should().NotBeNull();
223-
226+
eventData.measurements.Should().NotBeNull();
227+
224228
var props = eventData.properties!;
225229
props["app_type"].Should().Be("project_based");
226230
props["project_id"].Should().Be("project-hash");
227-
props["sdk_count"].Should().Be("1");
228-
props["package_reference_count"].Should().Be("5");
229-
props["project_reference_count"].Should().Be("2");
230231
props["launch_profile_requested"].Should().Be("none");
231-
props.Should().NotContainKey("additional_properties_count");
232232
props.Should().NotContainKey("used_msbuild");
233233
props.Should().NotContainKey("used_roslyn_compiler");
234+
235+
var measurements = eventData.measurements!;
236+
measurements["sdk_count"].Should().Be(1);
237+
measurements["package_reference_count"].Should().Be(5);
238+
measurements["project_reference_count"].Should().Be(2);
239+
measurements.Should().NotContainKey("additional_properties_count");
234240
}
235241
finally
236242
{
@@ -244,9 +250,9 @@ public void TrackRunEvent_WithDefaultLaunchProfile_MarksTelemetryCorrectly()
244250
{
245251
// Arrange
246252
var events = new List<(string? eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements)>();
247-
253+
248254
void handler(object? sender, InstrumentationEventArgs args) => events.Add((args.EventName, args.Properties, args.Measurements));
249-
255+
250256
TelemetryEventEntry.EntryPosted += handler;
251257

252258
var launchSettings = new ProjectLaunchSettingsModel

0 commit comments

Comments
 (0)