Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
Telemetry update
Browse files Browse the repository at this point in the history
  • Loading branch information
xpouyat committed Jul 29, 2022
1 parent ed5bd97 commit 0713d01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@ $RECYCLE.BIN/
.DS_Store
/SetupAMSExplorer/SetupAMSExplorer.isl.776
/MigrationBackup
/AMSExplorer/appsettings.json
5 changes: 5 additions & 0 deletions AMSExplorer/AMSExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.17.4-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="24.0.0" />
<PackageReference Include="Microsoft.Azure.Storage.DataMovement" Version="2.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.45.0" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.24" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
Expand Down Expand Up @@ -147,6 +149,9 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
11 changes: 9 additions & 2 deletions AMSExplorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//---------------------------------------------------------------------------------------------

using Microsoft.Azure.Management.Media.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -46,9 +47,15 @@ internal static class Program
[STAThread]
private static void Main(string[] args)
{
if (Properties.Settings.Default.Telemetry)

IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();


if (Properties.Settings.Default.Telemetry && configuration.GetConnectionString("appInsightsRelease") != null && configuration.GetConnectionString("appInsightsDev") != null)
{
Telemetry.StartTelemetry();
Telemetry.StartTelemetry(configuration);
}

Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Expand Down
11 changes: 6 additions & 5 deletions AMSExplorer/Telemetry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -15,22 +16,21 @@ namespace AMSExplorer
/// </summary>
public static class Telemetry
{
private static string TelemetryKeyDev = "2c258d64-b2e4-4219-8108-e938f2f4fc02";
private static string TelemetryKeyProd = "5fb7cbe4-882c-4df8-ad29-df9733248597";
private static TelemetryClient _telemetry;
private static IConfiguration _configuration;

public static bool Enabled { get; set; } = false;

private static TelemetryClient GetAppInsightsClient()
{
var config = new TelemetryConfiguration()
{
ConnectionString = "InstrumentationKey=" + TelemetryKeyProd,
ConnectionString = _configuration.GetConnectionString("appInsightsRelease"),
TelemetryChannel = new Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel(),
};
config.TelemetryChannel.DeveloperMode = Debugger.IsAttached;
#if DEBUG
config.ConnectionString = "InstrumentationKey=" + TelemetryKeyDev;
config.ConnectionString = _configuration.GetConnectionString("appInsightsDev");
config.TelemetryChannel.DeveloperMode = true;
#endif
TelemetryClient client = new(config);
Expand Down Expand Up @@ -119,8 +119,9 @@ private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
Telemetry.TrackEvent("Application exited");
}

public static void StartTelemetry()
public static void StartTelemetry(IConfiguration configuration)
{
_configuration = configuration;
_telemetry = GetAppInsightsClient();
Enabled = true;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
Expand Down

0 comments on commit 0713d01

Please sign in to comment.