Skip to content

Commit 7304a19

Browse files
committed
feat(telemetry): add Otel4Vsix integration
- Add CodingWithCalvin.Otel4Vsix package reference - Configure telemetry in OpenBinFolderPackage with Honeycomb export - Add HoneycombConfig.cs for API key placeholder - Instrument OpenPath and OpenProjectBinFolder with activities - Add proper telemetry shutdown in Dispose - Remove explicit DeployExtension (VsixSdk handles this)
1 parent 3735768 commit 7304a19

4 files changed

Lines changed: 94 additions & 32 deletions

File tree

src/CodingWithCalvin.OpenBinFolder/CodingWithCalvin.OpenBinFolder.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="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
1714
</ItemGroup>
1815

src/CodingWithCalvin.OpenBinFolder/Commands/OpenBinFolderCommand.cs

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Design;
34
using System.IO;
45
using System.Windows.Forms;
6+
using CodingWithCalvin.Otel4Vsix;
57
using EnvDTE;
68
using EnvDTE80;
79
using Microsoft.VisualStudio.Shell;
@@ -44,39 +46,48 @@ private void OpenPath(object sender, EventArgs e)
4446
{
4547
ThreadHelper.ThrowIfNotOnUIThread();
4648

47-
if (!(ServiceProvider.GetService(typeof(DTE)) is DTE2 dte))
48-
{
49-
throw new ArgumentNullException(nameof(dte));
50-
}
49+
using var activity = VsixTelemetry.StartCommandActivity("OpenBinFolder.OpenPath");
5150

52-
foreach (
53-
UIHierarchyItem selectedItem in (Array)
54-
dte.ToolWindows.SolutionExplorer.SelectedItems
55-
)
51+
try
5652
{
57-
switch (selectedItem.Object)
53+
if (!(ServiceProvider.GetService(typeof(DTE)) is DTE2 dte))
54+
{
55+
throw new ArgumentNullException(nameof(dte));
56+
}
57+
58+
foreach (
59+
UIHierarchyItem selectedItem in (Array)
60+
dte.ToolWindows.SolutionExplorer.SelectedItems
61+
)
5862
{
59-
case Project project:
60-
try
61-
{
63+
switch (selectedItem.Object)
64+
{
65+
case Project project:
6266
OpenProjectBinFolder(project);
63-
}
64-
catch (Exception ex)
65-
{
66-
MessageBox.Show(
67-
$@"
68-
Unable to determine output path for selected project
69-
{Environment.NewLine}
70-
{Environment.NewLine}
71-
Exception: {ex.Message}"
72-
);
73-
}
74-
75-
break;
67+
break;
68+
}
7669
}
70+
71+
VsixTelemetry.LogInformation("Bin folder opened successfully");
7772
}
73+
catch (Exception ex)
74+
{
75+
activity?.RecordError(ex);
76+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
77+
{
78+
{ "operation.name", "OpenPath" }
79+
});
80+
throw;
81+
}
82+
}
7883

79-
void OpenProjectBinFolder(Project project)
84+
private void OpenProjectBinFolder(Project project)
85+
{
86+
ThreadHelper.ThrowIfNotOnUIThread();
87+
88+
using var activity = VsixTelemetry.StartCommandActivity("OpenBinFolder.OpenProjectBinFolder");
89+
90+
try
8091
{
8192
var projectPath =
8293
Path.GetDirectoryName(project.FullName)
@@ -88,9 +99,31 @@ void OpenProjectBinFolder(Project project)
8899

89100
var projectBinPath = Path.Combine(projectPath, projectOutputPath);
90101

102+
activity?.SetTag("project.name", project.Name);
103+
activity?.SetTag("project.binPath", projectBinPath);
104+
91105
System.Diagnostics.Process.Start(
92106
Directory.Exists(projectBinPath) ? projectBinPath : projectPath
93107
);
108+
109+
VsixTelemetry.LogInformation("Opened bin folder for project {ProjectName}", project.Name);
110+
}
111+
catch (Exception ex)
112+
{
113+
activity?.RecordError(ex);
114+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
115+
{
116+
{ "operation.name", "OpenProjectBinFolder" },
117+
{ "project.name", project.Name }
118+
});
119+
120+
MessageBox.Show(
121+
$@"
122+
Unable to determine output path for selected project
123+
{Environment.NewLine}
124+
{Environment.NewLine}
125+
Exception: {ex.Message}"
126+
);
94127
}
95128
}
96129
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CodingWithCalvin.OpenBinFolder
2+
{
3+
internal static class HoneycombConfig
4+
{
5+
public const string ApiKey = "PLACEHOLDER";
6+
}
7+
}

src/CodingWithCalvin.OpenBinFolder/OpenBinFolderPackage.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
using System;
22
using System.Runtime.InteropServices;
33
using System.Threading;
44
using CodingWithCalvin.OpenBinFolder.Commands;
5+
using CodingWithCalvin.Otel4Vsix;
56
using Microsoft.VisualStudio.Shell;
67
using Task = System.Threading.Tasks.Task;
78

@@ -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
OpenBinFolderCommand.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)