Skip to content

[typespec-vs] Support telemetry in visual studio #7025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b0ac596
Merge pull request #1 from microsoft/main
mzhongl524 Nov 22, 2024
3fcbe52
Merge branch 'microsoft:main' into main
mzhongl524 Nov 25, 2024
c109816
Merge branch 'microsoft:main' into main
mzhongl524 Dec 6, 2024
23f0108
Merge branch 'microsoft:main' into main
mzhongl524 Dec 12, 2024
6f04f65
Merge branch 'microsoft:main' into main
mzhongl524 Dec 23, 2024
688ca03
Merge branch 'microsoft:main' into main
mzhongl524 Dec 24, 2024
de3725e
Merge branch 'microsoft:main' into main
mzhongl524 Dec 30, 2024
8130ffb
Merge branch 'microsoft:main' into main
mzhongl524 Jan 3, 2025
beb6433
Merge branch 'microsoft:main' into main
mzhongl524 Jan 15, 2025
8a501f2
Merge branch 'microsoft:main' into main
mzhongl524 Jan 15, 2025
6e1ab2d
Merge branch 'microsoft:main' into main
mzhongl524 Jan 23, 2025
a35052f
Merge branch 'microsoft:main' into main
mzhongl524 Jan 24, 2025
be57c13
Merge branch 'microsoft:main' into main
mzhongl524 Feb 5, 2025
3a9dc7a
Merge branch 'microsoft:main' into main
mzhongl524 Feb 10, 2025
ad7dff7
Merge branch 'microsoft:main' into main
mzhongl524 Feb 10, 2025
f8e8f2f
Merge branch 'microsoft:main' into main
mzhongl524 Feb 12, 2025
7a700c8
Merge branch 'microsoft:main' into main
mzhongl524 Feb 14, 2025
5099583
Merge branch 'microsoft:main' into main
mzhongl524 Feb 18, 2025
a45dbd5
Merge branch 'microsoft:main' into main
mzhongl524 Feb 25, 2025
68cc91d
Merge branch 'microsoft:main' into main
mzhongl524 Feb 25, 2025
48a44ad
Merge branch 'microsoft:main' into main
mzhongl524 Feb 27, 2025
b9283c4
Merge branch 'microsoft:main' into main
mzhongl524 Feb 28, 2025
4286411
Merge branch 'microsoft:main' into main
mzhongl524 Feb 28, 2025
e549035
Merge branch 'microsoft:main' into main
mzhongl524 Mar 5, 2025
9717310
Merge branch 'microsoft:main' into main
mzhongl524 Mar 6, 2025
75260f8
Merge branch 'microsoft:main' into main
mzhongl524 Mar 10, 2025
18b1595
Merge branch 'microsoft:main' into main
mzhongl524 Mar 11, 2025
51078a7
Merge branch 'microsoft:main' into main
mzhongl524 Mar 13, 2025
75ae17a
Merge branch 'microsoft:main' into main
mzhongl524 Mar 17, 2025
da28d95
Merge branch 'microsoft:main' into main
mzhongl524 Mar 18, 2025
4afbb98
Merge branch 'microsoft:main' into main
mzhongl524 Mar 25, 2025
463bdd5
Merge branch 'microsoft:main' into main
mzhongl524 Mar 27, 2025
c105d86
Merge branch 'microsoft:main' into main
mzhongl524 Mar 27, 2025
39dc63e
Merge branch 'microsoft:main' into main
mzhongl524 Mar 31, 2025
ddb0c11
Merge branch 'microsoft:main' into main
mzhongl524 Apr 1, 2025
dccb3dc
Merge branch 'microsoft:main' into main
mzhongl524 Apr 8, 2025
af9903b
Merge branch 'microsoft:main' into main
mzhongl524 Apr 10, 2025
2dddaf5
Merge branch 'microsoft:main' into main
mzhongl524 Apr 15, 2025
857b72b
Merge branch 'microsoft:main' into main
mzhongl524 Apr 16, 2025
41f34d9
Merge branch 'microsoft:main' into main
mzhongl524 Apr 17, 2025
5efea00
support telemetry in visual studio
mzhongl524 Apr 17, 2025
86b9f54
updated
mzhongl524 Apr 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/typespec-vs/src/VSExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
Expand Down Expand Up @@ -66,6 +67,7 @@ public event AsyncEventHandler<EventArgs>? StopAsync { add { } remove { } } // u

private readonly IVsFolderWorkspaceService _workspaceService;
private readonly SVsServiceProvider _serviceProvider;
private readonly IVsTelemetryService? _telemetryService;
private string? _workspaceFolder;
private string? _configuredTypeSpecServerPath;

Expand All @@ -75,6 +77,7 @@ public LanguageClient(
{
_workspaceService = workspaceService;
_serviceProvider = serviceProvider;
_telemetryService = serviceProvider.GetService(typeof(SVsTelemetryService)) as IVsTelemetryService;
}

public async Task<Connection?> ActivateAsync(CancellationToken token)
Expand Down Expand Up @@ -144,9 +147,41 @@ public async Task OnLoadedAsync()

public Task OnServerInitializedAsync()
{
string typespecCompilerVersion = GetTypespecVersion();
if (_telemetryService != null && !string.IsNullOrWhiteSpace(typespecCompilerVersion))
{
IVsTelemetryEvent telemetryEvent = _telemetryService.CreateEvent("vs/typespec/vs-extension/start-extension");
telemetryEvent.SetStringProperty("vs.typespec.compiler.version", typespecCompilerVersion);
_telemetryService.GetDefaultSession().PostEvent(telemetryEvent);
}
return Task.CompletedTask;
}

private string GetTypespecVersion()
{
try
{
ProcessStartInfo processStartInfo = new()
{
FileName = "cmd.exe",
Arguments = "/c tsp --version",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};

using Process process = Process.Start(processStartInfo);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output.Trim();
}
catch (Exception ex)
{
Debugger.Log(0, null, "tsp-server version exception: " + ex.Message);
return "";
}
}

private void LogStderrMessage(string? message)
{
if (message == null || message.Length == 0)
Expand Down
Loading