Skip to content

Commit 9e817f9

Browse files
authored
feat(telemetry): add Otel4Vsix integration (#19)
* feat(telemetry): add Otel4Vsix integration - Add CodingWithCalvin.Otel4Vsix package reference - Configure telemetry in SuperCleanPackage with Honeycomb export - Add HoneycombConfig.cs for API key placeholder - Instrument SuperClean commands with activities and logging - Track project counts and deletion status in telemetry - Add proper telemetry shutdown in Dispose - Remove explicit DeployExtension (VsixSdk handles this) * fix(telemetry): remove sensitive data from telemetry Remove project names and item names from telemetry tags and logs to avoid sending potentially sensitive information.
1 parent faa22f0 commit 9e817f9

4 files changed

Lines changed: 78 additions & 8 deletions

File tree

src/CodingWithCalvin.SuperClean/CodingWithCalvin.SuperClean.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
<OutputPath>bin/$(Configuration)/</OutputPath>
99
</PropertyGroup>
1010

11-
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
12-
<DeployExtension>True</DeployExtension>
13-
</PropertyGroup>
14-
1511
<ItemGroup>
12+
<PackageReference Include="CodingWithCalvin.Otel4Vsix" Version="0.2.2" />
1613
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.492" />
1714
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
1815
</ItemGroup>

src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Design;
34
using System.IO;
45
using System.Text;
56
using System.Threading.Tasks;
7+
using CodingWithCalvin.Otel4Vsix;
68
using Community.VisualStudio.Toolkit;
79
using Microsoft.VisualStudio.Shell;
810
using MessageBox = System.Windows.Forms.MessageBox;
@@ -42,12 +44,20 @@ public static void Initialize(Package package)
4244

4345
private static void OpenPathWrapper(object sender, EventArgs e)
4446
{
47+
using var activity = VsixTelemetry.StartCommandActivity("SuperClean.OpenPathWrapper");
48+
4549
try
4650
{
4751
_ = OpenPathAsync(sender, e);
4852
}
4953
catch (Exception ex)
5054
{
55+
activity?.RecordError(ex);
56+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
57+
{
58+
{ "operation.name", "OpenPathWrapper" }
59+
});
60+
5161
MessageBox.Show(
5262
$@"
5363
Fatal Error! Unable to invoke Super Clean!
@@ -60,14 +70,18 @@ Fatal Error! Unable to invoke Super Clean!
6070

6171
private static async Task OpenPathAsync(object sender, EventArgs e)
6272
{
73+
using var activity = VsixTelemetry.StartCommandActivity("SuperClean.OpenPathAsync");
74+
6375
var activeItem = await VS.Solutions.GetActiveItemAsync();
6476

6577
if (activeItem == null)
6678
{
79+
VsixTelemetry.LogInformation("No active item found");
6780
return;
6881
}
6982

70-
switch (activeItem.Type)
83+
activity?.SetTag("item.type", activeItem.Type.ToString());
84+
switch (activeItem.Type)
7185
{
7286
case SolutionItemType.Solution:
7387
try
@@ -78,9 +92,17 @@ private static async Task OpenPathAsync(object sender, EventArgs e)
7892
{
7993
throw new ApplicationException(errors);
8094
}
95+
96+
VsixTelemetry.LogInformation("Solution super cleaned successfully");
8197
}
8298
catch (Exception ex)
8399
{
100+
activity?.RecordError(ex);
101+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
102+
{
103+
{ "operation.name", "SuperCleanSolution" }
104+
});
105+
84106
MessageBox.Show(
85107
$@"
86108
Unable to Super Clean solution
@@ -95,9 +117,16 @@ Unable to Super Clean solution
95117
try
96118
{
97119
SuperCleanProject(activeItem);
120+
VsixTelemetry.LogInformation("Project super cleaned successfully");
98121
}
99122
catch (Exception ex)
100123
{
124+
activity?.RecordError(ex);
125+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
126+
{
127+
{ "operation.name", "SuperCleanProject" },
128+
});
129+
101130
MessageBox.Show(
102131
$@"
103132
Unable to Super Clean project ${activeItem.Name}
@@ -112,28 +141,38 @@ Unable to Super Clean project ${activeItem.Name}
112141

113142
async Task<(bool, string)> SuperCleanSolution()
114143
{
144+
using var solutionActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanSolution");
145+
115146
var success = true;
116147
var errors = new StringBuilder();
148+
var projectCount = 0;
117149

118150
foreach (var project in await VS.Solutions.GetAllProjectsAsync())
119151
{
120152
try
121153
{
122154
SuperCleanProject(project);
155+
projectCount++;
123156
}
124157
catch (Exception ex)
125158
{
126159
errors.AppendLine(ex.Message);
127160
success = false;
161+
solutionActivity?.RecordError(ex);
128162
}
129163
}
130164

165+
solutionActivity?.SetTag("projects.cleaned", projectCount);
166+
solutionActivity?.SetTag("success", success);
167+
131168
return (success, errors.ToString());
132169
}
133170

134171
void SuperCleanProject(SolutionItem project)
135172
{
136-
var projectPath =
173+
using var projectActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanProject");
174+
175+
var projectPath =
137176
Path.GetDirectoryName(project.FullPath)
138177
?? throw new InvalidOperationException();
139178

@@ -143,11 +182,13 @@ void SuperCleanProject(SolutionItem project)
143182
if (Directory.Exists(binPath))
144183
{
145184
Directory.Delete(binPath, true);
185+
projectActivity?.SetTag("bin.deleted", true);
146186
}
147187

148188
if (Directory.Exists(objPath))
149189
{
150190
Directory.Delete(objPath, true);
191+
projectActivity?.SetTag("obj.deleted", true);
151192
}
152193
}
153194
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CodingWithCalvin.SuperClean
2+
{
3+
internal static class HoneycombConfig
4+
{
5+
public const string ApiKey = "PLACEHOLDER";
6+
}
7+
}

src/CodingWithCalvin.SuperClean/SuperCleanPackage.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
1+
using System;
22
using System.Runtime.InteropServices;
33
using System.Threading;
4+
using CodingWithCalvin.Otel4Vsix;
45
using CodingWithCalvin.SuperClean.Commands;
56
using Microsoft.VisualStudio.Shell;
67
using Task = System.Threading.Tasks.Task;
@@ -20,7 +21,31 @@ IProgress<ServiceProgressData> progress
2021
{
2122
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
2223

24+
var builder = VsixTelemetry.Configure()
25+
.WithServiceName(VsixInfo.DisplayName)
26+
.WithServiceVersion(VsixInfo.Version)
27+
.WithVisualStudioAttributes(this)
28+
.WithEnvironmentAttributes();
29+
30+
#if !DEBUG
31+
builder
32+
.WithOtlpHttp("https://api.honeycomb.io")
33+
.WithHeader("x-honeycomb-team", HoneycombConfig.ApiKey);
34+
#endif
35+
36+
builder.Initialize();
37+
2338
SuperCleanCommand.Initialize(this);
2439
}
40+
41+
protected override void Dispose(bool disposing)
42+
{
43+
if (disposing)
44+
{
45+
VsixTelemetry.Shutdown();
46+
}
47+
48+
base.Dispose(disposing);
49+
}
2550
}
2651
}

0 commit comments

Comments
 (0)