Skip to content

Commit

Permalink
Update With elmah.io support (#2139)
Browse files Browse the repository at this point in the history
Add advanced Exception support.
  • Loading branch information
MrHinsh authored Jul 11, 2024
1 parent b70413c commit bd26dca
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=vsts-sync-migrator%3Amaster&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=vsts-sync-migrator%3Amaster)
![Visual Studio Marketplace Rating](https://img.shields.io/visual-studio-marketplace/stars/nkdagility.vsts-sync-migration?logo=visualstudio)
![Chocolatey Downloads](https://img.shields.io/chocolatey/dt/vsts-sync-migrator)
[![Elmah.io](https://img.shields.io/badge/sponsored_by-elmah_io-0da58e)](https://elmah.io)

Created and maintained by [Martin Hinshelwood](https://www.linkedin.com/in/martinhinshelwood/) (http://nkdagility.com)

Expand Down Expand Up @@ -37,6 +38,9 @@ The Azure DevOps Migration Tools allow you to bulk edit and migrate data between
| Migration Run Total | **19bn Seconds** | Thats **316m hours** or **13m days** of run time in the last 30 days. |
| Average Work item Migration Time | **22s** | Work Item (includes all revisions, links, and attachments for the work item) |

Exceptions shipped to Application Insights and [Elmah.io](https://elmah.io) for analysis and improvement.



## What can you do with this tool?

Expand Down
1 change: 1 addition & 0 deletions src/MigrationTools/MigrationTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elmah.Io.Client" Version="5.1.76" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
Expand Down
40 changes: 40 additions & 0 deletions src/MigrationTools/Services/TelemetryClientAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using Elmah.Io.Client;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;

Expand All @@ -8,6 +10,7 @@ namespace MigrationTools
public class TelemetryClientAdapter : ITelemetryLogger
{
private TelemetryClient _telemetryClient;
private static IElmahioAPI elmahIoClient;

public TelemetryClientAdapter(TelemetryClient telemetryClient)
{
Expand All @@ -19,6 +22,14 @@ public TelemetryClientAdapter(TelemetryClient telemetryClient)
telemetryClient.Context.Component.Version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
}
_telemetryClient = telemetryClient;

elmahIoClient = ElmahioAPI.Create("7589821e832a4ae1a1170f8201def634", new ElmahIoOptions
{
Timeout = TimeSpan.FromSeconds(30),
UserAgent = "Azure-DevOps-Migration-Tools",
});
elmahIoClient.Messages.OnMessage += (sender, args) => args.Message.Version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();

}

public string SessionId
Expand Down Expand Up @@ -57,6 +68,35 @@ public void TrackEvent(string name, IDictionary<string, string> properties, IDic
public void TrackException(Exception ex, IDictionary<string, string> properties, IDictionary<string, double> measurements)
{
_telemetryClient.TrackException(ex, properties, measurements);

var baseException = ex.GetBaseException();
var createMessage = new CreateMessage
{
DateTime = DateTime.UtcNow,
Detail = ex.ToString(),
Type = baseException.GetType().FullName,
Title = baseException.Message ?? "An error occurred",
Severity = "Error",
Source = baseException.Source,
User = Environment.UserName,
Hostname = System.Environment.GetEnvironmentVariable("COMPUTERNAME"),
Application = "Azure-DevOps-Migration-Tools",
ServerVariables = new List<Item>
{
new Item("User-Agent", $"X-ELMAHIO-APPLICATION; OS={Environment.OSVersion.Platform}; OSVERSION={Environment.OSVersion.Version}; ENGINE=Azure-DevOps-Migration-Tools"),
}
};
foreach (var property in properties)
{
createMessage.Data.Add(new Item(property.Key, property.Value));
}
foreach (var measurement in measurements)
{
createMessage.Data.Add(new Item(measurement.Key, measurement.Value.ToString()));
}

elmahIoClient.Messages.CreateAndNotify(new Guid("24086b6d-4f58-47f4-8ac7-68d8bc05ca9e"), createMessage);

}

public void TrackRequest(string name, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool success)
Expand Down
48 changes: 48 additions & 0 deletions src/VstsSyncMigrator.Core/VstsSyncMigrator - Backup.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Product>VstsSyncMigrator.Core</Product>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>..\..\docs\Reference\Generated\VstsSyncMigrator.Core.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Execution\MigrationContext\ExcelMigrationContext.cs" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(AssemblyName).Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="CsvHelper" Version="33.0.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.ExtendedClient" Version="19.225.1">
<IncludeAssets>all</IncludeAssets>
<ExcludeAssets>none</ExcludeAssets>
<PrivateAssets>contentFiles;analyzers</PrivateAssets><!--Need to be able to flow up the build folder so that we can get some native dlls into the output folder-->
</PackageReference>

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.AzureDevops.ObjectModel\MigrationTools.Clients.AzureDevops.ObjectModel.csproj" />
<ProjectReference Include="..\MigrationTools\MigrationTools.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/VstsSyncMigrator.Core/VstsSyncMigrator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

<ItemGroup>
<ProjectReference Include="..\MigrationTools.Clients.AzureDevops.ObjectModel\MigrationTools.Clients.AzureDevops.ObjectModel.csproj" />
<ProjectReference Include="..\MigrationTools\MigrationTools.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit bd26dca

Please sign in to comment.