Skip to content

Commit 75489a5

Browse files
authored
feat(telemetry): add Otel4Vsix integration (#57)
1 parent a4ddb08 commit 75489a5

4 files changed

Lines changed: 71 additions & 13 deletions

File tree

src/CodingWithCalvin.ProjectRenamifier/CodingWithCalvin.ProjectRenamifier.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="CodingWithCalvin.VsixSdk/0.3.0">
1+
<Project Sdk="CodingWithCalvin.VsixSdk/0.3.0">
22

33
<PropertyGroup>
44
<TargetFramework>net48</TargetFramework>
@@ -9,11 +9,8 @@
99
<UseWPF>true</UseWPF>
1010
</PropertyGroup>
1111

12-
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
13-
<DeployExtension>True</DeployExtension>
14-
</PropertyGroup>
15-
1612
<ItemGroup>
13+
<PackageReference Include="CodingWithCalvin.Otel4Vsix" Version="0.2.2" />
1714
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
1815
</ItemGroup>
1916

@@ -29,4 +26,4 @@
2926
</Content>
3027
</ItemGroup>
3128

32-
</Project>
29+
</Project>

src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Collections.Generic;
12
using System.ComponentModel.Design;
23
using System.IO;
34
using System.Windows.Interop;
45
using System.Windows.Threading;
56
using CodingWithCalvin.ProjectRenamifier.Dialogs;
67
using CodingWithCalvin.ProjectRenamifier.Services;
8+
using CodingWithCalvin.Otel4Vsix;
79
using EnvDTE;
810
using EnvDTE80;
911

@@ -44,6 +46,8 @@ private void Execute(object sender, EventArgs e)
4446
{
4547
ThreadHelper.ThrowIfNotOnUIThread();
4648

49+
using var activity = VsixTelemetry.StartCommandActivity("ProjectRenamifier.Execute");
50+
4751
if (!(ServiceProvider.GetService(typeof(DTE)) is DTE2 dte))
4852
{
4953
return;
@@ -63,9 +67,10 @@ private void RenameProject(Project project, DTE2 dte)
6367
{
6468
ThreadHelper.ThrowIfNotOnUIThread();
6569

66-
var currentName = Path.GetFileNameWithoutExtension(project.FullName);
70+
using var activity = VsixTelemetry.StartCommandActivity("ProjectRenamifier.RenameProject");
6771

68-
var dialog = new RenameProjectDialog(currentName);
72+
var currentName = Path.GetFileNameWithoutExtension(project.FullName);
73+
var dialog = new RenameProjectDialog(currentName);
6974

7075
// Set the owner to the VS main window for proper modal behavior
7176
var helper = new WindowInteropHelper(dialog)
@@ -75,13 +80,16 @@ private void RenameProject(Project project, DTE2 dte)
7580

7681
if (dialog.ShowDialog() != true)
7782
{
83+
VsixTelemetry.LogInformation("Rename cancelled by user");
7884
return;
7985
}
8086

8187
var newName = dialog.NewProjectName;
8288
var projectFilePath = project.FullName;
8389
var originalProjectFilePath = projectFilePath;
8490

91+
VsixTelemetry.LogInformation("Renaming project");
92+
8593
// Show progress dialog
8694
var progressDialog = new RenameProgressDialog(currentName);
8795
var progressHelper = new WindowInteropHelper(progressDialog)
@@ -93,7 +101,7 @@ private void RenameProject(Project project, DTE2 dte)
93101
var stepIndex = 0;
94102
var projectRemovedFromSolution = false;
95103
var projectReaddedToSolution = false;
96-
System.Collections.Generic.List<string> referencingProjects = null;
104+
List<string> referencingProjects = null;
97105
Project parentSolutionFolder = null;
98106

99107
try
@@ -172,13 +180,27 @@ private void RenameProject(Project project, DTE2 dte)
172180
DoEvents();
173181
System.Threading.Thread.Sleep(500);
174182
progressDialog.Close();
183+
184+
activity?.SetTag("rename.success", true);
185+
activity?.SetTag("rename.steps_completed", stepIndex);
186+
VsixTelemetry.LogInformation("Successfully renamed project");
175187
}
176188
catch (Exception ex)
177189
{
178190
// Mark the current step as failed
179191
progressDialog.FailStep(stepIndex, ex.Message);
180192
DoEvents();
181193

194+
activity?.RecordError(ex);
195+
activity?.SetTag("rename.success", false);
196+
activity?.SetTag("rename.failed_step", stepIndex);
197+
198+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
199+
{
200+
{ "operation.name", "RenameProject" },
201+
{ "step.index", stepIndex }
202+
});
203+
182204
// Attempt rollback if project was removed but not re-added
183205
if (projectRemovedFromSolution && !projectReaddedToSolution)
184206
{
@@ -187,13 +209,16 @@ private void RenameProject(Project project, DTE2 dte)
187209
// Try to re-add the project at its current location
188210
var currentProjectPath = File.Exists(projectFilePath) ? projectFilePath : originalProjectFilePath;
189211
if (File.Exists(currentProjectPath))
190-
{
191-
SolutionFolderService.AddProjectToSolution(dte.Solution, currentProjectPath, parentSolutionFolder);
212+
{ SolutionFolderService.AddProjectToSolution(dte.Solution, currentProjectPath, parentSolutionFolder);
213+
VsixTelemetry.LogInformation("Rollback: Re-added project");
192214
}
193215
}
194-
catch
216+
catch (Exception rollbackEx)
195217
{
196-
// Rollback failed, nothing more we can do
218+
VsixTelemetry.TrackException(rollbackEx, new Dictionary<string, object>
219+
{
220+
{ "operation.name", "RenameProject.Rollback" }
221+
});
197222
}
198223
}
199224

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CodingWithCalvin.ProjectRenamifier
2+
{
3+
internal static class HoneycombConfig
4+
{
5+
public const string ApiKey = "PLACEHOLDER";
6+
}
7+
}

src/CodingWithCalvin.ProjectRenamifier/ProjectRenamifierPackage.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
global using Task = System.Threading.Tasks.Task;
44
using System.Runtime.InteropServices;
55
using System.Threading;
6+
using CodingWithCalvin.Otel4Vsix;
67

78
namespace CodingWithCalvin.ProjectRenamifier
89
{
@@ -14,10 +15,38 @@ public sealed class ProjectRenamifierPackage : AsyncPackage
1415
{
1516
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
1617
{
18+
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
19+
20+
var builder = VsixTelemetry.Configure()
21+
.WithServiceName(VsixInfo.DisplayName)
22+
.WithServiceVersion(VsixInfo.Version)
23+
.WithVisualStudioAttributes(this)
24+
.WithEnvironmentAttributes();
25+
26+
#if !DEBUG
27+
builder
28+
.WithOtlpHttp("https://api.honeycomb.io")
29+
.WithHeader("x-honeycomb-team", HoneycombConfig.ApiKey);
30+
#endif
31+
32+
builder.Initialize();
33+
1734
await Task.Run(() =>
1835
{
1936
RenamifyProjectCommand.Initialize(this);
2037
});
38+
39+
VsixTelemetry.LogInformation("Project Renamifier initialized successfully");
40+
}
41+
42+
protected override void Dispose(bool disposing)
43+
{
44+
if (disposing)
45+
{
46+
VsixTelemetry.Shutdown();
47+
}
48+
49+
base.Dispose(disposing);
2150
}
2251
}
2352
}

0 commit comments

Comments
 (0)