Skip to content

Commit 438a317

Browse files
authored
feat(telemetry): add Otel4Vsix integration (#346)
1 parent d65d9b5 commit 438a317

5 files changed

Lines changed: 255 additions & 112 deletions

File tree

src/CodingWithCalvin.CouchbaseExplorer/CodingWithCalvin.CouchbaseExplorer.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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="CouchbaseNetClient" Version="3.8.1" />
1815
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
1916
</ItemGroup>

src/CodingWithCalvin.CouchbaseExplorer/CouchbaseExplorerPackage.cs

Lines changed: 17 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.CouchbaseExplorer.Editors;
5+
using CodingWithCalvin.Otel4Vsix;
56
using Microsoft.VisualStudio.Shell;
67
using Microsoft.VisualStudio.Shell.Interop;
78

@@ -32,6 +33,20 @@ IProgress<ServiceProgressData> progress
3233
{
3334
await JoinableTaskFactory.SwitchToMainThreadAsync();
3435

36+
var builder = VsixTelemetry.Configure()
37+
.WithServiceName(VsixInfo.DisplayName)
38+
.WithServiceVersion(VsixInfo.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+
3550
// Register the editor factory
3651
_editorFactory = new DocumentEditorFactory();
3752
RegisterEditorFactory(_editorFactory);
@@ -43,6 +58,7 @@ protected override void Dispose(bool disposing)
4358
{
4459
if (disposing)
4560
{
61+
VsixTelemetry.Shutdown();
4662
_editorFactory?.Dispose();
4763
}
4864
base.Dispose(disposing);

src/CodingWithCalvin.CouchbaseExplorer/CouchbaseExplorerWindowCommand.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.Design;
4+
using CodingWithCalvin.Otel4Vsix;
35
using Microsoft.VisualStudio.Shell;
46
using Microsoft.VisualStudio.Shell.Interop;
57

@@ -44,14 +46,30 @@ public static void Initialize(Package package)
4446

4547
private void ShowToolWindow(object sender, EventArgs e)
4648
{
47-
var window = this._package.FindToolWindow(typeof(CouchbaseExplorerWindow), 0, true);
48-
if (window?.Frame == null)
49+
using var activity = VsixTelemetry.StartCommandActivity("CouchbaseExplorer.ShowToolWindow");
50+
51+
try
4952
{
50-
throw new NotSupportedException("Cannot create tool window");
51-
}
53+
var window = this._package.FindToolWindow(typeof(CouchbaseExplorerWindow), 0, true);
54+
if (window?.Frame == null)
55+
{
56+
throw new NotSupportedException("Cannot create tool window");
57+
}
58+
59+
var windowFrame = (IVsWindowFrame)window.Frame;
60+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
5261

53-
var windowFrame = (IVsWindowFrame)window.Frame;
54-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
62+
VsixTelemetry.LogInformation("Couchbase Explorer tool window shown");
63+
}
64+
catch (Exception ex)
65+
{
66+
activity?.RecordError(ex);
67+
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
68+
{
69+
{ "operation.name", "ShowToolWindow" }
70+
});
71+
throw;
72+
}
5573
}
5674
}
5775
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CodingWithCalvin.CouchbaseExplorer
2+
{
3+
internal static class HoneycombConfig
4+
{
5+
public const string ApiKey = "PLACEHOLDER";
6+
}
7+
}

0 commit comments

Comments
 (0)