Skip to content

Commit 39a7f63

Browse files
authored
feature: add otel using honeycomb (#22)
1 parent ce87ae2 commit 39a7f63

File tree

5 files changed

+74
-22
lines changed

5 files changed

+74
-22
lines changed

src/CodingWithCalvin.OpenInNotepadPlusPlus/CodingWithCalvin.OpenInNotepadPlusPlus.csproj

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="17.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
4+
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
55
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
66
<UseCodebase>true</UseCodebase>
77
</PropertyGroup>
8-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
9-
<PlatformTarget>x64</PlatformTarget>
10-
<OutputPath>bin\x64\Release\</OutputPath>
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
9+
<OutputPath>bin\Release\</OutputPath>
10+
<DefineConstants>
11+
</DefineConstants>
1112
<Optimize>true</Optimize>
12-
<DefineConstants>X64</DefineConstants>
13+
<PlatformTarget>AnyCPU</PlatformTarget>
14+
<LangVersion>latest</LangVersion>
15+
<UseWinFormsOutOfProcDesigner>False</UseWinFormsOutOfProcDesigner>
1316
</PropertyGroup>
14-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
1518
<DebugSymbols>true</DebugSymbols>
16-
<OutputPath>bin\x64\Debug\</OutputPath>
17-
<PlatformTarget>x64</PlatformTarget>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>TRACE;DEBUG</DefineConstants>
1821
<DebugType>full</DebugType>
19-
<DefineConstants>TRACE;DEBUG;X64</DefineConstants>
22+
<PlatformTarget>AnyCPU</PlatformTarget>
23+
<LangVersion>latest</LangVersion>
24+
<DeployExtension>True</DeployExtension>
25+
<UseWinFormsOutOfProcDesigner>False</UseWinFormsOutOfProcDesigner>
2026
</PropertyGroup>
2127
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
2228
<PropertyGroup>
2329
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
24-
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
30+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
2531
<SchemaVersion>2.0</SchemaVersion>
2632
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
2733
<ProjectGuid>{ADD4175C-AA5C-49E4-AFAF-6B9D3E832E8D}</ProjectGuid>
@@ -36,18 +42,22 @@
3642
<IncludeDebugSymbolsInLocalVSIXDeployment>true</IncludeDebugSymbolsInLocalVSIXDeployment>
3743
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
3844
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
45+
<LangVersion>latest</LangVersion>
3946
<StartAction>Program</StartAction>
4047
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
4148
<StartArguments>/rootsuffix Exp</StartArguments>
4249
<VsixType>v3</VsixType>
4350
</PropertyGroup>
4451
<ItemGroup>
4552
<PackageReference Include="Microsoft.VisualStudio.SDK">
46-
<Version>15.0.1</Version>
53+
<Version>17.14.40265</Version>
4754
</PackageReference>
4855
<PackageReference Include="Microsoft.VSSDK.BuildTools">
49-
<Version>17.0.5232</Version>
50-
<IncludeAssets>runtime; build; native; contentfiles; analyzers;</IncludeAssets>
56+
<Version>17.14.2120</Version>
57+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
58+
</PackageReference>
59+
<PackageReference Include="CodingWithCalvin.Otel4Vsix">
60+
<Version>0.2.0</Version>
5161
</PackageReference>
5262
</ItemGroup>
5363
<ItemGroup>
@@ -90,9 +100,9 @@
90100
<Compile Include="Dialogs\SettingsDialogPage.cs">
91101
<SubType>Component</SubType>
92102
</Compile>
93-
<Compile Include="Helpers\Logger.cs" />
94103
<Compile Include="Helpers\ProjectHelpers.cs" />
95104
<Compile Include="OpenInNotepadPlusPlusPackage.cs" />
105+
<Compile Include="HoneycombConfig.cs" />
96106
<Compile Include="Properties\AssemblyInfo.cs" />
97107
<Compile Include="source.extension.cs">
98108
<AutoGen>True</AutoGen>

src/CodingWithCalvin.OpenInNotepadPlusPlus/Commands/OpenExecutableCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Design;
34
using System.Diagnostics;
45
using System.Windows.Forms;
56
using CodingWithCalvin.OpenInNotepadPlusPlus.Dialogs;
67
using CodingWithCalvin.OpenInNotepadPlusPlus.Helpers;
8+
using CodingWithCalvin.Otel4Vsix;
79
using EnvDTE;
810
using EnvDTE80;
911
using Microsoft.VisualStudio.Shell;
@@ -45,26 +47,37 @@ public static void Initialize(Package package, SettingsDialogPage settings)
4547

4648
private void OpenPath(object sender, EventArgs e)
4749
{
50+
using var activity = VsixTelemetry.StartCommandActivity("OpenInNotepadPlusPlus.OpenPath");
51+
4852
var service = (DTE2)this.ServiceProvider.GetService(typeof(DTE));
4953
try
5054
{
5155
ThreadHelper.ThrowIfNotOnUIThread();
5256
var selectedFilePath = ProjectHelpers.GetSelectedPath(service);
5357
var executablePath = _settings.FolderPath;
58+
5459
if (
5560
!string.IsNullOrEmpty(selectedFilePath) && !string.IsNullOrEmpty(executablePath)
5661
)
5762
{
63+
VsixTelemetry.LogInformation("Opening file in Notepad++");
5864
OpenExecutable(executablePath, selectedFilePath);
5965
}
6066
else
6167
{
68+
VsixTelemetry.LogError("Could not resolve path!");
6269
MessageBox.Show("Couldn't resolve the folder");
6370
}
6471
}
6572
catch (Exception ex)
6673
{
67-
Logger.Log(ex);
74+
activity?.RecordError(ex);
75+
76+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
77+
{
78+
{ "operation.name", "OpenPath" },
79+
{ "command.name", "OpenInNotepadPlusPlus" }
80+
});
6881
}
6982
}
7083

src/CodingWithCalvin.OpenInNotepadPlusPlus/Dialogs/SettingsDialogPage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.ComponentModel;
33
using System.IO;
4-
using System.Linq;
54
using Microsoft.VisualStudio.Shell;
65

76
namespace CodingWithCalvin.OpenInNotepadPlusPlus.Dialogs
@@ -41,7 +40,7 @@ var directory in directoryInfo.Parent.GetDirectories(
4140
)
4241
)
4342
{
44-
foreach (var fileSystemInfo in directory.GetDirectories("Notepad++").Reverse())
43+
foreach (var fileSystemInfo in directory.GetDirectories("Notepad++"))
4544
{
4645
var path = Path.Combine(fileSystemInfo.FullName, "notepad++.exe");
4746
if (File.Exists(path))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CodingWithCalvin.OpenInNotepadPlusPlus
2+
{
3+
internal static class HoneycombConfig
4+
{
5+
// CI replaces PLACEHOLDER before Release builds
6+
public const string ApiKey = "PLACEHOLDER";
7+
}
8+
}

src/CodingWithCalvin.OpenInNotepadPlusPlus/OpenInNotepadPlusPlusPackage.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
1+
using System;
22
using System.Runtime.InteropServices;
33
using System.Threading;
44
using CodingWithCalvin.OpenInNotepadPlusPlus.Commands;
55
using CodingWithCalvin.OpenInNotepadPlusPlus.Dialogs;
6-
using CodingWithCalvin.OpenInNotepadPlusPlus.Helpers;
6+
using CodingWithCalvin.Otel4Vsix;
77
using Microsoft.VisualStudio.Shell;
88

99
namespace CodingWithCalvin.OpenInNotepadPlusPlus
@@ -33,8 +33,30 @@ IProgress<ServiceProgressData> progress
3333

3434
var settings = (SettingsDialogPage)this.GetDialogPage(typeof(SettingsDialogPage));
3535

36-
Logger.Initialize(this, Vsix.Name);
36+
var builder = VsixTelemetry.Configure()
37+
.WithServiceName(Vsix.Name)
38+
.WithServiceVersion(Vsix.Version)
39+
.WithVisualStudioAttributes(this)
40+
.WithEnvironmentAttributes();
41+
42+
#if !DEBUG
43+
builder
44+
.WithOtlpHttp("https://api.honeycomb.io")
45+
.WithHeader("x-honeycomb-team", HoneycombConfig.ApiKey);
46+
#endif
47+
48+
builder.Initialize();
49+
3750
OpenExecutableCommand.Initialize(this, settings);
3851
}
52+
53+
protected override void Dispose(bool disposing)
54+
{
55+
if (disposing)
56+
{
57+
VsixTelemetry.Shutdown();
58+
}
59+
base.Dispose(disposing);
60+
}
3961
}
4062
}

0 commit comments

Comments
 (0)